]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
6e46de09 | 2 | |
6e46de09 | 3 | import 'mocha' |
c55e3d72 C |
4 | import { checkBadCountPagination, checkBadStartPagination } from '@server/tests/shared' |
5 | import { HttpStatusCode } from '@shared/models' | |
6e46de09 | 6 | import { |
7c3b7976 | 7 | cleanupTests, |
254d3579 | 8 | createSingleServer, |
7177b46c | 9 | makeDeleteRequest, |
8b9a525a | 10 | makeGetRequest, |
6e46de09 C |
11 | makePostBodyRequest, |
12 | makePutBodyRequest, | |
254d3579 | 13 | PeerTubeServer, |
d23dd9fb | 14 | setAccessTokensToServers |
bf54587a | 15 | } from '@shared/server-commands' |
6e46de09 | 16 | |
6e46de09 | 17 | describe('Test videos history API validator', function () { |
a1587156 C |
18 | const myHistoryPath = '/api/v1/users/me/history/videos' |
19 | const myHistoryRemove = myHistoryPath + '/remove' | |
8b9a525a | 20 | let watchingPath: string |
254d3579 | 21 | let server: PeerTubeServer |
7177b46c | 22 | let videoId: number |
6e46de09 C |
23 | |
24 | // --------------------------------------------------------------- | |
25 | ||
26 | before(async function () { | |
27 | this.timeout(30000) | |
28 | ||
254d3579 | 29 | server = await createSingleServer(1) |
6e46de09 C |
30 | |
31 | await setAccessTokensToServers([ server ]) | |
32 | ||
7177b46c | 33 | const { id, uuid } = await server.videos.upload() |
d23dd9fb | 34 | watchingPath = '/api/v1/videos/' + uuid + '/watching' |
7177b46c | 35 | videoId = id |
6e46de09 C |
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 } | |
c0e8b12e | 42 | await makePutBodyRequest({ url: server.url, path: watchingPath, fields, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
6e46de09 C |
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' | |
2d53be02 RK |
48 | await makePutBodyRequest({ |
49 | url: server.url, | |
50 | path, | |
51 | fields, | |
52 | token: server.accessToken, | |
c0e8b12e | 53 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 |
2d53be02 | 54 | }) |
6e46de09 C |
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 | ||
2d53be02 RK |
61 | await makePutBodyRequest({ |
62 | url: server.url, | |
63 | path, | |
64 | fields, | |
65 | token: server.accessToken, | |
c0e8b12e | 66 | expectedStatus: HttpStatusCode.NOT_FOUND_404 |
2d53be02 | 67 | }) |
6e46de09 C |
68 | }) |
69 | ||
70 | it('Should fail with a bad current time', async function () { | |
71 | const fields = { currentTime: 'hello' } | |
2d53be02 RK |
72 | await makePutBodyRequest({ |
73 | url: server.url, | |
74 | path: watchingPath, | |
75 | fields, | |
76 | token: server.accessToken, | |
c0e8b12e | 77 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 |
2d53be02 | 78 | }) |
6e46de09 C |
79 | }) |
80 | ||
81 | it('Should succeed with the correct parameters', async function () { | |
82 | const fields = { currentTime: 5 } | |
83 | ||
2d53be02 RK |
84 | await makePutBodyRequest({ |
85 | url: server.url, | |
86 | path: watchingPath, | |
87 | fields, | |
88 | token: server.accessToken, | |
c0e8b12e | 89 | expectedStatus: HttpStatusCode.NO_CONTENT_204 |
2d53be02 | 90 | }) |
8b9a525a C |
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 () { | |
c0e8b12e | 104 | await makeGetRequest({ url: server.url, path: myHistoryPath, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
8b9a525a C |
105 | }) |
106 | ||
107 | it('Should succeed with the correct params', async function () { | |
c0e8b12e | 108 | await makeGetRequest({ url: server.url, token: server.accessToken, path: myHistoryPath, expectedStatus: HttpStatusCode.OK_200 }) |
8b9a525a C |
109 | }) |
110 | }) | |
111 | ||
7177b46c C |
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 () { | |
8b9a525a | 143 | it('Should fail with an unauthenticated user', async function () { |
c0e8b12e | 144 | await makePostBodyRequest({ url: server.url, path: myHistoryPath + '/remove', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
8b9a525a C |
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, | |
c0e8b12e | 154 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 |
8b9a525a C |
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, | |
c0e8b12e | 165 | expectedStatus: HttpStatusCode.NO_CONTENT_204 |
8b9a525a C |
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, | |
c0e8b12e | 174 | expectedStatus: HttpStatusCode.NO_CONTENT_204 |
8b9a525a | 175 | }) |
6e46de09 C |
176 | }) |
177 | }) | |
178 | ||
7c3b7976 C |
179 | after(async function () { |
180 | await cleanupTests([ server ]) | |
6e46de09 C |
181 | }) |
182 | }) |