X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fvideos%2Fvideos-history.ts;h=e4bc0bb3a3569f776dd033ecdd1e52bc276ba4b0;hb=a37e9e74ff07b057370d1ed6c0b391a02be8a6d2;hp=256271bd0ec790bbcc5e26a3de968d866dbf47f0;hpb=41d1d075011174e73dccb74006181a92a618d7b4;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/videos/videos-history.ts b/server/tests/api/videos/videos-history.ts index 256271bd0..e4bc0bb3a 100644 --- a/server/tests/api/videos/videos-history.ts +++ b/server/tests/api/videos/videos-history.ts @@ -2,28 +2,21 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, - createUser, - flushAndRunServer, - getVideosListWithToken, - getVideoWithToken, + createSingleServer, HistoryCommand, killallServers, - reRunServer, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, - updateMyUser, - uploadVideo, wait } from '@shared/extra-utils' -import { Video, VideoDetails } from '@shared/models' +import { HttpStatusCode, Video } from '@shared/models' const expect = chai.expect describe('Test videos history', function () { - let server: ServerInfo = null + let server: PeerTubeServer = null let video1UUID: string let video2UUID: string let video3UUID: string @@ -34,42 +27,40 @@ describe('Test videos history', function () { before(async function () { this.timeout(30000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) - command = server.historyCommand + command = server.history { - const res = await uploadVideo(server.url, server.accessToken, { name: 'video 1' }) - video1UUID = res.body.video.uuid + const { uuid } = await server.videos.upload({ attributes: { name: 'video 1' } }) + video1UUID = uuid } { - const res = await uploadVideo(server.url, server.accessToken, { name: 'video 2' }) - video2UUID = res.body.video.uuid + const { uuid } = await server.videos.upload({ attributes: { name: 'video 2' } }) + video2UUID = uuid } { - const res = await uploadVideo(server.url, server.accessToken, { name: 'video 3' }) - video3UUID = res.body.video.uuid + const { uuid } = await server.videos.upload({ attributes: { name: 'video 3' } }) + video3UUID = uuid } const user = { username: 'user_1', password: 'super password' } - await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) - userAccessToken = await server.loginCommand.getAccessToken(user) + await server.users.create({ username: user.username, password: user.password }) + userAccessToken = await server.login.getAccessToken(user) }) it('Should get videos, without watching history', async function () { - const res = await getVideosListWithToken(server.url, server.accessToken) - const videos: Video[] = res.body.data + const { data } = await server.videos.listWithToken() - for (const video of videos) { - const resDetail = await getVideoWithToken(server.url, server.accessToken, video.id) - const videoDetails: VideoDetails = resDetail.body + for (const video of data) { + const videoDetails = await server.videos.getWithToken({ id: video.id }) expect(video.userHistory).to.be.undefined expect(videoDetails.userHistory).to.be.undefined @@ -85,12 +76,12 @@ describe('Test videos history', function () { const videosOfVideos: Video[][] = [] { - const res = await getVideosListWithToken(server.url, server.accessToken) - videosOfVideos.push(res.body.data) + const { data } = await server.videos.listWithToken() + videosOfVideos.push(data) } { - const body = await server.searchCommand.searchVideos({ token: server.accessToken, search: 'video' }) + const body = await server.search.searchVideos({ token: server.accessToken, search: 'video' }) videosOfVideos.push(body.data) } @@ -109,24 +100,21 @@ describe('Test videos history', function () { } { - const resDetail = await getVideoWithToken(server.url, server.accessToken, video1UUID) - const videoDetails: VideoDetails = resDetail.body + const videoDetails = await server.videos.getWithToken({ id: video1UUID }) expect(videoDetails.userHistory).to.not.be.undefined expect(videoDetails.userHistory.currentTime).to.equal(3) } { - const resDetail = await getVideoWithToken(server.url, server.accessToken, video2UUID) - const videoDetails: VideoDetails = resDetail.body + const videoDetails = await server.videos.getWithToken({ id: video2UUID }) expect(videoDetails.userHistory).to.not.be.undefined expect(videoDetails.userHistory.currentTime).to.equal(8) } { - const resDetail = await getVideoWithToken(server.url, server.accessToken, video3UUID) - const videoDetails: VideoDetails = resDetail.body + const videoDetails = await server.videos.getWithToken({ id: video3UUID }) expect(videoDetails.userHistory).to.be.undefined } @@ -174,9 +162,7 @@ describe('Test videos history', function () { }) it('Should disable videos history', async function () { - await updateMyUser({ - url: server.url, - accessToken: server.accessToken, + await server.users.updateMe({ videosHistoryEnabled: false }) @@ -184,9 +170,7 @@ describe('Test videos history', function () { }) it('Should re-enable videos history', async function () { - await updateMyUser({ - url: server.url, - accessToken: server.accessToken, + await server.users.updateMe({ videosHistoryEnabled: true }) @@ -205,7 +189,7 @@ describe('Test videos history', function () { await killallServers([ server ]) - await reRunServer(server, { history: { videos: { max_age: '10 days' } } }) + await server.run({ history: { videos: { max_age: '10 days' } } }) await wait(6000) @@ -220,7 +204,7 @@ describe('Test videos history', function () { await killallServers([ server ]) - await reRunServer(server, { history: { videos: { max_age: '5 seconds' } } }) + await server.run({ history: { videos: { max_age: '5 seconds' } } }) await wait(6000)