]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/check-params/videos-history.ts
Upgrade minor dependencies
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / videos-history.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import 'mocha'
4 import { checkBadCountPagination, checkBadStartPagination } from '@server/tests/shared'
5 import { HttpStatusCode } from '@shared/models'
6 import {
7 cleanupTests,
8 createSingleServer,
9 makeGetRequest,
10 makePostBodyRequest,
11 makePutBodyRequest,
12 PeerTubeServer,
13 setAccessTokensToServers
14 } from '@shared/server-commands'
15
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
21
22 // ---------------------------------------------------------------
23
24 before(async function () {
25 this.timeout(30000)
26
27 server = await createSingleServer(1)
28
29 await setAccessTokensToServers([ server ])
30
31 const { uuid } = await server.videos.upload()
32 watchingPath = '/api/v1/videos/' + uuid + '/watching'
33 })
34
35 describe('When notifying a user is watching a video', function () {
36
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 })
40 })
41
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({
46 url: server.url,
47 path,
48 fields,
49 token: server.accessToken,
50 expectedStatus: HttpStatusCode.BAD_REQUEST_400
51 })
52 })
53
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'
57
58 await makePutBodyRequest({
59 url: server.url,
60 path,
61 fields,
62 token: server.accessToken,
63 expectedStatus: HttpStatusCode.NOT_FOUND_404
64 })
65 })
66
67 it('Should fail with a bad current time', async function () {
68 const fields = { currentTime: 'hello' }
69 await makePutBodyRequest({
70 url: server.url,
71 path: watchingPath,
72 fields,
73 token: server.accessToken,
74 expectedStatus: HttpStatusCode.BAD_REQUEST_400
75 })
76 })
77
78 it('Should succeed with the correct parameters', async function () {
79 const fields = { currentTime: 5 }
80
81 await makePutBodyRequest({
82 url: server.url,
83 path: watchingPath,
84 fields,
85 token: server.accessToken,
86 expectedStatus: HttpStatusCode.NO_CONTENT_204
87 })
88 })
89 })
90
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)
94 })
95
96 it('Should fail with a bad count pagination', async function () {
97 await checkBadCountPagination(server.url, myHistoryPath, server.accessToken)
98 })
99
100 it('Should fail with an unauthenticated user', async function () {
101 await makeGetRequest({ url: server.url, path: myHistoryPath, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
102 })
103
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 })
106 })
107 })
108
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 })
112 })
113
114 it('Should fail with a bad beforeDate parameter', async function () {
115 const body = { beforeDate: '15' }
116 await makePostBodyRequest({
117 url: server.url,
118 token: server.accessToken,
119 path: myHistoryRemove,
120 fields: body,
121 expectedStatus: HttpStatusCode.BAD_REQUEST_400
122 })
123 })
124
125 it('Should succeed with a valid beforeDate param', async function () {
126 const body = { beforeDate: new Date().toISOString() }
127 await makePostBodyRequest({
128 url: server.url,
129 token: server.accessToken,
130 path: myHistoryRemove,
131 fields: body,
132 expectedStatus: HttpStatusCode.NO_CONTENT_204
133 })
134 })
135
136 it('Should succeed without body', async function () {
137 await makePostBodyRequest({
138 url: server.url,
139 token: server.accessToken,
140 path: myHistoryRemove,
141 expectedStatus: HttpStatusCode.NO_CONTENT_204
142 })
143 })
144 })
145
146 after(async function () {
147 await cleanupTests([ server ])
148 })
149 })