diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-10-24 19:41:30 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-10-26 09:11:38 +0200 |
commit | 5f04dd2f743961e0a06c29531cc3ccc9e4928d56 (patch) | |
tree | a73085d0d83affc2377b78a2c7c25bda08d26388 /server/tests/utils | |
parent | 72c7248b6fdcdb2175e726ff51b42e7555f2bd84 (diff) | |
download | PeerTube-5f04dd2f743961e0a06c29531cc3ccc9e4928d56.tar.gz PeerTube-5f04dd2f743961e0a06c29531cc3ccc9e4928d56.tar.zst PeerTube-5f04dd2f743961e0a06c29531cc3ccc9e4928d56.zip |
Add video channel tests
Diffstat (limited to 'server/tests/utils')
-rw-r--r-- | server/tests/utils/index.ts | 1 | ||||
-rw-r--r-- | server/tests/utils/login.ts | 2 | ||||
-rw-r--r-- | server/tests/utils/video-channels.ts | 95 | ||||
-rw-r--r-- | server/tests/utils/videos.ts | 12 |
4 files changed, 108 insertions, 2 deletions
diff --git a/server/tests/utils/index.ts b/server/tests/utils/index.ts index 90ee2d515..4325e4c94 100644 --- a/server/tests/utils/index.ts +++ b/server/tests/utils/index.ts | |||
@@ -11,4 +11,5 @@ export * from './services' | |||
11 | export * from './users' | 11 | export * from './users' |
12 | export * from './video-abuses' | 12 | export * from './video-abuses' |
13 | export * from './video-blacklist' | 13 | export * from './video-blacklist' |
14 | export * from './video-channels' | ||
14 | export * from './videos' | 15 | export * from './videos' |
diff --git a/server/tests/utils/login.ts b/server/tests/utils/login.ts index c9d4aed44..22d37c46f 100644 --- a/server/tests/utils/login.ts +++ b/server/tests/utils/login.ts | |||
@@ -32,7 +32,7 @@ async function loginAndGetAccessToken (server: Server) { | |||
32 | return res.body.access_token as string | 32 | return res.body.access_token as string |
33 | } | 33 | } |
34 | 34 | ||
35 | async function getUserAccessToken (server, user) { | 35 | async function getUserAccessToken (server: Server, user: User) { |
36 | const res = await login(server.url, server.client, user, 200) | 36 | const res = await login(server.url, server.client, user, 200) |
37 | 37 | ||
38 | return res.body.access_token as string | 38 | return res.body.access_token as string |
diff --git a/server/tests/utils/video-channels.ts b/server/tests/utils/video-channels.ts new file mode 100644 index 000000000..5b436b183 --- /dev/null +++ b/server/tests/utils/video-channels.ts | |||
@@ -0,0 +1,95 @@ | |||
1 | import * as request from 'supertest' | ||
2 | |||
3 | type VideoChannelAttributes = { | ||
4 | name?: string | ||
5 | description?: string | ||
6 | } | ||
7 | |||
8 | function getVideoChannelsList (url: string, start: number, count: number, sort?: string) { | ||
9 | const path = '/api/v1/videos/channels' | ||
10 | |||
11 | const req = request(url) | ||
12 | .get(path) | ||
13 | .query({ start: start }) | ||
14 | .query({ count: count }) | ||
15 | |||
16 | if (sort) req.query({ sort }) | ||
17 | |||
18 | return req.set('Accept', 'application/json') | ||
19 | .expect(200) | ||
20 | .expect('Content-Type', /json/) | ||
21 | } | ||
22 | |||
23 | function getAuthorVideoChannelsList (url: string, authorId: number | string) { | ||
24 | const path = '/api/v1/videos/authors/' + authorId + '/channels' | ||
25 | |||
26 | return request(url) | ||
27 | .get(path) | ||
28 | .set('Accept', 'application/json') | ||
29 | .expect(200) | ||
30 | .expect('Content-Type', /json/) | ||
31 | } | ||
32 | |||
33 | function addVideoChannel (url: string, token: string, videoChannelAttributesArg: VideoChannelAttributes, expectedStatus = 204) { | ||
34 | const path = '/api/v1/videos/channels' | ||
35 | |||
36 | // Default attributes | ||
37 | let attributes = { | ||
38 | name: 'my super video channel', | ||
39 | description: 'my super channel description' | ||
40 | } | ||
41 | attributes = Object.assign(attributes, videoChannelAttributesArg) | ||
42 | |||
43 | return request(url) | ||
44 | .post(path) | ||
45 | .send(attributes) | ||
46 | .set('Accept', 'application/json') | ||
47 | .set('Authorization', 'Bearer ' + token) | ||
48 | .expect(expectedStatus) | ||
49 | } | ||
50 | |||
51 | function updateVideoChannel (url: string, token: string, channelId: number, attributes: VideoChannelAttributes, expectedStatus = 204) { | ||
52 | const body = {} | ||
53 | const path = '/api/v1/videos/channels/' + channelId | ||
54 | |||
55 | if (attributes.name) body['name'] = attributes.name | ||
56 | if (attributes.description) body['description'] = attributes.description | ||
57 | |||
58 | return request(url) | ||
59 | .put(path) | ||
60 | .send(body) | ||
61 | .set('Accept', 'application/json') | ||
62 | .set('Authorization', 'Bearer ' + token) | ||
63 | .expect(expectedStatus) | ||
64 | } | ||
65 | |||
66 | function deleteVideoChannel (url: string, token: string, channelId: number, expectedStatus = 204) { | ||
67 | const path = '/api/v1/videos/channels/' | ||
68 | |||
69 | return request(url) | ||
70 | .delete(path + channelId) | ||
71 | .set('Accept', 'application/json') | ||
72 | .set('Authorization', 'Bearer ' + token) | ||
73 | .expect(expectedStatus) | ||
74 | } | ||
75 | |||
76 | function getVideoChannel (url: string, channelId: number) { | ||
77 | const path = '/api/v1/videos/channels/' + channelId | ||
78 | |||
79 | return request(url) | ||
80 | .get(path) | ||
81 | .set('Accept', 'application/json') | ||
82 | .expect(200) | ||
83 | .expect('Content-Type', /json/) | ||
84 | } | ||
85 | |||
86 | // --------------------------------------------------------------------------- | ||
87 | |||
88 | export { | ||
89 | getVideoChannelsList, | ||
90 | getAuthorVideoChannelsList, | ||
91 | addVideoChannel, | ||
92 | updateVideoChannel, | ||
93 | deleteVideoChannel, | ||
94 | getVideoChannel | ||
95 | } | ||
diff --git a/server/tests/utils/videos.ts b/server/tests/utils/videos.ts index 2a9a236ca..08fa48da6 100644 --- a/server/tests/utils/videos.ts +++ b/server/tests/utils/videos.ts | |||
@@ -6,6 +6,7 @@ import * as parseTorrent from 'parse-torrent' | |||
6 | import { makeGetRequest } from './requests' | 6 | import { makeGetRequest } from './requests' |
7 | import { readFilePromise } from './miscs' | 7 | import { readFilePromise } from './miscs' |
8 | import { ServerInfo } from './servers' | 8 | import { ServerInfo } from './servers' |
9 | import { getMyUserInformation } from './users' | ||
9 | 10 | ||
10 | type VideoAttributes = { | 11 | type VideoAttributes = { |
11 | name?: string | 12 | name?: string |
@@ -15,6 +16,7 @@ type VideoAttributes = { | |||
15 | nsfw?: boolean | 16 | nsfw?: boolean |
16 | description?: string | 17 | description?: string |
17 | tags?: string[] | 18 | tags?: string[] |
19 | channelId?: number | ||
18 | fixture?: string | 20 | fixture?: string |
19 | } | 21 | } |
20 | 22 | ||
@@ -162,8 +164,14 @@ async function testVideoImage (url: string, imageName: string, imagePath: string | |||
162 | } | 164 | } |
163 | } | 165 | } |
164 | 166 | ||
165 | function uploadVideo (url: string, accessToken: string, videoAttributesArg: VideoAttributes, specialStatus = 204) { | 167 | async function uploadVideo (url: string, accessToken: string, videoAttributesArg: VideoAttributes, specialStatus = 204) { |
166 | const path = '/api/v1/videos/upload' | 168 | const path = '/api/v1/videos/upload' |
169 | let defaultChannelId = '1' | ||
170 | |||
171 | try { | ||
172 | const res = await getMyUserInformation(url, accessToken) | ||
173 | defaultChannelId = res.body.videoChannels[0].id | ||
174 | } catch (e) { /* empty */ } | ||
167 | 175 | ||
168 | // Default attributes | 176 | // Default attributes |
169 | let attributes = { | 177 | let attributes = { |
@@ -171,6 +179,7 @@ function uploadVideo (url: string, accessToken: string, videoAttributesArg: Vide | |||
171 | category: 5, | 179 | category: 5, |
172 | licence: 4, | 180 | licence: 4, |
173 | language: 3, | 181 | language: 3, |
182 | channelId: defaultChannelId, | ||
174 | nsfw: true, | 183 | nsfw: true, |
175 | description: 'my super description', | 184 | description: 'my super description', |
176 | tags: [ 'tag' ], | 185 | tags: [ 'tag' ], |
@@ -187,6 +196,7 @@ function uploadVideo (url: string, accessToken: string, videoAttributesArg: Vide | |||
187 | .field('licence', attributes.licence.toString()) | 196 | .field('licence', attributes.licence.toString()) |
188 | .field('nsfw', JSON.stringify(attributes.nsfw)) | 197 | .field('nsfw', JSON.stringify(attributes.nsfw)) |
189 | .field('description', attributes.description) | 198 | .field('description', attributes.description) |
199 | .field('channelId', attributes.channelId) | ||
190 | 200 | ||
191 | if (attributes.language !== undefined) { | 201 | if (attributes.language !== undefined) { |
192 | req.field('language', attributes.language.toString()) | 202 | req.field('language', attributes.language.toString()) |