aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-04-24 17:05:32 +0200
committerChocobozzz <me@florianbigard.com>2018-04-24 17:12:57 +0200
commit48dce1c90dff4e90a4bcffefaecf157336cf904b (patch)
tree478de23812d0bfd93f47e9ad6ad8888c9edcc235 /server/tests
parent82e392f8a42a19815e932dd386e96e61ebe6d191 (diff)
downloadPeerTube-48dce1c90dff4e90a4bcffefaecf157336cf904b.tar.gz
PeerTube-48dce1c90dff4e90a4bcffefaecf157336cf904b.tar.zst
PeerTube-48dce1c90dff4e90a4bcffefaecf157336cf904b.zip
Update video channel routes
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/api/check-params/video-channels.ts101
-rw-r--r--server/tests/api/videos/multiple-servers.ts21
-rw-r--r--server/tests/api/videos/video-channels.ts15
-rw-r--r--server/tests/utils/videos/video-channels.ts35
4 files changed, 121 insertions, 51 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
diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts
index 2563939ec..6238cdc08 100644
--- a/server/tests/api/videos/multiple-servers.ts
+++ b/server/tests/api/videos/multiple-servers.ts
@@ -39,6 +39,7 @@ import {
39 getVideoCommentThreads, 39 getVideoCommentThreads,
40 getVideoThreadComments 40 getVideoThreadComments
41} from '../../utils/videos/video-comments' 41} from '../../utils/videos/video-comments'
42import { getAccountsList } from '../../utils/users/accounts'
42 43
43const expect = chai.expect 44const expect = chai.expect
44 45
@@ -46,6 +47,7 @@ describe('Test multiple servers', function () {
46 let servers: ServerInfo[] = [] 47 let servers: ServerInfo[] = []
47 const toRemove = [] 48 const toRemove = []
48 let videoUUID = '' 49 let videoUUID = ''
50 let accountId: number
49 let videoChannelId: number 51 let videoChannelId: number
50 52
51 before(async function () { 53 before(async function () {
@@ -56,13 +58,20 @@ describe('Test multiple servers', function () {
56 // Get the access tokens 58 // Get the access tokens
57 await setAccessTokensToServers(servers) 59 await setAccessTokensToServers(servers)
58 60
59 const videoChannel = { 61 {
60 name: 'my channel', 62 const res = await getAccountsList(servers[0].url)
61 description: 'super channel' 63 accountId = res.body.data[0].id
64 }
65
66 {
67 const videoChannel = {
68 name: 'my channel',
69 description: 'super channel'
70 }
71 await addVideoChannel(servers[ 0 ].url, servers[ 0 ].accessToken, accountId, videoChannel)
72 const channelRes = await getVideoChannelsList(servers[ 0 ].url, 0, 1)
73 videoChannelId = channelRes.body.data[ 0 ].id
62 } 74 }
63 await addVideoChannel(servers[0].url, servers[0].accessToken, videoChannel)
64 const channelRes = await getVideoChannelsList(servers[0].url, 0, 1)
65 videoChannelId = channelRes.body.data[0].id
66 75
67 // Server 1 and server 2 follow each other 76 // Server 1 and server 2 follow each other
68 await doubleFollow(servers[0], servers[1]) 77 await doubleFollow(servers[0], servers[1])
diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts
index b9c9bbf3c..a7552a83a 100644
--- a/server/tests/api/videos/video-channels.ts
+++ b/server/tests/api/videos/video-channels.ts
@@ -17,12 +17,14 @@ import {
17 setAccessTokensToServers, 17 setAccessTokensToServers,
18 updateVideoChannel 18 updateVideoChannel
19} from '../../utils/index' 19} from '../../utils/index'
20import { getAccountsList } from '../../utils/users/accounts'
20 21
21const expect = chai.expect 22const expect = chai.expect
22 23
23describe('Test video channels', function () { 24describe('Test video channels', function () {
24 let servers: ServerInfo[] 25 let servers: ServerInfo[]
25 let userInfo: User 26 let userInfo: User
27 let accountId: number
26 let videoChannelId: number 28 let videoChannelId: number
27 29
28 before(async function () { 30 before(async function () {
@@ -35,6 +37,11 @@ describe('Test video channels', function () {
35 await setAccessTokensToServers(servers) 37 await setAccessTokensToServers(servers)
36 await doubleFollow(servers[0], servers[1]) 38 await doubleFollow(servers[0], servers[1])
37 39
40 {
41 const res = await getAccountsList(servers[0].url)
42 accountId = res.body.data[0].id
43 }
44
38 await wait(5000) 45 await wait(5000)
39 }) 46 })
40 47
@@ -54,7 +61,7 @@ describe('Test video channels', function () {
54 description: 'super video channel description', 61 description: 'super video channel description',
55 support: 'super video channel support text' 62 support: 'super video channel support text'
56 } 63 }
57 const res = await addVideoChannel(servers[0].url, servers[0].accessToken, videoChannel) 64 const res = await addVideoChannel(servers[0].url, servers[0].accessToken, accountId, videoChannel)
58 videoChannelId = res.body.videoChannel.id 65 videoChannelId = res.body.videoChannel.id
59 66
60 // The channel is 1 is propagated to servers 2 67 // The channel is 1 is propagated to servers 2
@@ -120,7 +127,7 @@ describe('Test video channels', function () {
120 support: 'video channel support text updated' 127 support: 'video channel support text updated'
121 } 128 }
122 129
123 await updateVideoChannel(servers[0].url, servers[0].accessToken, videoChannelId, videoChannelAttributes) 130 await updateVideoChannel(servers[0].url, servers[0].accessToken, accountId, videoChannelId, videoChannelAttributes)
124 131
125 await wait(3000) 132 await wait(3000)
126 }) 133 })
@@ -139,7 +146,7 @@ describe('Test video channels', function () {
139 }) 146 })
140 147
141 it('Should get video channel', async function () { 148 it('Should get video channel', async function () {
142 const res = await getVideoChannel(servers[0].url, videoChannelId) 149 const res = await getVideoChannel(servers[0].url, accountId, videoChannelId)
143 150
144 const videoChannel = res.body 151 const videoChannel = res.body
145 expect(videoChannel.displayName).to.equal('video channel updated') 152 expect(videoChannel.displayName).to.equal('video channel updated')
@@ -148,7 +155,7 @@ describe('Test video channels', function () {
148 }) 155 })
149 156
150 it('Should delete video channel', async function () { 157 it('Should delete video channel', async function () {
151 await deleteVideoChannel(servers[0].url, servers[0].accessToken, videoChannelId) 158 await deleteVideoChannel(servers[0].url, servers[0].accessToken, accountId, videoChannelId)
152 }) 159 })
153 160
154 it('Should have video channel deleted', async function () { 161 it('Should have video channel deleted', async function () {
diff --git a/server/tests/utils/videos/video-channels.ts b/server/tests/utils/videos/video-channels.ts
index 2d095d8ab..cfc541431 100644
--- a/server/tests/utils/videos/video-channels.ts
+++ b/server/tests/utils/videos/video-channels.ts
@@ -7,7 +7,7 @@ type VideoChannelAttributes = {
7} 7}
8 8
9function getVideoChannelsList (url: string, start: number, count: number, sort?: string) { 9function getVideoChannelsList (url: string, start: number, count: number, sort?: string) {
10 const path = '/api/v1/videos/channels' 10 const path = '/api/v1/video-channels'
11 11
12 const req = request(url) 12 const req = request(url)
13 .get(path) 13 .get(path)
@@ -22,7 +22,7 @@ function getVideoChannelsList (url: string, start: number, count: number, sort?:
22} 22}
23 23
24function getAccountVideoChannelsList (url: string, accountId: number | string, specialStatus = 200) { 24function getAccountVideoChannelsList (url: string, accountId: number | string, specialStatus = 200) {
25 const path = '/api/v1/videos/accounts/' + accountId + '/channels' 25 const path = '/api/v1/accounts/' + accountId + '/video-channels'
26 26
27 return request(url) 27 return request(url)
28 .get(path) 28 .get(path)
@@ -31,8 +31,14 @@ function getAccountVideoChannelsList (url: string, accountId: number | string, s
31 .expect('Content-Type', /json/) 31 .expect('Content-Type', /json/)
32} 32}
33 33
34function addVideoChannel (url: string, token: string, videoChannelAttributesArg: VideoChannelAttributes, expectedStatus = 200) { 34function addVideoChannel (
35 const path = '/api/v1/videos/channels' 35 url: string,
36 token: string,
37 accountId: number,
38 videoChannelAttributesArg: VideoChannelAttributes,
39 expectedStatus = 200
40) {
41 const path = '/api/v1/accounts/' + accountId + '/video-channels/'
36 42
37 // Default attributes 43 // Default attributes
38 let attributes = { 44 let attributes = {
@@ -50,9 +56,16 @@ function addVideoChannel (url: string, token: string, videoChannelAttributesArg:
50 .expect(expectedStatus) 56 .expect(expectedStatus)
51} 57}
52 58
53function updateVideoChannel (url: string, token: string, channelId: number, attributes: VideoChannelAttributes, expectedStatus = 204) { 59function updateVideoChannel (
60 url: string,
61 token: string,
62 accountId: number,
63 channelId: number,
64 attributes: VideoChannelAttributes,
65 expectedStatus = 204
66) {
54 const body = {} 67 const body = {}
55 const path = '/api/v1/videos/channels/' + channelId 68 const path = '/api/v1/accounts/' + accountId + '/video-channels/' + channelId
56 69
57 if (attributes.name) body['name'] = attributes.name 70 if (attributes.name) body['name'] = attributes.name
58 if (attributes.description) body['description'] = attributes.description 71 if (attributes.description) body['description'] = attributes.description
@@ -66,18 +79,18 @@ function updateVideoChannel (url: string, token: string, channelId: number, attr
66 .expect(expectedStatus) 79 .expect(expectedStatus)
67} 80}
68 81
69function deleteVideoChannel (url: string, token: string, channelId: number, expectedStatus = 204) { 82function deleteVideoChannel (url: string, token: string, accountId: number, channelId: number, expectedStatus = 204) {
70 const path = '/api/v1/videos/channels/' 83 const path = '/api/v1/accounts/' + accountId + '/video-channels/' + channelId
71 84
72 return request(url) 85 return request(url)
73 .delete(path + channelId) 86 .delete(path)
74 .set('Accept', 'application/json') 87 .set('Accept', 'application/json')
75 .set('Authorization', 'Bearer ' + token) 88 .set('Authorization', 'Bearer ' + token)
76 .expect(expectedStatus) 89 .expect(expectedStatus)
77} 90}
78 91
79function getVideoChannel (url: string, channelId: number) { 92function getVideoChannel (url: string, accountId: number, channelId: number) {
80 const path = '/api/v1/videos/channels/' + channelId 93 const path = '/api/v1/accounts/' + accountId + '/video-channels/' + channelId
81 94
82 return request(url) 95 return request(url)
83 .get(path) 96 .get(path)