aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-04-25 10:21:38 +0200
committerChocobozzz <me@florianbigard.com>2018-04-25 13:50:48 +0200
commit6b738c7a31591a83fdcd9c78b6b1f98e543c378b (patch)
treedb771d0e99e9ff27570885fe2a6f58a7c1948fbc /server/tests/api/check-params
parent48dce1c90dff4e90a4bcffefaecf157336cf904b (diff)
downloadPeerTube-6b738c7a31591a83fdcd9c78b6b1f98e543c378b.tar.gz
PeerTube-6b738c7a31591a83fdcd9c78b6b1f98e543c378b.tar.zst
PeerTube-6b738c7a31591a83fdcd9c78b6b1f98e543c378b.zip
Video channel API routes refractor
Diffstat (limited to 'server/tests/api/check-params')
-rw-r--r--server/tests/api/check-params/video-channels.ts73
-rw-r--r--server/tests/api/check-params/videos.ts73
2 files changed, 99 insertions, 47 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
diff --git a/server/tests/api/check-params/videos.ts b/server/tests/api/check-params/videos.ts
index da41f515b..850ad12e0 100644
--- a/server/tests/api/check-params/videos.ts
+++ b/server/tests/api/check-params/videos.ts
@@ -10,6 +10,7 @@ import {
10 makeGetRequest, makeUploadRequest, makePutBodyRequest, removeVideo, runServer, ServerInfo, setAccessTokensToServers, userLogin 10 makeGetRequest, makeUploadRequest, makePutBodyRequest, removeVideo, runServer, ServerInfo, setAccessTokensToServers, userLogin
11} from '../../utils' 11} from '../../utils'
12import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' 12import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
13import { getAccountsList } from '../../utils/users/accounts'
13 14
14const expect = chai.expect 15const expect = chai.expect
15 16
@@ -17,7 +18,9 @@ describe('Test videos API validator', function () {
17 const path = '/api/v1/videos/' 18 const path = '/api/v1/videos/'
18 let server: ServerInfo 19 let server: ServerInfo
19 let userAccessToken = '' 20 let userAccessToken = ''
21 let accountUUID: string
20 let channelId: number 22 let channelId: number
23 let channelUUID: string
21 let videoId 24 let videoId
22 25
23 // --------------------------------------------------------------- 26 // ---------------------------------------------------------------
@@ -36,8 +39,12 @@ describe('Test videos API validator', function () {
36 await createUser(server.url, server.accessToken, username, password) 39 await createUser(server.url, server.accessToken, username, password)
37 userAccessToken = await userLogin(server, { username, password }) 40 userAccessToken = await userLogin(server, { username, password })
38 41
39 const res = await getMyUserInformation(server.url, server.accessToken) 42 {
40 channelId = res.body.videoChannels[0].id 43 const res = await getMyUserInformation(server.url, server.accessToken)
44 channelId = res.body.videoChannels[ 0 ].id
45 channelUUID = res.body.videoChannels[ 0 ].uuid
46 accountUUID = res.body.account.uuid
47 }
41 }) 48 })
42 49
43 describe('When listing a video', function () { 50 describe('When listing a video', function () {
@@ -52,6 +59,10 @@ describe('Test videos API validator', function () {
52 it('Should fail with an incorrect sort', async function () { 59 it('Should fail with an incorrect sort', async function () {
53 await checkBadSortPagination(server.url, path) 60 await checkBadSortPagination(server.url, path)
54 }) 61 })
62
63 it('Should success with the correct parameters', async function () {
64 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 })
65 })
55 }) 66 })
56 67
57 describe('When searching a video', function () { 68 describe('When searching a video', function () {
@@ -75,6 +86,10 @@ describe('Test videos API validator', function () {
75 it('Should fail with an incorrect sort', async function () { 86 it('Should fail with an incorrect sort', async function () {
76 await checkBadSortPagination(server.url, join(path, 'search', 'test')) 87 await checkBadSortPagination(server.url, join(path, 'search', 'test'))
77 }) 88 })
89
90 it('Should success with the correct parameters', async function () {
91 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 })
92 })
78 }) 93 })
79 94
80 describe('When listing my videos', function () { 95 describe('When listing my videos', function () {
@@ -91,6 +106,58 @@ describe('Test videos API validator', function () {
91 it('Should fail with an incorrect sort', async function () { 106 it('Should fail with an incorrect sort', async function () {
92 await checkBadSortPagination(server.url, path, server.accessToken) 107 await checkBadSortPagination(server.url, path, server.accessToken)
93 }) 108 })
109
110 it('Should success with the correct parameters', async function () {
111 await makeGetRequest({ url: server.url, token: server.accessToken, path, statusCodeExpected: 200 })
112 })
113 })
114
115 describe('When listing account videos', function () {
116 let path: string
117
118 before(async function () {
119 path = '/api/v1/accounts/' + accountUUID + '/videos'
120 })
121
122 it('Should fail with a bad start pagination', async function () {
123 await checkBadStartPagination(server.url, path, server.accessToken)
124 })
125
126 it('Should fail with a bad count pagination', async function () {
127 await checkBadCountPagination(server.url, path, server.accessToken)
128 })
129
130 it('Should fail with an incorrect sort', async function () {
131 await checkBadSortPagination(server.url, path, server.accessToken)
132 })
133
134 it('Should success with the correct parameters', async function () {
135 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 })
136 })
137 })
138
139 describe('When listing video channel videos', function () {
140 let path: string
141
142 before(async function () {
143 path = '/api/v1/accounts/' + accountUUID + '/video-channels/' + channelUUID + '/videos'
144 })
145
146 it('Should fail with a bad start pagination', async function () {
147 await checkBadStartPagination(server.url, path, server.accessToken)
148 })
149
150 it('Should fail with a bad count pagination', async function () {
151 await checkBadCountPagination(server.url, path, server.accessToken)
152 })
153
154 it('Should fail with an incorrect sort', async function () {
155 await checkBadSortPagination(server.url, path, server.accessToken)
156 })
157
158 it('Should success with the correct parameters', async function () {
159 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 })
160 })
94 }) 161 })
95 162
96 describe('When adding a video', function () { 163 describe('When adding a video', function () {
@@ -112,7 +179,7 @@ describe('Test videos API validator', function () {
112 support: 'my super support text', 179 support: 'my super support text',
113 tags: [ 'tag1', 'tag2' ], 180 tags: [ 'tag1', 'tag2' ],
114 privacy: VideoPrivacy.PUBLIC, 181 privacy: VideoPrivacy.PUBLIC,
115 channelId 182 channelId: channelId
116 } 183 }
117 }) 184 })
118 185