1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { checkBadCountPagination, checkBadStartPagination } from '@server/tests/shared'
5 import { HttpStatusCode } from '@shared/models'
13 setAccessTokensToServers
14 } from '@shared/server-commands'
16 describe('Test videos history API validator', function () {
17 const myHistoryPath = '/api/v1/users/me/history/videos'
18 const myHistoryRemove = myHistoryPath + '/remove'
19 let watchingPath: string
20 let server: PeerTubeServer
22 // ---------------------------------------------------------------
24 before(async function () {
27 server = await createSingleServer(1)
29 await setAccessTokensToServers([ server ])
31 const { uuid } = await server.videos.upload()
32 watchingPath = '/api/v1/videos/' + uuid + '/watching'
35 describe('When notifying a user is watching a video', function () {
37 it('Should fail with an unauthenticated user', async function () {
38 const fields = { currentTime: 5 }
39 await makePutBodyRequest({ url: server.url, path: watchingPath, fields, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
42 it('Should fail with an incorrect video id', async function () {
43 const fields = { currentTime: 5 }
44 const path = '/api/v1/videos/blabla/watching'
45 await makePutBodyRequest({
49 token: server.accessToken,
50 expectedStatus: HttpStatusCode.BAD_REQUEST_400
54 it('Should fail with an unknown video', async function () {
55 const fields = { currentTime: 5 }
56 const path = '/api/v1/videos/d91fff41-c24d-4508-8e13-3bd5902c3b02/watching'
58 await makePutBodyRequest({
62 token: server.accessToken,
63 expectedStatus: HttpStatusCode.NOT_FOUND_404
67 it('Should fail with a bad current time', async function () {
68 const fields = { currentTime: 'hello' }
69 await makePutBodyRequest({
73 token: server.accessToken,
74 expectedStatus: HttpStatusCode.BAD_REQUEST_400
78 it('Should succeed with the correct parameters', async function () {
79 const fields = { currentTime: 5 }
81 await makePutBodyRequest({
85 token: server.accessToken,
86 expectedStatus: HttpStatusCode.NO_CONTENT_204
91 describe('When listing user videos history', function () {
92 it('Should fail with a bad start pagination', async function () {
93 await checkBadStartPagination(server.url, myHistoryPath, server.accessToken)
96 it('Should fail with a bad count pagination', async function () {
97 await checkBadCountPagination(server.url, myHistoryPath, server.accessToken)
100 it('Should fail with an unauthenticated user', async function () {
101 await makeGetRequest({ url: server.url, path: myHistoryPath, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
104 it('Should succeed with the correct params', async function () {
105 await makeGetRequest({ url: server.url, token: server.accessToken, path: myHistoryPath, expectedStatus: HttpStatusCode.OK_200 })
109 describe('When removing user videos history', function () {
110 it('Should fail with an unauthenticated user', async function () {
111 await makePostBodyRequest({ url: server.url, path: myHistoryPath + '/remove', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
114 it('Should fail with a bad beforeDate parameter', async function () {
115 const body = { beforeDate: '15' }
116 await makePostBodyRequest({
118 token: server.accessToken,
119 path: myHistoryRemove,
121 expectedStatus: HttpStatusCode.BAD_REQUEST_400
125 it('Should succeed with a valid beforeDate param', async function () {
126 const body = { beforeDate: new Date().toISOString() }
127 await makePostBodyRequest({
129 token: server.accessToken,
130 path: myHistoryRemove,
132 expectedStatus: HttpStatusCode.NO_CONTENT_204
136 it('Should succeed without body', async function () {
137 await makePostBodyRequest({
139 token: server.accessToken,
140 path: myHistoryRemove,
141 expectedStatus: HttpStatusCode.NO_CONTENT_204
146 after(async function () {
147 await cleanupTests([ server ])