diff options
author | Chocobozzz <me@florianbigard.com> | 2022-05-06 14:23:02 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-05-06 14:23:02 +0200 |
commit | f40712abbbb74e51f06037ef02757c42736bccf8 (patch) | |
tree | 4b130c6387f9687d52d570907eb1bbac6bc04b61 /server/tests/api/views/video-views-overall-stats.ts | |
parent | 49f0468d44468528c2fb2c8b0efd19cdaeeec43d (diff) | |
download | PeerTube-f40712abbbb74e51f06037ef02757c42736bccf8.tar.gz PeerTube-f40712abbbb74e51f06037ef02757c42736bccf8.tar.zst PeerTube-f40712abbbb74e51f06037ef02757c42736bccf8.zip |
Add ability to filter overall video stats by date
Diffstat (limited to 'server/tests/api/views/video-views-overall-stats.ts')
-rw-r--r-- | server/tests/api/views/video-views-overall-stats.ts | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/server/tests/api/views/video-views-overall-stats.ts b/server/tests/api/views/video-views-overall-stats.ts index 53b8f0d4b..02012388d 100644 --- a/server/tests/api/views/video-views-overall-stats.ts +++ b/server/tests/api/views/video-views-overall-stats.ts | |||
@@ -169,6 +169,7 @@ describe('Test views overall stats', function () { | |||
169 | 169 | ||
170 | describe('Test watchers peak stats of local videos on VOD', function () { | 170 | describe('Test watchers peak stats of local videos on VOD', function () { |
171 | let videoUUID: string | 171 | let videoUUID: string |
172 | let before2Watchers: Date | ||
172 | 173 | ||
173 | before(async function () { | 174 | before(async function () { |
174 | this.timeout(120000); | 175 | this.timeout(120000); |
@@ -201,7 +202,7 @@ describe('Test views overall stats', function () { | |||
201 | it('Should have watcher peak with 2 watchers', async function () { | 202 | it('Should have watcher peak with 2 watchers', async function () { |
202 | this.timeout(60000) | 203 | this.timeout(60000) |
203 | 204 | ||
204 | const before = new Date() | 205 | before2Watchers = new Date() |
205 | await servers[0].views.view({ id: videoUUID, currentTime: 0 }) | 206 | await servers[0].views.view({ id: videoUUID, currentTime: 0 }) |
206 | await servers[1].views.view({ id: videoUUID, currentTime: 0 }) | 207 | await servers[1].views.view({ id: videoUUID, currentTime: 0 }) |
207 | await servers[0].views.view({ id: videoUUID, currentTime: 2 }) | 208 | await servers[0].views.view({ id: videoUUID, currentTime: 2 }) |
@@ -213,11 +214,26 @@ describe('Test views overall stats', function () { | |||
213 | const stats = await servers[0].videoStats.getOverallStats({ videoId: videoUUID }) | 214 | const stats = await servers[0].videoStats.getOverallStats({ videoId: videoUUID }) |
214 | 215 | ||
215 | expect(stats.viewersPeak).to.equal(2) | 216 | expect(stats.viewersPeak).to.equal(2) |
216 | expect(new Date(stats.viewersPeakDate)).to.be.above(before).and.below(after) | 217 | expect(new Date(stats.viewersPeakDate)).to.be.above(before2Watchers).and.below(after) |
218 | }) | ||
219 | |||
220 | it('Should filter peak viewers stats by date', async function () { | ||
221 | { | ||
222 | const stats = await servers[0].videoStats.getOverallStats({ videoId: videoUUID, startDate: new Date().toISOString() }) | ||
223 | expect(stats.viewersPeak).to.equal(0) | ||
224 | expect(stats.viewersPeakDate).to.not.exist | ||
225 | } | ||
226 | |||
227 | { | ||
228 | const stats = await servers[0].videoStats.getOverallStats({ videoId: videoUUID, endDate: before2Watchers.toISOString() }) | ||
229 | expect(stats.viewersPeak).to.equal(1) | ||
230 | expect(new Date(stats.viewersPeakDate)).to.be.below(before2Watchers) | ||
231 | } | ||
217 | }) | 232 | }) |
218 | }) | 233 | }) |
219 | 234 | ||
220 | describe('Test countries', function () { | 235 | describe('Test countries', function () { |
236 | let videoUUID: string | ||
221 | 237 | ||
222 | it('Should not report countries if geoip is disabled', async function () { | 238 | it('Should not report countries if geoip is disabled', async function () { |
223 | this.timeout(120000) | 239 | this.timeout(120000) |
@@ -237,6 +253,7 @@ describe('Test views overall stats', function () { | |||
237 | this.timeout(240000) | 253 | this.timeout(240000) |
238 | 254 | ||
239 | const { uuid } = await servers[0].videos.quickUpload({ name: 'video' }) | 255 | const { uuid } = await servers[0].videos.quickUpload({ name: 'video' }) |
256 | videoUUID = uuid | ||
240 | await waitJobs(servers) | 257 | await waitJobs(servers) |
241 | 258 | ||
242 | await Promise.all([ | 259 | await Promise.all([ |
@@ -265,6 +282,11 @@ describe('Test views overall stats', function () { | |||
265 | expect(stats.countries[1].isoCode).to.equal('FR') | 282 | expect(stats.countries[1].isoCode).to.equal('FR') |
266 | expect(stats.countries[1].viewers).to.equal(1) | 283 | expect(stats.countries[1].viewers).to.equal(1) |
267 | }) | 284 | }) |
285 | |||
286 | it('Should filter countries stats by date', async function () { | ||
287 | const stats = await servers[0].videoStats.getOverallStats({ videoId: videoUUID, startDate: new Date().toISOString() }) | ||
288 | expect(stats.countries).to.have.lengthOf(0) | ||
289 | }) | ||
268 | }) | 290 | }) |
269 | 291 | ||
270 | after(async function () { | 292 | after(async function () { |