]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
6e46de09 | 2 | |
6e46de09 C |
3 | import 'mocha' |
4 | import { | |
8b9a525a C |
5 | checkBadCountPagination, |
6 | checkBadStartPagination, | |
7c3b7976 C |
7 | cleanupTests, |
8 | flushAndRunServer, | |
8b9a525a | 9 | makeGetRequest, |
6e46de09 C |
10 | makePostBodyRequest, |
11 | makePutBodyRequest, | |
6e46de09 C |
12 | ServerInfo, |
13 | setAccessTokensToServers, | |
14 | uploadVideo | |
94565d52 | 15 | } from '../../../../shared/extra-utils' |
2d53be02 | 16 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' |
6e46de09 | 17 | |
6e46de09 | 18 | describe('Test videos history API validator', function () { |
a1587156 C |
19 | const myHistoryPath = '/api/v1/users/me/history/videos' |
20 | const myHistoryRemove = myHistoryPath + '/remove' | |
8b9a525a | 21 | let watchingPath: string |
6e46de09 C |
22 | let server: ServerInfo |
23 | ||
24 | // --------------------------------------------------------------- | |
25 | ||
26 | before(async function () { | |
27 | this.timeout(30000) | |
28 | ||
210feb6c | 29 | server = await flushAndRunServer(1) |
6e46de09 C |
30 | |
31 | await setAccessTokensToServers([ server ]) | |
32 | ||
33 | const res = await uploadVideo(server.url, server.accessToken, {}) | |
34 | const videoUUID = res.body.video.uuid | |
35 | ||
8b9a525a | 36 | watchingPath = '/api/v1/videos/' + videoUUID + '/watching' |
6e46de09 C |
37 | }) |
38 | ||
39 | describe('When notifying a user is watching a video', function () { | |
40 | ||
41 | it('Should fail with an unauthenticated user', async function () { | |
42 | const fields = { currentTime: 5 } | |
2d53be02 | 43 | await makePutBodyRequest({ url: server.url, path: watchingPath, fields, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) |
6e46de09 C |
44 | }) |
45 | ||
46 | it('Should fail with an incorrect video id', async function () { | |
47 | const fields = { currentTime: 5 } | |
48 | const path = '/api/v1/videos/blabla/watching' | |
2d53be02 RK |
49 | await makePutBodyRequest({ |
50 | url: server.url, | |
51 | path, | |
52 | fields, | |
53 | token: server.accessToken, | |
54 | statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 | |
55 | }) | |
6e46de09 C |
56 | }) |
57 | ||
58 | it('Should fail with an unknown video', async function () { | |
59 | const fields = { currentTime: 5 } | |
60 | const path = '/api/v1/videos/d91fff41-c24d-4508-8e13-3bd5902c3b02/watching' | |
61 | ||
2d53be02 RK |
62 | await makePutBodyRequest({ |
63 | url: server.url, | |
64 | path, | |
65 | fields, | |
66 | token: server.accessToken, | |
67 | statusCodeExpected: HttpStatusCode.NOT_FOUND_404 | |
68 | }) | |
6e46de09 C |
69 | }) |
70 | ||
71 | it('Should fail with a bad current time', async function () { | |
72 | const fields = { currentTime: 'hello' } | |
2d53be02 RK |
73 | await makePutBodyRequest({ |
74 | url: server.url, | |
75 | path: watchingPath, | |
76 | fields, | |
77 | token: server.accessToken, | |
78 | statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 | |
79 | }) | |
6e46de09 C |
80 | }) |
81 | ||
82 | it('Should succeed with the correct parameters', async function () { | |
83 | const fields = { currentTime: 5 } | |
84 | ||
2d53be02 RK |
85 | await makePutBodyRequest({ |
86 | url: server.url, | |
87 | path: watchingPath, | |
88 | fields, | |
89 | token: server.accessToken, | |
90 | statusCodeExpected: HttpStatusCode.NO_CONTENT_204 | |
91 | }) | |
8b9a525a C |
92 | }) |
93 | }) | |
94 | ||
95 | describe('When listing user videos history', function () { | |
96 | it('Should fail with a bad start pagination', async function () { | |
97 | await checkBadStartPagination(server.url, myHistoryPath, server.accessToken) | |
98 | }) | |
99 | ||
100 | it('Should fail with a bad count pagination', async function () { | |
101 | await checkBadCountPagination(server.url, myHistoryPath, server.accessToken) | |
102 | }) | |
103 | ||
104 | it('Should fail with an unauthenticated user', async function () { | |
2d53be02 | 105 | await makeGetRequest({ url: server.url, path: myHistoryPath, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) |
8b9a525a C |
106 | }) |
107 | ||
108 | it('Should succeed with the correct params', async function () { | |
2d53be02 | 109 | await makeGetRequest({ url: server.url, token: server.accessToken, path: myHistoryPath, statusCodeExpected: HttpStatusCode.OK_200 }) |
8b9a525a C |
110 | }) |
111 | }) | |
112 | ||
113 | describe('When removing user videos history', function () { | |
114 | it('Should fail with an unauthenticated user', async function () { | |
2d53be02 | 115 | await makePostBodyRequest({ url: server.url, path: myHistoryPath + '/remove', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) |
8b9a525a C |
116 | }) |
117 | ||
118 | it('Should fail with a bad beforeDate parameter', async function () { | |
119 | const body = { beforeDate: '15' } | |
120 | await makePostBodyRequest({ | |
121 | url: server.url, | |
122 | token: server.accessToken, | |
123 | path: myHistoryRemove, | |
124 | fields: body, | |
2d53be02 | 125 | statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 |
8b9a525a C |
126 | }) |
127 | }) | |
128 | ||
129 | it('Should succeed with a valid beforeDate param', async function () { | |
130 | const body = { beforeDate: new Date().toISOString() } | |
131 | await makePostBodyRequest({ | |
132 | url: server.url, | |
133 | token: server.accessToken, | |
134 | path: myHistoryRemove, | |
135 | fields: body, | |
2d53be02 | 136 | statusCodeExpected: HttpStatusCode.NO_CONTENT_204 |
8b9a525a C |
137 | }) |
138 | }) | |
139 | ||
140 | it('Should succeed without body', async function () { | |
141 | await makePostBodyRequest({ | |
142 | url: server.url, | |
143 | token: server.accessToken, | |
144 | path: myHistoryRemove, | |
2d53be02 | 145 | statusCodeExpected: HttpStatusCode.NO_CONTENT_204 |
8b9a525a | 146 | }) |
6e46de09 C |
147 | }) |
148 | }) | |
149 | ||
7c3b7976 C |
150 | after(async function () { |
151 | await cleanupTests([ server ]) | |
6e46de09 C |
152 | }) |
153 | }) |