X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fcheck-params%2Fviews.ts;h=84d31c5094b8f9cb8269cc78d48c3d43fcc64651;hb=cffef25313bdf7a6c435f56ac6715fdd91acf7b3;hp=ca4752345ed95fb948c99efd266e87fe3a4bdf6a;hpb=ac907dc7c158056e9b6a5cb58acd27df5c7c2670;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/check-params/views.ts b/server/tests/api/check-params/views.ts index ca4752345..84d31c509 100644 --- a/server/tests/api/check-params/views.ts +++ b/server/tests/api/check-params/views.ts @@ -1,6 +1,5 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import 'mocha' import { HttpStatusCode, VideoPrivacy } from '@shared/models' import { cleanupTests, @@ -64,19 +63,41 @@ describe('Test videos views', function () { }) it('Should fail without token', async function () { - await servers[0].videoStats.getOverallStats({ videoId: videoId, token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await servers[0].videoStats.getOverallStats({ videoId, token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail with another token', async function () { await servers[0].videoStats.getOverallStats({ - videoId: videoId, + videoId, token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) + it('Should fail with an invalid start date', async function () { + await servers[0].videoStats.getOverallStats({ + videoId, + startDate: 'fake' as any, + endDate: new Date().toISOString(), + expectedStatus: HttpStatusCode.BAD_REQUEST_400 + }) + }) + + it('Should fail with an invalid end date', async function () { + await servers[0].videoStats.getOverallStats({ + videoId, + startDate: new Date().toISOString(), + endDate: 'fake' as any, + expectedStatus: HttpStatusCode.BAD_REQUEST_400 + }) + }) + it('Should succeed with the correct parameters', async function () { - await servers[0].videoStats.getOverallStats({ videoId }) + await servers[0].videoStats.getOverallStats({ + videoId, + startDate: new Date().toISOString(), + endDate: new Date().toISOString() + }) }) }) @@ -92,7 +113,7 @@ describe('Test videos views', function () { it('Should fail without token', async function () { await servers[0].videoStats.getTimeserieStats({ - videoId: videoId, + videoId, token: null, metric: 'viewers', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 @@ -101,7 +122,7 @@ describe('Test videos views', function () { it('Should fail with another token', async function () { await servers[0].videoStats.getTimeserieStats({ - videoId: videoId, + videoId, token: userAccessToken, metric: 'viewers', expectedStatus: HttpStatusCode.FORBIDDEN_403 @@ -112,6 +133,54 @@ describe('Test videos views', function () { await servers[0].videoStats.getTimeserieStats({ videoId, metric: 'hello' as any, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) + it('Should fail with an invalid start date', async function () { + await servers[0].videoStats.getTimeserieStats({ + videoId, + metric: 'viewers', + startDate: 'fake' as any, + endDate: new Date(), + expectedStatus: HttpStatusCode.BAD_REQUEST_400 + }) + }) + + it('Should fail with an invalid end date', async function () { + await servers[0].videoStats.getTimeserieStats({ + videoId, + metric: 'viewers', + startDate: new Date(), + endDate: 'fake' as any, + expectedStatus: HttpStatusCode.BAD_REQUEST_400 + }) + }) + + it('Should fail if start date is specified but not end date', async function () { + await servers[0].videoStats.getTimeserieStats({ + videoId, + metric: 'viewers', + startDate: new Date(), + expectedStatus: HttpStatusCode.BAD_REQUEST_400 + }) + }) + + it('Should fail if end date is specified but not start date', async function () { + await servers[0].videoStats.getTimeserieStats({ + videoId, + metric: 'viewers', + endDate: new Date(), + expectedStatus: HttpStatusCode.BAD_REQUEST_400 + }) + }) + + it('Should fail with a too big interval', async function () { + await servers[0].videoStats.getTimeserieStats({ + videoId, + metric: 'viewers', + startDate: new Date('2000-04-07T08:31:57.126Z'), + endDate: new Date(), + expectedStatus: HttpStatusCode.BAD_REQUEST_400 + }) + }) + it('Should succeed with the correct parameters', async function () { await servers[0].videoStats.getTimeserieStats({ videoId, metric: 'viewers' }) }) @@ -128,7 +197,7 @@ describe('Test videos views', function () { it('Should fail without token', async function () { await servers[0].videoStats.getRetentionStats({ - videoId: videoId, + videoId, token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) @@ -136,7 +205,7 @@ describe('Test videos views', function () { it('Should fail with another token', async function () { await servers[0].videoStats.getRetentionStats({ - videoId: videoId, + videoId, token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 })