aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/check-params')
-rw-r--r--server/tests/api/check-params/video-channels.ts101
1 files changed, 71 insertions, 30 deletions
diff --git a/server/tests/api/check-params/video-channels.ts b/server/tests/api/check-params/video-channels.ts
index 43c5462ee..acb6bdd57 100644
--- a/server/tests/api/check-params/video-channels.ts
+++ b/server/tests/api/check-params/video-channels.ts
@@ -4,15 +4,29 @@ import * as chai from 'chai'
4import { omit } from 'lodash' 4import { omit } from 'lodash'
5import 'mocha' 5import 'mocha'
6import { 6import {
7 createUser, deleteVideoChannel, flushTests, getAccountVideoChannelsList, getVideoChannelsList, immutableAssign, killallServers, 7 createUser,
8 makeGetRequest, makePostBodyRequest, makePutBodyRequest, runServer, ServerInfo, setAccessTokensToServers, userLogin 8 deleteVideoChannel,
9 flushTests,
10 getAccountVideoChannelsList,
11 getVideoChannelsList,
12 immutableAssign,
13 killallServers,
14 makeGetRequest,
15 makePostBodyRequest,
16 makePutBodyRequest,
17 runServer,
18 ServerInfo,
19 setAccessTokensToServers,
20 userLogin
9} from '../../utils' 21} from '../../utils'
10import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' 22import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
23import { getAccountsList } from '../../utils/users/accounts'
11 24
12const expect = chai.expect 25const expect = chai.expect
13 26
14describe('Test videos API validator', function () { 27describe('Test videos API validator', function () {
15 const path = '/api/v1/videos/channels' 28 const videoChannelPath = '/api/v1/video-channels'
29 const accountPath = '/api/v1/accounts/'
16 let server: ServerInfo 30 let server: ServerInfo
17 let accessTokenUser: string 31 let accessTokenUser: string
18 32
@@ -37,15 +51,15 @@ describe('Test videos API validator', function () {
37 51
38 describe('When listing a video channels', function () { 52 describe('When listing a video channels', function () {
39 it('Should fail with a bad start pagination', async function () { 53 it('Should fail with a bad start pagination', async function () {
40 await checkBadStartPagination(server.url, path, server.accessToken) 54 await checkBadStartPagination(server.url, videoChannelPath, server.accessToken)
41 }) 55 })
42 56
43 it('Should fail with a bad count pagination', async function () { 57 it('Should fail with a bad count pagination', async function () {
44 await checkBadCountPagination(server.url, path, server.accessToken) 58 await checkBadCountPagination(server.url, videoChannelPath, server.accessToken)
45 }) 59 })
46 60
47 it('Should fail with an incorrect sort', async function () { 61 it('Should fail with an incorrect sort', async function () {
48 await checkBadSortPagination(server.url, path, server.accessToken) 62 await checkBadSortPagination(server.url, videoChannelPath, server.accessToken)
49 }) 63 })
50 }) 64 })
51 65
@@ -60,12 +74,20 @@ describe('Test videos API validator', function () {
60 }) 74 })
61 75
62 describe('When adding a video channel', function () { 76 describe('When adding a video channel', function () {
77 let path: string
78
63 const baseCorrectParams = { 79 const baseCorrectParams = {
64 name: 'hello', 80 name: 'hello',
65 description: 'super description', 81 description: 'super description',
66 support: 'super support text' 82 support: 'super support text'
67 } 83 }
68 84
85 before(async function () {
86 const res = await getAccountsList(server.url)
87 const accountId = res.body.data[0].id
88 path = accountPath + accountId + '/video-channels'
89 })
90
69 it('Should fail with a non authenticated user', async function () { 91 it('Should fail with a non authenticated user', async function () {
70 await makePostBodyRequest({ url: server.url, path, token: 'none', fields: baseCorrectParams, statusCodeExpected: 401 }) 92 await makePostBodyRequest({ url: server.url, path, token: 'none', fields: baseCorrectParams, statusCodeExpected: 401 })
71 }) 93 })
@@ -107,22 +129,27 @@ describe('Test videos API validator', function () {
107 }) 129 })
108 130
109 describe('When updating a video channel', function () { 131 describe('When updating a video channel', function () {
132 let path: string
133
110 const baseCorrectParams = { 134 const baseCorrectParams = {
111 name: 'hello', 135 name: 'hello',
112 description: 'super description' 136 description: 'super description'
113 } 137 }
114 138
115 let videoChannelId
116
117 before(async function () { 139 before(async function () {
118 const res = await getVideoChannelsList(server.url, 0, 1) 140 const res1 = await getVideoChannelsList(server.url, 0, 1)
119 videoChannelId = res.body.data[0].id 141 const videoChannelId = res1.body.data[0].id
142
143 const res2 = await getAccountsList(server.url)
144 const accountId = res2.body.data[0].id
145
146 path = accountPath + accountId + '/video-channels/' + videoChannelId
120 }) 147 })
121 148
122 it('Should fail with a non authenticated user', async function () { 149 it('Should fail with a non authenticated user', async function () {
123 await makePutBodyRequest({ 150 await makePutBodyRequest({
124 url: server.url, 151 url: server.url,
125 path: path + '/' + videoChannelId, 152 path,
126 token: 'hi', 153 token: 'hi',
127 fields: baseCorrectParams, 154 fields: baseCorrectParams,
128 statusCodeExpected: 401 155 statusCodeExpected: 401
@@ -132,7 +159,7 @@ describe('Test videos API validator', function () {
132 it('Should fail with another authenticated user', async function () { 159 it('Should fail with another authenticated user', async function () {
133 await makePutBodyRequest({ 160 await makePutBodyRequest({
134 url: server.url, 161 url: server.url,
135 path: path + '/' + videoChannelId, 162 path,
136 token: accessTokenUser, 163 token: accessTokenUser,
137 fields: baseCorrectParams, 164 fields: baseCorrectParams,
138 statusCodeExpected: 403 165 statusCodeExpected: 403
@@ -141,23 +168,23 @@ describe('Test videos API validator', function () {
141 168
142 it('Should fail with a long name', async function () { 169 it('Should fail with a long name', async function () {
143 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(25) }) 170 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(25) })
144 await makePutBodyRequest({ url: server.url, path: path + '/' + videoChannelId, token: server.accessToken, fields }) 171 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
145 }) 172 })
146 173
147 it('Should fail with a long description', async function () { 174 it('Should fail with a long description', async function () {
148 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(60) }) 175 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(60) })
149 await makePutBodyRequest({ url: server.url, path: path + '/' + videoChannelId, token: server.accessToken, fields }) 176 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
150 }) 177 })
151 178
152 it('Should fail with a long support text', async function () { 179 it('Should fail with a long support text', async function () {
153 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(70) }) 180 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(70) })
154 await makePutBodyRequest({ url: server.url, path: path + '/' + videoChannelId, token: server.accessToken, fields }) 181 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
155 }) 182 })
156 183
157 it('Should succeed with the correct parameters', async function () { 184 it('Should succeed with the correct parameters', async function () {
158 await makePutBodyRequest({ 185 await makePutBodyRequest({
159 url: server.url, 186 url: server.url,
160 path: path + '/' + videoChannelId, 187 path,
161 token: server.accessToken, 188 token: server.accessToken,
162 fields: baseCorrectParams, 189 fields: baseCorrectParams,
163 statusCodeExpected: 204 190 statusCodeExpected: 204
@@ -166,17 +193,23 @@ describe('Test videos API validator', function () {
166 }) 193 })
167 194
168 describe('When getting a video channel', function () { 195 describe('When getting a video channel', function () {
196 let basePath: string
169 let videoChannelId: number 197 let videoChannelId: number
170 198
171 before(async function () { 199 before(async function () {
172 const res = await getVideoChannelsList(server.url, 0, 1) 200 const res1 = await getVideoChannelsList(server.url, 0, 1)
173 videoChannelId = res.body.data[0].id 201 videoChannelId = res1.body.data[0].id
202
203 const res2 = await getAccountsList(server.url)
204 const accountId = res2.body.data[0].id
205
206 basePath = accountPath + accountId + '/video-channels'
174 }) 207 })
175 208
176 it('Should return the list of the video channels with nothing', async function () { 209 it('Should return the list of the video channels with nothing', async function () {
177 const res = await makeGetRequest({ 210 const res = await makeGetRequest({
178 url: server.url, 211 url: server.url,
179 path, 212 path: basePath,
180 statusCodeExpected: 200 213 statusCodeExpected: 200
181 }) 214 })
182 215
@@ -186,7 +219,7 @@ describe('Test videos API validator', function () {
186 it('Should fail without a correct uuid', async function () { 219 it('Should fail without a correct uuid', async function () {
187 await makeGetRequest({ 220 await makeGetRequest({
188 url: server.url, 221 url: server.url,
189 path: path + '/coucou', 222 path: basePath + '/coucou',
190 statusCodeExpected: 400 223 statusCodeExpected: 400
191 }) 224 })
192 }) 225 })
@@ -194,7 +227,7 @@ describe('Test videos API validator', function () {
194 it('Should return 404 with an incorrect video channel', async function () { 227 it('Should return 404 with an incorrect video channel', async function () {
195 await makeGetRequest({ 228 await makeGetRequest({
196 url: server.url, 229 url: server.url,
197 path: path + '/4da6fde3-88f7-4d16-b119-108df5630b06', 230 path: basePath + '/4da6fde3-88f7-4d16-b119-108df5630b06',
198 statusCodeExpected: 404 231 statusCodeExpected: 404
199 }) 232 })
200 }) 233 })
@@ -202,7 +235,7 @@ describe('Test videos API validator', function () {
202 it('Should succeed with the correct parameters', async function () { 235 it('Should succeed with the correct parameters', async function () {
203 await makeGetRequest({ 236 await makeGetRequest({
204 url: server.url, 237 url: server.url,
205 path: path + '/' + videoChannelId, 238 path: basePath + '/' + videoChannelId,
206 statusCodeExpected: 200 239 statusCodeExpected: 200
207 }) 240 })
208 }) 241 })
@@ -210,33 +243,41 @@ describe('Test videos API validator', function () {
210 243
211 describe('When deleting a video channel', function () { 244 describe('When deleting a video channel', function () {
212 let videoChannelId: number 245 let videoChannelId: number
246 let accountId: number
213 247
214 before(async function () { 248 before(async function () {
215 const res = await getVideoChannelsList(server.url, 0, 1) 249 const res1 = await getVideoChannelsList(server.url, 0, 1)
216 videoChannelId = res.body.data[0].id 250 videoChannelId = res1.body.data[0].id
251
252 const res2 = await getAccountsList(server.url)
253 accountId = res2.body.data[0].id
217 }) 254 })
218 255
219 it('Should fail with a non authenticated user', async function () { 256 it('Should fail with a non authenticated user', async function () {
220 await deleteVideoChannel(server.url, 'coucou', videoChannelId, 401) 257 await deleteVideoChannel(server.url, 'coucou', accountId, videoChannelId, 401)
221 }) 258 })
222 259
223 it('Should fail with another authenticated user', async function () { 260 it('Should fail with another authenticated user', async function () {
224 await deleteVideoChannel(server.url, accessTokenUser, videoChannelId, 403) 261 await deleteVideoChannel(server.url, accessTokenUser, accountId, videoChannelId, 403)
262 })
263
264 it('Should fail with an unknown account id', async function () {
265 await deleteVideoChannel(server.url, server.accessToken, 454554,videoChannelId, 404)
225 }) 266 })
226 267
227 it('Should fail with an unknown id', async function () { 268 it('Should fail with an unknown video channel id', async function () {
228 await deleteVideoChannel(server.url, server.accessToken, 454554, 404) 269 await deleteVideoChannel(server.url, server.accessToken, accountId,454554, 404)
229 }) 270 })
230 271
231 it('Should succeed with the correct parameters', async function () { 272 it('Should succeed with the correct parameters', async function () {
232 await deleteVideoChannel(server.url, server.accessToken, videoChannelId) 273 await deleteVideoChannel(server.url, server.accessToken, accountId, videoChannelId)
233 }) 274 })
234 275
235 it('Should fail to delete the last user video channel', async function () { 276 it('Should fail to delete the last user video channel', async function () {
236 const res = await getVideoChannelsList(server.url, 0, 1) 277 const res = await getVideoChannelsList(server.url, 0, 1)
237 videoChannelId = res.body.data[0].id 278 videoChannelId = res.body.data[0].id
238 279
239 await deleteVideoChannel(server.url, server.accessToken, videoChannelId, 409) 280 await deleteVideoChannel(server.url, server.accessToken, accountId, videoChannelId, 409)
240 }) 281 })
241 }) 282 })
242 283