aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params/video-channels.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/check-params/video-channels.ts')
-rw-r--r--server/tests/api/check-params/video-channels.ts73
1 files changed, 29 insertions, 44 deletions
diff --git a/server/tests/api/check-params/video-channels.ts b/server/tests/api/check-params/video-channels.ts
index acb6bdd57..25b2dc9b9 100644
--- a/server/tests/api/check-params/video-channels.ts
+++ b/server/tests/api/check-params/video-channels.ts
@@ -7,7 +7,7 @@ import {
7 createUser, 7 createUser,
8 deleteVideoChannel, 8 deleteVideoChannel,
9 flushTests, 9 flushTests,
10 getAccountVideoChannelsList, 10 getAccountVideoChannelsList, getMyUserInformation,
11 getVideoChannelsList, 11 getVideoChannelsList,
12 immutableAssign, 12 immutableAssign,
13 killallServers, 13 killallServers,
@@ -21,6 +21,7 @@ import {
21} from '../../utils' 21} from '../../utils'
22import { 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' 23import { getAccountsList } from '../../utils/users/accounts'
24import { User } from '../../../../shared/models/users'
24 25
25const expect = chai.expect 26const expect = chai.expect
26 27
@@ -29,6 +30,8 @@ describe('Test videos API validator', function () {
29 const accountPath = '/api/v1/accounts/' 30 const accountPath = '/api/v1/accounts/'
30 let server: ServerInfo 31 let server: ServerInfo
31 let accessTokenUser: string 32 let accessTokenUser: string
33 let accountUUID: string
34 let videoChannelUUID: string
32 35
33 // --------------------------------------------------------------- 36 // ---------------------------------------------------------------
34 37
@@ -45,8 +48,18 @@ describe('Test videos API validator', function () {
45 username: 'fake', 48 username: 'fake',
46 password: 'fake_password' 49 password: 'fake_password'
47 } 50 }
48 await createUser(server.url, server.accessToken, user.username, user.password) 51
49 accessTokenUser = await userLogin(server, user) 52 {
53 await createUser(server.url, server.accessToken, user.username, user.password)
54 accessTokenUser = await userLogin(server, user)
55 }
56
57 {
58 const res = await getMyUserInformation(server.url, server.accessToken)
59 const user: User = res.body
60 accountUUID = user.account.uuid
61 videoChannelUUID = user.videoChannels[0].uuid
62 }
50 }) 63 })
51 64
52 describe('When listing a video channels', function () { 65 describe('When listing a video channels', function () {
@@ -74,18 +87,15 @@ describe('Test videos API validator', function () {
74 }) 87 })
75 88
76 describe('When adding a video channel', function () { 89 describe('When adding a video channel', function () {
77 let path: string
78
79 const baseCorrectParams = { 90 const baseCorrectParams = {
80 name: 'hello', 91 name: 'hello',
81 description: 'super description', 92 description: 'super description',
82 support: 'super support text' 93 support: 'super support text'
83 } 94 }
95 let path: string
84 96
85 before(async function () { 97 before(async function () {
86 const res = await getAccountsList(server.url) 98 path = accountPath + accountUUID + '/video-channels'
87 const accountId = res.body.data[0].id
88 path = accountPath + accountId + '/video-channels'
89 }) 99 })
90 100
91 it('Should fail with a non authenticated user', async function () { 101 it('Should fail with a non authenticated user', async function () {
@@ -129,21 +139,14 @@ describe('Test videos API validator', function () {
129 }) 139 })
130 140
131 describe('When updating a video channel', function () { 141 describe('When updating a video channel', function () {
132 let path: string
133
134 const baseCorrectParams = { 142 const baseCorrectParams = {
135 name: 'hello', 143 name: 'hello',
136 description: 'super description' 144 description: 'super description'
137 } 145 }
146 let path: string
138 147
139 before(async function () { 148 before(async function () {
140 const res1 = await getVideoChannelsList(server.url, 0, 1) 149 path = accountPath + accountUUID + '/video-channels/' + videoChannelUUID
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
147 }) 150 })
148 151
149 it('Should fail with a non authenticated user', async function () { 152 it('Should fail with a non authenticated user', async function () {
@@ -194,16 +197,9 @@ describe('Test videos API validator', function () {
194 197
195 describe('When getting a video channel', function () { 198 describe('When getting a video channel', function () {
196 let basePath: string 199 let basePath: string
197 let videoChannelId: number
198 200
199 before(async function () { 201 before(async function () {
200 const res1 = await getVideoChannelsList(server.url, 0, 1) 202 basePath = accountPath + accountUUID + '/video-channels'
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'
207 }) 203 })
208 204
209 it('Should return the list of the video channels with nothing', async function () { 205 it('Should return the list of the video channels with nothing', async function () {
@@ -235,49 +231,38 @@ describe('Test videos API validator', function () {
235 it('Should succeed with the correct parameters', async function () { 231 it('Should succeed with the correct parameters', async function () {
236 await makeGetRequest({ 232 await makeGetRequest({
237 url: server.url, 233 url: server.url,
238 path: basePath + '/' + videoChannelId, 234 path: basePath + '/' + videoChannelUUID,
239 statusCodeExpected: 200 235 statusCodeExpected: 200
240 }) 236 })
241 }) 237 })
242 }) 238 })
243 239
244 describe('When deleting a video channel', function () { 240 describe('When deleting a video channel', function () {
245 let videoChannelId: number
246 let accountId: number
247
248 before(async function () {
249 const res1 = await getVideoChannelsList(server.url, 0, 1)
250 videoChannelId = res1.body.data[0].id
251
252 const res2 = await getAccountsList(server.url)
253 accountId = res2.body.data[0].id
254 })
255
256 it('Should fail with a non authenticated user', async function () { 241 it('Should fail with a non authenticated user', async function () {
257 await deleteVideoChannel(server.url, 'coucou', accountId, videoChannelId, 401) 242 await deleteVideoChannel(server.url, 'coucou', accountUUID, videoChannelUUID, 401)
258 }) 243 })
259 244
260 it('Should fail with another authenticated user', async function () { 245 it('Should fail with another authenticated user', async function () {
261 await deleteVideoChannel(server.url, accessTokenUser, accountId, videoChannelId, 403) 246 await deleteVideoChannel(server.url, accessTokenUser, accountUUID, videoChannelUUID, 403)
262 }) 247 })
263 248
264 it('Should fail with an unknown account id', async function () { 249 it('Should fail with an unknown account id', async function () {
265 await deleteVideoChannel(server.url, server.accessToken, 454554,videoChannelId, 404) 250 await deleteVideoChannel(server.url, server.accessToken, 454554,videoChannelUUID, 404)
266 }) 251 })
267 252
268 it('Should fail with an unknown video channel id', async function () { 253 it('Should fail with an unknown video channel id', async function () {
269 await deleteVideoChannel(server.url, server.accessToken, accountId,454554, 404) 254 await deleteVideoChannel(server.url, server.accessToken, accountUUID,454554, 404)
270 }) 255 })
271 256
272 it('Should succeed with the correct parameters', async function () { 257 it('Should succeed with the correct parameters', async function () {
273 await deleteVideoChannel(server.url, server.accessToken, accountId, videoChannelId) 258 await deleteVideoChannel(server.url, server.accessToken, accountUUID, videoChannelUUID)
274 }) 259 })
275 260
276 it('Should fail to delete the last user video channel', async function () { 261 it('Should fail to delete the last user video channel', async function () {
277 const res = await getVideoChannelsList(server.url, 0, 1) 262 const res = await getVideoChannelsList(server.url, 0, 1)
278 videoChannelId = res.body.data[0].id 263 const lastVideoChannelUUID = res.body.data[0].uuid
279 264
280 await deleteVideoChannel(server.url, server.accessToken, accountId, videoChannelId, 409) 265 await deleteVideoChannel(server.url, server.accessToken, accountUUID, lastVideoChannelUUID, 409)
281 }) 266 })
282 }) 267 })
283 268