1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
5 checkBadCountPagination,
6 checkBadStartPagination,
13 setAccessTokensToServers,
15 } from '../../../../shared/extra-utils'
16 import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
18 describe('Test videos history API validator', function () {
19 const myHistoryPath = '/api/v1/users/me/history/videos'
20 const myHistoryRemove = myHistoryPath + '/remove'
21 let watchingPath: string
22 let server: ServerInfo
24 // ---------------------------------------------------------------
26 before(async function () {
29 server = await flushAndRunServer(1)
31 await setAccessTokensToServers([ server ])
33 const res = await uploadVideo(server.url, server.accessToken, {})
34 const videoUUID = res.body.video.uuid
36 watchingPath = '/api/v1/videos/' + videoUUID + '/watching'
39 describe('When notifying a user is watching a video', function () {
41 it('Should fail with an unauthenticated user', async function () {
42 const fields = { currentTime: 5 }
43 await makePutBodyRequest({ url: server.url, path: watchingPath, fields, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
46 it('Should fail with an incorrect video id', async function () {
47 const fields = { currentTime: 5 }
48 const path = '/api/v1/videos/blabla/watching'
49 await makePutBodyRequest({
53 token: server.accessToken,
54 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
58 it('Should fail with an unknown video', async function () {
59 const fields = { currentTime: 5 }
60 const path = '/api/v1/videos/d91fff41-c24d-4508-8e13-3bd5902c3b02/watching'
62 await makePutBodyRequest({
66 token: server.accessToken,
67 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
71 it('Should fail with a bad current time', async function () {
72 const fields = { currentTime: 'hello' }
73 await makePutBodyRequest({
77 token: server.accessToken,
78 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
82 it('Should succeed with the correct parameters', async function () {
83 const fields = { currentTime: 5 }
85 await makePutBodyRequest({
89 token: server.accessToken,
90 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
95 describe('When listing user videos history', function () {
96 it('Should fail with a bad start pagination', async function () {
97 await checkBadStartPagination(server.url, myHistoryPath, server.accessToken)
100 it('Should fail with a bad count pagination', async function () {
101 await checkBadCountPagination(server.url, myHistoryPath, server.accessToken)
104 it('Should fail with an unauthenticated user', async function () {
105 await makeGetRequest({ url: server.url, path: myHistoryPath, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
108 it('Should succeed with the correct params', async function () {
109 await makeGetRequest({ url: server.url, token: server.accessToken, path: myHistoryPath, statusCodeExpected: HttpStatusCode.OK_200 })
113 describe('When removing user videos history', function () {
114 it('Should fail with an unauthenticated user', async function () {
115 await makePostBodyRequest({ url: server.url, path: myHistoryPath + '/remove', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
118 it('Should fail with a bad beforeDate parameter', async function () {
119 const body = { beforeDate: '15' }
120 await makePostBodyRequest({
122 token: server.accessToken,
123 path: myHistoryRemove,
125 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
129 it('Should succeed with a valid beforeDate param', async function () {
130 const body = { beforeDate: new Date().toISOString() }
131 await makePostBodyRequest({
133 token: server.accessToken,
134 path: myHistoryRemove,
136 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
140 it('Should succeed without body', async function () {
141 await makePostBodyRequest({
143 token: server.accessToken,
144 path: myHistoryRemove,
145 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
150 after(async function () {
151 await cleanupTests([ server ])