1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
5 checkBadCountPagination,
6 checkBadStartPagination,
13 setAccessTokensToServers
14 } from '@shared/extra-utils'
15 import { HttpStatusCode } from '@shared/models'
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: PeerTubeServer
23 // ---------------------------------------------------------------
25 before(async function () {
28 server = await createSingleServer(1)
30 await setAccessTokensToServers([ server ])
32 const { uuid } = await server.videos.upload()
33 watchingPath = '/api/v1/videos/' + uuid + '/watching'
36 describe('When notifying a user is watching a video', function () {
38 it('Should fail with an unauthenticated user', async function () {
39 const fields = { currentTime: 5 }
40 await makePutBodyRequest({ url: server.url, path: watchingPath, fields, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
43 it('Should fail with an incorrect video id', async function () {
44 const fields = { currentTime: 5 }
45 const path = '/api/v1/videos/blabla/watching'
46 await makePutBodyRequest({
50 token: server.accessToken,
51 expectedStatus: HttpStatusCode.BAD_REQUEST_400
55 it('Should fail with an unknown video', async function () {
56 const fields = { currentTime: 5 }
57 const path = '/api/v1/videos/d91fff41-c24d-4508-8e13-3bd5902c3b02/watching'
59 await makePutBodyRequest({
63 token: server.accessToken,
64 expectedStatus: HttpStatusCode.NOT_FOUND_404
68 it('Should fail with a bad current time', async function () {
69 const fields = { currentTime: 'hello' }
70 await makePutBodyRequest({
74 token: server.accessToken,
75 expectedStatus: HttpStatusCode.BAD_REQUEST_400
79 it('Should succeed with the correct parameters', async function () {
80 const fields = { currentTime: 5 }
82 await makePutBodyRequest({
86 token: server.accessToken,
87 expectedStatus: HttpStatusCode.NO_CONTENT_204
92 describe('When listing user videos history', function () {
93 it('Should fail with a bad start pagination', async function () {
94 await checkBadStartPagination(server.url, myHistoryPath, server.accessToken)
97 it('Should fail with a bad count pagination', async function () {
98 await checkBadCountPagination(server.url, myHistoryPath, server.accessToken)
101 it('Should fail with an unauthenticated user', async function () {
102 await makeGetRequest({ url: server.url, path: myHistoryPath, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
105 it('Should succeed with the correct params', async function () {
106 await makeGetRequest({ url: server.url, token: server.accessToken, path: myHistoryPath, expectedStatus: HttpStatusCode.OK_200 })
110 describe('When removing user videos history', function () {
111 it('Should fail with an unauthenticated user', async function () {
112 await makePostBodyRequest({ url: server.url, path: myHistoryPath + '/remove', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
115 it('Should fail with a bad beforeDate parameter', async function () {
116 const body = { beforeDate: '15' }
117 await makePostBodyRequest({
119 token: server.accessToken,
120 path: myHistoryRemove,
122 expectedStatus: HttpStatusCode.BAD_REQUEST_400
126 it('Should succeed with a valid beforeDate param', async function () {
127 const body = { beforeDate: new Date().toISOString() }
128 await makePostBodyRequest({
130 token: server.accessToken,
131 path: myHistoryRemove,
133 expectedStatus: HttpStatusCode.NO_CONTENT_204
137 it('Should succeed without body', async function () {
138 await makePostBodyRequest({
140 token: server.accessToken,
141 path: myHistoryRemove,
142 expectedStatus: HttpStatusCode.NO_CONTENT_204
147 after(async function () {
148 await cleanupTests([ server ])