X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fvideos%2Fvideos-history.ts;h=f654a422bd45eff49ae18dd0fd50944df6f1b775;hb=8b9a525a180cc9f3a98c334cc052dcfc8f36dcd4;hp=40ae94f797f198e1bdc9e79c833c82d252dd84a6;hpb=583cd0d2129dc855e599f981d70e537feade1632;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/videos/videos-history.ts b/server/tests/api/videos/videos-history.ts index 40ae94f79..f654a422b 100644 --- a/server/tests/api/videos/videos-history.ts +++ b/server/tests/api/videos/videos-history.ts @@ -3,17 +3,21 @@ import * as chai from 'chai' import 'mocha' import { + createUser, flushTests, getVideosListWithToken, getVideoWithToken, - killallServers, makePutBodyRequest, - runServer, searchVideoWithToken, + killallServers, + runServer, + searchVideoWithToken, ServerInfo, setAccessTokensToServers, - uploadVideo + updateMyUser, + uploadVideo, + userLogin } from '../../../../shared/utils' import { Video, VideoDetails } from '../../../../shared/models/videos' -import { userWatchVideo } from '../../../../shared/utils/videos/video-history' +import { listMyVideosHistory, removeMyVideosHistory, userWatchVideo } from '../../../../shared/utils/videos/video-history' const expect = chai.expect @@ -22,6 +26,8 @@ describe('Test videos history', function () { let video1UUID: string let video2UUID: string let video3UUID: string + let video3WatchedDate: Date + let userAccessToken: string before(async function () { this.timeout(30000) @@ -46,6 +52,13 @@ describe('Test videos history', function () { const res = await uploadVideo(server.url, server.accessToken, { name: 'video 3' }) video3UUID = res.body.video.uuid } + + const user = { + username: 'user_1', + password: 'super password' + } + await createUser(server.url, server.accessToken, user.username, user.password) + userAccessToken = await userLogin(server, user) }) it('Should get videos, without watching history', async function () { @@ -62,8 +75,8 @@ describe('Test videos history', function () { }) it('Should watch the first and second video', async function () { - await userWatchVideo(server.url, server.accessToken, video1UUID, 3) await userWatchVideo(server.url, server.accessToken, video2UUID, 8) + await userWatchVideo(server.url, server.accessToken, video1UUID, 3) }) it('Should return the correct history when listing, searching and getting videos', async function () { @@ -117,6 +130,68 @@ describe('Test videos history', function () { } }) + it('Should have these videos when listing my history', async function () { + video3WatchedDate = new Date() + await userWatchVideo(server.url, server.accessToken, video3UUID, 2) + + const res = await listMyVideosHistory(server.url, server.accessToken) + + expect(res.body.total).to.equal(3) + + const videos: Video[] = res.body.data + expect(videos[0].name).to.equal('video 3') + expect(videos[1].name).to.equal('video 1') + expect(videos[2].name).to.equal('video 2') + }) + + it('Should not have videos history on another user', async function () { + const res = await listMyVideosHistory(server.url, userAccessToken) + + expect(res.body.total).to.equal(0) + expect(res.body.data).to.have.lengthOf(0) + }) + + it('Should clear my history', async function () { + await removeMyVideosHistory(server.url, server.accessToken, video3WatchedDate.toISOString()) + }) + + it('Should have my history cleared', async function () { + const res = await listMyVideosHistory(server.url, server.accessToken) + + expect(res.body.total).to.equal(1) + + const videos: Video[] = res.body.data + expect(videos[0].name).to.equal('video 3') + }) + + it('Should disable videos history', async function () { + await updateMyUser({ + url: server.url, + accessToken: server.accessToken, + videosHistoryEnabled: false + }) + + await userWatchVideo(server.url, server.accessToken, video2UUID, 8, 409) + }) + + it('Should re-enable videos history', async function () { + await updateMyUser({ + url: server.url, + accessToken: server.accessToken, + videosHistoryEnabled: true + }) + + await userWatchVideo(server.url, server.accessToken, video1UUID, 8) + + const res = await listMyVideosHistory(server.url, server.accessToken) + + expect(res.body.total).to.equal(2) + + const videos: Video[] = res.body.data + expect(videos[0].name).to.equal('video 1') + expect(videos[1].name).to.equal('video 3') + }) + after(async function () { killallServers([ server ])