1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
5 checkBadCountPagination,
6 checkBadStartPagination,
13 setAccessTokensToServers,
15 } from '../../../../shared/extra-utils'
17 describe('Test videos history API validator', function () {
18 const myHistoryPath = '/api/v1/users/me/history/videos'
19 const myHistoryRemove = myHistoryPath + '/remove'
20 let watchingPath: string
21 let server: ServerInfo
23 // ---------------------------------------------------------------
25 before(async function () {
28 server = await flushAndRunServer(1)
30 await setAccessTokensToServers([ server ])
32 const res = await uploadVideo(server.url, server.accessToken, {})
33 const videoUUID = res.body.video.uuid
35 watchingPath = '/api/v1/videos/' + videoUUID + '/watching'
38 describe('When notifying a user is watching a video', function () {
40 it('Should fail with an unauthenticated user', async function () {
41 const fields = { currentTime: 5 }
42 await makePutBodyRequest({ url: server.url, path: watchingPath, fields, statusCodeExpected: 401 })
45 it('Should fail with an incorrect video id', async function () {
46 const fields = { currentTime: 5 }
47 const path = '/api/v1/videos/blabla/watching'
48 await makePutBodyRequest({ url: server.url, path, fields, token: server.accessToken, statusCodeExpected: 400 })
51 it('Should fail with an unknown video', async function () {
52 const fields = { currentTime: 5 }
53 const path = '/api/v1/videos/d91fff41-c24d-4508-8e13-3bd5902c3b02/watching'
55 await makePutBodyRequest({ url: server.url, path, fields, token: server.accessToken, statusCodeExpected: 404 })
58 it('Should fail with a bad current time', async function () {
59 const fields = { currentTime: 'hello' }
60 await makePutBodyRequest({ url: server.url, path: watchingPath, fields, token: server.accessToken, statusCodeExpected: 400 })
63 it('Should succeed with the correct parameters', async function () {
64 const fields = { currentTime: 5 }
66 await makePutBodyRequest({ url: server.url, path: watchingPath, fields, token: server.accessToken, statusCodeExpected: 204 })
70 describe('When listing user videos history', function () {
71 it('Should fail with a bad start pagination', async function () {
72 await checkBadStartPagination(server.url, myHistoryPath, server.accessToken)
75 it('Should fail with a bad count pagination', async function () {
76 await checkBadCountPagination(server.url, myHistoryPath, server.accessToken)
79 it('Should fail with an unauthenticated user', async function () {
80 await makeGetRequest({ url: server.url, path: myHistoryPath, statusCodeExpected: 401 })
83 it('Should succeed with the correct params', async function () {
84 await makeGetRequest({ url: server.url, token: server.accessToken, path: myHistoryPath, statusCodeExpected: 200 })
88 describe('When removing user videos history', function () {
89 it('Should fail with an unauthenticated user', async function () {
90 await makePostBodyRequest({ url: server.url, path: myHistoryPath + '/remove', statusCodeExpected: 401 })
93 it('Should fail with a bad beforeDate parameter', async function () {
94 const body = { beforeDate: '15' }
95 await makePostBodyRequest({
97 token: server.accessToken,
98 path: myHistoryRemove,
100 statusCodeExpected: 400
104 it('Should succeed with a valid beforeDate param', async function () {
105 const body = { beforeDate: new Date().toISOString() }
106 await makePostBodyRequest({
108 token: server.accessToken,
109 path: myHistoryRemove,
111 statusCodeExpected: 204
115 it('Should succeed without body', async function () {
116 await makePostBodyRequest({
118 token: server.accessToken,
119 path: myHistoryRemove,
120 statusCodeExpected: 204
125 after(async function () {
126 await cleanupTests([ server ])