]>
Commit | Line | Data |
---|---|---|
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 | makeDeleteRequest, | |
10 | makeGetRequest, | |
11 | makePostBodyRequest, | |
12 | makePutBodyRequest, | |
13 | PeerTubeServer, | |
14 | setAccessTokensToServers | |
15 | } from '@shared/server-commands' | |
16 | ||
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 | |
22 | let videoId: number | |
23 | ||
24 | // --------------------------------------------------------------- | |
25 | ||
26 | before(async function () { | |
27 | this.timeout(30000) | |
28 | ||
29 | server = await createSingleServer(1) | |
30 | ||
31 | await setAccessTokensToServers([ server ]) | |
32 | ||
33 | const { id, uuid } = await server.videos.upload() | |
34 | watchingPath = '/api/v1/videos/' + uuid + '/watching' | |
35 | videoId = id | |
36 | }) | |
37 | ||
38 | describe('When notifying a user is watching a video', function () { | |
39 | ||
40 | it('Should fail with an unauthenticated user', async function () { | |
41 | const fields = { currentTime: 5 } | |
42 | await makePutBodyRequest({ url: server.url, path: watchingPath, fields, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) | |
43 | }) | |
44 | ||
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({ | |
49 | url: server.url, | |
50 | path, | |
51 | fields, | |
52 | token: server.accessToken, | |
53 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | |
54 | }) | |
55 | }) | |
56 | ||
57 | it('Should fail with an unknown video', async function () { | |
58 | const fields = { currentTime: 5 } | |
59 | const path = '/api/v1/videos/d91fff41-c24d-4508-8e13-3bd5902c3b02/watching' | |
60 | ||
61 | await makePutBodyRequest({ | |
62 | url: server.url, | |
63 | path, | |
64 | fields, | |
65 | token: server.accessToken, | |
66 | expectedStatus: HttpStatusCode.NOT_FOUND_404 | |
67 | }) | |
68 | }) | |
69 | ||
70 | it('Should fail with a bad current time', async function () { | |
71 | const fields = { currentTime: 'hello' } | |
72 | await makePutBodyRequest({ | |
73 | url: server.url, | |
74 | path: watchingPath, | |
75 | fields, | |
76 | token: server.accessToken, | |
77 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | |
78 | }) | |
79 | }) | |
80 | ||
81 | it('Should succeed with the correct parameters', async function () { | |
82 | const fields = { currentTime: 5 } | |
83 | ||
84 | await makePutBodyRequest({ | |
85 | url: server.url, | |
86 | path: watchingPath, | |
87 | fields, | |
88 | token: server.accessToken, | |
89 | expectedStatus: HttpStatusCode.NO_CONTENT_204 | |
90 | }) | |
91 | }) | |
92 | }) | |
93 | ||
94 | describe('When listing user videos history', function () { | |
95 | it('Should fail with a bad start pagination', async function () { | |
96 | await checkBadStartPagination(server.url, myHistoryPath, server.accessToken) | |
97 | }) | |
98 | ||
99 | it('Should fail with a bad count pagination', async function () { | |
100 | await checkBadCountPagination(server.url, myHistoryPath, server.accessToken) | |
101 | }) | |
102 | ||
103 | it('Should fail with an unauthenticated user', async function () { | |
104 | await makeGetRequest({ url: server.url, path: myHistoryPath, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) | |
105 | }) | |
106 | ||
107 | it('Should succeed with the correct params', async function () { | |
108 | await makeGetRequest({ url: server.url, token: server.accessToken, path: myHistoryPath, expectedStatus: HttpStatusCode.OK_200 }) | |
109 | }) | |
110 | }) | |
111 | ||
112 | describe('When removing a specific user video history element', function () { | |
113 | let path: string | |
114 | ||
115 | before(function () { | |
116 | path = myHistoryPath + '/' + videoId | |
117 | }) | |
118 | ||
119 | it('Should fail with an unauthenticated user', async function () { | |
120 | await makeDeleteRequest({ url: server.url, path, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) | |
121 | }) | |
122 | ||
123 | it('Should fail with a bad videoId parameter', async function () { | |
124 | await makeDeleteRequest({ | |
125 | url: server.url, | |
126 | token: server.accessToken, | |
127 | path: myHistoryRemove + '/hi', | |
128 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | |
129 | }) | |
130 | }) | |
131 | ||
132 | it('Should succeed with the correct parameters', async function () { | |
133 | await makeDeleteRequest({ | |
134 | url: server.url, | |
135 | token: server.accessToken, | |
136 | path, | |
137 | expectedStatus: HttpStatusCode.NO_CONTENT_204 | |
138 | }) | |
139 | }) | |
140 | }) | |
141 | ||
142 | describe('When removing all user videos history', function () { | |
143 | it('Should fail with an unauthenticated user', async function () { | |
144 | await makePostBodyRequest({ url: server.url, path: myHistoryPath + '/remove', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) | |
145 | }) | |
146 | ||
147 | it('Should fail with a bad beforeDate parameter', async function () { | |
148 | const body = { beforeDate: '15' } | |
149 | await makePostBodyRequest({ | |
150 | url: server.url, | |
151 | token: server.accessToken, | |
152 | path: myHistoryRemove, | |
153 | fields: body, | |
154 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | |
155 | }) | |
156 | }) | |
157 | ||
158 | it('Should succeed with a valid beforeDate param', async function () { | |
159 | const body = { beforeDate: new Date().toISOString() } | |
160 | await makePostBodyRequest({ | |
161 | url: server.url, | |
162 | token: server.accessToken, | |
163 | path: myHistoryRemove, | |
164 | fields: body, | |
165 | expectedStatus: HttpStatusCode.NO_CONTENT_204 | |
166 | }) | |
167 | }) | |
168 | ||
169 | it('Should succeed without body', async function () { | |
170 | await makePostBodyRequest({ | |
171 | url: server.url, | |
172 | token: server.accessToken, | |
173 | path: myHistoryRemove, | |
174 | expectedStatus: HttpStatusCode.NO_CONTENT_204 | |
175 | }) | |
176 | }) | |
177 | }) | |
178 | ||
179 | after(async function () { | |
180 | await cleanupTests([ server ]) | |
181 | }) | |
182 | }) |