]>
Commit | Line | Data |
---|---|---|
1 | /* tslint:disable:no-unused-expression */ | |
2 | ||
3 | import * as chai from 'chai' | |
4 | import { omit } from 'lodash' | |
5 | import 'mocha' | |
6 | import { | |
7 | createUser, deleteVideoChannel, flushTests, getAccountVideoChannelsList, getVideoChannelsList, immutableAssign, killallServers, | |
8 | makeGetRequest, makePostBodyRequest, makePutBodyRequest, runServer, ServerInfo, setAccessTokensToServers, userLogin | |
9 | } from '../../utils' | |
10 | import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' | |
11 | ||
12 | const expect = chai.expect | |
13 | ||
14 | describe('Test videos API validator', function () { | |
15 | const path = '/api/v1/videos/channels' | |
16 | let server: ServerInfo | |
17 | let accessTokenUser: string | |
18 | ||
19 | // --------------------------------------------------------------- | |
20 | ||
21 | before(async function () { | |
22 | this.timeout(30000) | |
23 | ||
24 | await flushTests() | |
25 | ||
26 | server = await runServer(1) | |
27 | ||
28 | await setAccessTokensToServers([ server ]) | |
29 | ||
30 | const user = { | |
31 | username: 'fake', | |
32 | password: 'fake_password' | |
33 | } | |
34 | await createUser(server.url, server.accessToken, user.username, user.password) | |
35 | accessTokenUser = await userLogin(server, user) | |
36 | }) | |
37 | ||
38 | describe('When listing a video channels', function () { | |
39 | it('Should fail with a bad start pagination', async function () { | |
40 | await checkBadStartPagination(server.url, path, server.accessToken) | |
41 | }) | |
42 | ||
43 | it('Should fail with a bad count pagination', async function () { | |
44 | await checkBadCountPagination(server.url, path, server.accessToken) | |
45 | }) | |
46 | ||
47 | it('Should fail with an incorrect sort', async function () { | |
48 | await checkBadSortPagination(server.url, path, server.accessToken) | |
49 | }) | |
50 | }) | |
51 | ||
52 | describe('When listing account video channels', function () { | |
53 | it('Should fail with bad account', async function () { | |
54 | await getAccountVideoChannelsList(server.url, 'hello', 400) | |
55 | }) | |
56 | ||
57 | it('Should fail with a unknown account', async function () { | |
58 | await getAccountVideoChannelsList(server.url, 154, 404) | |
59 | }) | |
60 | }) | |
61 | ||
62 | describe('When adding a video channel', function () { | |
63 | const baseCorrectParams = { | |
64 | name: 'hello', | |
65 | description: 'super description', | |
66 | support: 'super support text' | |
67 | } | |
68 | ||
69 | it('Should fail with a non authenticated user', async function () { | |
70 | await makePostBodyRequest({ url: server.url, path, token: 'none', fields: baseCorrectParams, statusCodeExpected: 401 }) | |
71 | }) | |
72 | ||
73 | it('Should fail with nothing', async function () { | |
74 | const fields = {} | |
75 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
76 | }) | |
77 | ||
78 | it('Should fail without name', async function () { | |
79 | const fields = omit(baseCorrectParams, 'name') | |
80 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
81 | }) | |
82 | ||
83 | it('Should fail with a long name', async function () { | |
84 | const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(25) }) | |
85 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
86 | }) | |
87 | ||
88 | it('Should fail with a long description', async function () { | |
89 | const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(60) }) | |
90 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
91 | }) | |
92 | ||
93 | it('Should fail with a long support text', async function () { | |
94 | const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(70) }) | |
95 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
96 | }) | |
97 | ||
98 | it('Should succeed with the correct parameters', async function () { | |
99 | await makePostBodyRequest({ | |
100 | url: server.url, | |
101 | path, | |
102 | token: server.accessToken, | |
103 | fields: baseCorrectParams, | |
104 | statusCodeExpected: 200 | |
105 | }) | |
106 | }) | |
107 | }) | |
108 | ||
109 | describe('When updating a video channel', function () { | |
110 | const baseCorrectParams = { | |
111 | name: 'hello', | |
112 | description: 'super description' | |
113 | } | |
114 | ||
115 | let videoChannelId | |
116 | ||
117 | before(async function () { | |
118 | const res = await getVideoChannelsList(server.url, 0, 1) | |
119 | videoChannelId = res.body.data[0].id | |
120 | }) | |
121 | ||
122 | it('Should fail with a non authenticated user', async function () { | |
123 | await makePutBodyRequest({ | |
124 | url: server.url, | |
125 | path: path + '/' + videoChannelId, | |
126 | token: 'hi', | |
127 | fields: baseCorrectParams, | |
128 | statusCodeExpected: 401 | |
129 | }) | |
130 | }) | |
131 | ||
132 | it('Should fail with another authenticated user', async function () { | |
133 | await makePutBodyRequest({ | |
134 | url: server.url, | |
135 | path: path + '/' + videoChannelId, | |
136 | token: accessTokenUser, | |
137 | fields: baseCorrectParams, | |
138 | statusCodeExpected: 403 | |
139 | }) | |
140 | }) | |
141 | ||
142 | it('Should fail with a long name', async function () { | |
143 | const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(25) }) | |
144 | await makePutBodyRequest({ url: server.url, path: path + '/' + videoChannelId, token: server.accessToken, fields }) | |
145 | }) | |
146 | ||
147 | it('Should fail with a long description', async function () { | |
148 | const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(60) }) | |
149 | await makePutBodyRequest({ url: server.url, path: path + '/' + videoChannelId, token: server.accessToken, fields }) | |
150 | }) | |
151 | ||
152 | it('Should fail with a long support text', async function () { | |
153 | const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(70) }) | |
154 | await makePutBodyRequest({ url: server.url, path: path + '/' + videoChannelId, token: server.accessToken, fields }) | |
155 | }) | |
156 | ||
157 | it('Should succeed with the correct parameters', async function () { | |
158 | await makePutBodyRequest({ | |
159 | url: server.url, | |
160 | path: path + '/' + videoChannelId, | |
161 | token: server.accessToken, | |
162 | fields: baseCorrectParams, | |
163 | statusCodeExpected: 204 | |
164 | }) | |
165 | }) | |
166 | }) | |
167 | ||
168 | describe('When getting a video channel', function () { | |
169 | let videoChannelId: number | |
170 | ||
171 | before(async function () { | |
172 | const res = await getVideoChannelsList(server.url, 0, 1) | |
173 | videoChannelId = res.body.data[0].id | |
174 | }) | |
175 | ||
176 | it('Should return the list of the video channels with nothing', async function () { | |
177 | const res = await makeGetRequest({ | |
178 | url: server.url, | |
179 | path, | |
180 | statusCodeExpected: 200 | |
181 | }) | |
182 | ||
183 | expect(res.body.data).to.be.an('array') | |
184 | }) | |
185 | ||
186 | it('Should fail without a correct uuid', async function () { | |
187 | await makeGetRequest({ | |
188 | url: server.url, | |
189 | path: path + '/coucou', | |
190 | statusCodeExpected: 400 | |
191 | }) | |
192 | }) | |
193 | ||
194 | it('Should return 404 with an incorrect video channel', async function () { | |
195 | await makeGetRequest({ | |
196 | url: server.url, | |
197 | path: path + '/4da6fde3-88f7-4d16-b119-108df5630b06', | |
198 | statusCodeExpected: 404 | |
199 | }) | |
200 | }) | |
201 | ||
202 | it('Should succeed with the correct parameters', async function () { | |
203 | await makeGetRequest({ | |
204 | url: server.url, | |
205 | path: path + '/' + videoChannelId, | |
206 | statusCodeExpected: 200 | |
207 | }) | |
208 | }) | |
209 | }) | |
210 | ||
211 | describe('When deleting a video channel', function () { | |
212 | let videoChannelId: number | |
213 | ||
214 | before(async function () { | |
215 | const res = await getVideoChannelsList(server.url, 0, 1) | |
216 | videoChannelId = res.body.data[0].id | |
217 | }) | |
218 | ||
219 | it('Should fail with a non authenticated user', async function () { | |
220 | await deleteVideoChannel(server.url, 'coucou', videoChannelId, 401) | |
221 | }) | |
222 | ||
223 | it('Should fail with another authenticated user', async function () { | |
224 | await deleteVideoChannel(server.url, accessTokenUser, videoChannelId, 403) | |
225 | }) | |
226 | ||
227 | it('Should fail with an unknown id', async function () { | |
228 | await deleteVideoChannel(server.url, server.accessToken, 454554, 404) | |
229 | }) | |
230 | ||
231 | it('Should succeed with the correct parameters', async function () { | |
232 | await deleteVideoChannel(server.url, server.accessToken, videoChannelId) | |
233 | }) | |
234 | ||
235 | it('Should fail to delete the last user video channel', async function () { | |
236 | const res = await getVideoChannelsList(server.url, 0, 1) | |
237 | videoChannelId = res.body.data[0].id | |
238 | ||
239 | await deleteVideoChannel(server.url, server.accessToken, videoChannelId, 409) | |
240 | }) | |
241 | }) | |
242 | ||
243 | after(async function () { | |
244 | killallServers([ server ]) | |
245 | ||
246 | // Keep the logs if the test failed | |
247 | if (this['ok']) { | |
248 | await flushTests() | |
249 | } | |
250 | }) | |
251 | }) |