From 7177b46ca1b35aa9d7ed39a06c1dcf41a4fc6180 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 18 Jan 2022 11:23:41 +0100 Subject: Add ability to delete history element --- server/tests/api/check-params/videos-history.ts | 37 +++++++++++++++++++++++-- server/tests/api/videos/videos-history.ts | 36 +++++++++++++++++++----- 2 files changed, 64 insertions(+), 9 deletions(-) (limited to 'server/tests/api') diff --git a/server/tests/api/check-params/videos-history.ts b/server/tests/api/check-params/videos-history.ts index 31a0752c7..82f38b7b4 100644 --- a/server/tests/api/check-params/videos-history.ts +++ b/server/tests/api/check-params/videos-history.ts @@ -6,6 +6,7 @@ import { HttpStatusCode } from '@shared/models' import { cleanupTests, createSingleServer, + makeDeleteRequest, makeGetRequest, makePostBodyRequest, makePutBodyRequest, @@ -18,6 +19,7 @@ describe('Test videos history API validator', function () { const myHistoryRemove = myHistoryPath + '/remove' let watchingPath: string let server: PeerTubeServer + let videoId: number // --------------------------------------------------------------- @@ -28,8 +30,9 @@ describe('Test videos history API validator', function () { await setAccessTokensToServers([ server ]) - const { uuid } = await server.videos.upload() + const { id, uuid } = await server.videos.upload() watchingPath = '/api/v1/videos/' + uuid + '/watching' + videoId = id }) describe('When notifying a user is watching a video', function () { @@ -106,7 +109,37 @@ describe('Test videos history API validator', function () { }) }) - describe('When removing user videos history', function () { + describe('When removing a specific user video history element', function () { + let path: string + + before(function () { + path = myHistoryPath + '/' + videoId + }) + + it('Should fail with an unauthenticated user', async function () { + await makeDeleteRequest({ url: server.url, path, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + }) + + it('Should fail with a bad videoId parameter', async function () { + await makeDeleteRequest({ + url: server.url, + token: server.accessToken, + path: myHistoryRemove + '/hi', + expectedStatus: HttpStatusCode.BAD_REQUEST_400 + }) + }) + + it('Should succeed with the correct parameters', async function () { + await makeDeleteRequest({ + url: server.url, + token: server.accessToken, + path, + expectedStatus: HttpStatusCode.NO_CONTENT_204 + }) + }) + }) + + describe('When removing all user videos history', function () { it('Should fail with an unauthenticated user', async function () { await makePostBodyRequest({ url: server.url, path: myHistoryPath + '/remove', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) diff --git a/server/tests/api/videos/videos-history.ts b/server/tests/api/videos/videos-history.ts index 4e5ba13aa..8648c97f0 100644 --- a/server/tests/api/videos/videos-history.ts +++ b/server/tests/api/videos/videos-history.ts @@ -17,6 +17,7 @@ const expect = chai.expect describe('Test videos history', function () { let server: PeerTubeServer = null + let video1Id: number let video1UUID: string let video2UUID: string let video3UUID: string @@ -34,8 +35,9 @@ describe('Test videos history', function () { command = server.history { - const { uuid } = await server.videos.upload({ attributes: { name: 'video 1' } }) + const { id, uuid } = await server.videos.upload({ attributes: { name: 'video 1' } }) video1UUID = uuid + video1Id = id } { @@ -68,8 +70,8 @@ describe('Test videos history', function () { }) it('Should watch the first and second video', async function () { - await command.wathVideo({ videoId: video2UUID, currentTime: 8 }) - await command.wathVideo({ videoId: video1UUID, currentTime: 3 }) + await command.watchVideo({ videoId: video2UUID, currentTime: 8 }) + await command.watchVideo({ videoId: video1UUID, currentTime: 3 }) }) it('Should return the correct history when listing, searching and getting videos', async function () { @@ -122,7 +124,7 @@ describe('Test videos history', function () { it('Should have these videos when listing my history', async function () { video3WatchedDate = new Date() - await command.wathVideo({ videoId: video3UUID, currentTime: 2 }) + await command.watchVideo({ videoId: video3UUID, currentTime: 2 }) const body = await command.list() @@ -150,7 +152,7 @@ describe('Test videos history', function () { }) it('Should clear my history', async function () { - await command.remove({ beforeDate: video3WatchedDate.toISOString() }) + await command.removeAll({ beforeDate: video3WatchedDate.toISOString() }) }) it('Should have my history cleared', async function () { @@ -166,7 +168,7 @@ describe('Test videos history', function () { videosHistoryEnabled: false }) - await command.wathVideo({ videoId: video2UUID, currentTime: 8, expectedStatus: HttpStatusCode.CONFLICT_409 }) + await command.watchVideo({ videoId: video2UUID, currentTime: 8, expectedStatus: HttpStatusCode.CONFLICT_409 }) }) it('Should re-enable videos history', async function () { @@ -174,7 +176,7 @@ describe('Test videos history', function () { videosHistoryEnabled: true }) - await command.wathVideo({ videoId: video1UUID, currentTime: 8 }) + await command.watchVideo({ videoId: video1UUID, currentTime: 8 }) const body = await command.list() expect(body.total).to.equal(2) @@ -212,6 +214,26 @@ describe('Test videos history', function () { expect(body.total).to.equal(0) }) + it('Should delete a specific history element', async function () { + { + await command.watchVideo({ videoId: video1UUID, currentTime: 4 }) + await command.watchVideo({ videoId: video2UUID, currentTime: 8 }) + } + + { + const body = await command.list() + expect(body.total).to.equal(2) + } + + { + await command.removeElement({ videoId: video1Id }) + + const body = await command.list() + expect(body.total).to.equal(1) + expect(body.data[0].uuid).to.equal(video2UUID) + } + }) + after(async function () { await cleanupTests([ server ]) }) -- cgit v1.2.3