X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fvideos%2Fvideos-history.ts;h=89e74a309143ea6182fc37e76c907835c1df540b;hb=9295c68b74fe1f1e2e9f72009205d7f0379844c5;hp=8648c97f092a8158ad9cf4449024f795a421e200;hpb=7177b46ca1b35aa9d7ed39a06c1dcf41a4fc6180;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/videos/videos-history.ts b/server/tests/api/videos/videos-history.ts index 8648c97f0..89e74a309 100644 --- a/server/tests/api/videos/videos-history.ts +++ b/server/tests/api/videos/videos-history.ts @@ -3,15 +3,8 @@ import 'mocha' import * as chai from 'chai' import { wait } from '@shared/core-utils' -import { HttpStatusCode, Video } from '@shared/models' -import { - cleanupTests, - createSingleServer, - HistoryCommand, - killallServers, - PeerTubeServer, - setAccessTokensToServers -} from '@shared/server-commands' +import { Video } from '@shared/models' +import { cleanupTests, createSingleServer, killallServers, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands' const expect = chai.expect @@ -23,7 +16,6 @@ describe('Test videos history', function () { let video3UUID: string let video3WatchedDate: Date let userAccessToken: string - let command: HistoryCommand before(async function () { this.timeout(30000) @@ -32,30 +24,26 @@ describe('Test videos history', function () { await setAccessTokensToServers([ server ]) - command = server.history + // 10 seconds long + const fixture = 'video_short1.webm' { - const { id, uuid } = await server.videos.upload({ attributes: { name: 'video 1' } }) + const { id, uuid } = await server.videos.upload({ attributes: { name: 'video 1', fixture } }) video1UUID = uuid video1Id = id } { - const { uuid } = await server.videos.upload({ attributes: { name: 'video 2' } }) + const { uuid } = await server.videos.upload({ attributes: { name: 'video 2', fixture } }) video2UUID = uuid } { - const { uuid } = await server.videos.upload({ attributes: { name: 'video 3' } }) + const { uuid } = await server.videos.upload({ attributes: { name: 'video 3', fixture } }) video3UUID = uuid } - const user = { - username: 'user_1', - password: 'super password' - } - await server.users.create({ username: user.username, password: user.password }) - userAccessToken = await server.login.getAccessToken(user) + userAccessToken = await server.users.generateUserAndToken('user_1') }) it('Should get videos, without watching history', async function () { @@ -70,8 +58,8 @@ describe('Test videos history', function () { }) it('Should watch the first and second video', async function () { - await command.watchVideo({ videoId: video2UUID, currentTime: 8 }) - await command.watchVideo({ videoId: video1UUID, currentTime: 3 }) + await server.views.view({ id: video2UUID, token: server.accessToken, currentTime: 8 }) + await server.views.view({ id: video1UUID, token: server.accessToken, currentTime: 3 }) }) it('Should return the correct history when listing, searching and getting videos', async function () { @@ -124,9 +112,9 @@ describe('Test videos history', function () { it('Should have these videos when listing my history', async function () { video3WatchedDate = new Date() - await command.watchVideo({ videoId: video3UUID, currentTime: 2 }) + await server.views.view({ id: video3UUID, token: server.accessToken, currentTime: 2 }) - const body = await command.list() + const body = await server.history.list() expect(body.total).to.equal(3) @@ -137,14 +125,14 @@ describe('Test videos history', function () { }) it('Should not have videos history on another user', async function () { - const body = await command.list({ token: userAccessToken }) + const body = await server.history.list({ token: userAccessToken }) expect(body.total).to.equal(0) expect(body.data).to.have.lengthOf(0) }) it('Should be able to search through videos in my history', async function () { - const body = await command.list({ search: '2' }) + const body = await server.history.list({ search: '2' }) expect(body.total).to.equal(1) const videos = body.data @@ -152,11 +140,11 @@ describe('Test videos history', function () { }) it('Should clear my history', async function () { - await command.removeAll({ beforeDate: video3WatchedDate.toISOString() }) + await server.history.removeAll({ beforeDate: video3WatchedDate.toISOString() }) }) it('Should have my history cleared', async function () { - const body = await command.list() + const body = await server.history.list() expect(body.total).to.equal(1) const videos = body.data @@ -168,7 +156,10 @@ describe('Test videos history', function () { videosHistoryEnabled: false }) - await command.watchVideo({ videoId: video2UUID, currentTime: 8, expectedStatus: HttpStatusCode.CONFLICT_409 }) + await server.views.view({ id: video2UUID, token: server.accessToken, currentTime: 8 }) + + const { data } = await server.history.list() + expect(data[0].name).to.not.equal('video 2') }) it('Should re-enable videos history', async function () { @@ -176,14 +167,10 @@ describe('Test videos history', function () { videosHistoryEnabled: true }) - await command.watchVideo({ videoId: video1UUID, currentTime: 8 }) + await server.views.view({ id: video2UUID, token: server.accessToken, currentTime: 8 }) - const body = await command.list() - expect(body.total).to.equal(2) - - const videos = body.data - expect(videos[0].name).to.equal('video 1') - expect(videos[1].name).to.equal('video 3') + const { data } = await server.history.list() + expect(data[0].name).to.equal('video 2') }) it('Should not clean old history', async function () { @@ -197,7 +184,7 @@ describe('Test videos history', function () { // Should still have history - const body = await command.list() + const body = await server.history.list() expect(body.total).to.equal(2) }) @@ -210,25 +197,25 @@ describe('Test videos history', function () { await wait(6000) - const body = await command.list() + const body = await server.history.list() 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 }) + await server.views.view({ id: video1UUID, token: server.accessToken, currentTime: 4 }) + await server.views.view({ id: video2UUID, token: server.accessToken, currentTime: 8 }) } { - const body = await command.list() + const body = await server.history.list() expect(body.total).to.equal(2) } { - await command.removeElement({ videoId: video1Id }) + await server.history.removeElement({ videoId: video1Id }) - const body = await command.list() + const body = await server.history.list() expect(body.total).to.equal(1) expect(body.data[0].uuid).to.equal(video2UUID) }