diff options
author | Chocobozzz <me@florianbigard.com> | 2017-12-28 13:59:22 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2017-12-28 13:59:22 +0100 |
commit | c5d31dba56d669c0df0209761c43c5a6ac7cec4a (patch) | |
tree | fe72b56a1c0e7beb6e092c393a00ddfe93a5d71f /server/tests/utils/videos/video-channels.ts | |
parent | db799da3d2b2ea465165df78ff71effa653b6309 (diff) | |
download | PeerTube-c5d31dba56d669c0df0209761c43c5a6ac7cec4a.tar.gz PeerTube-c5d31dba56d669c0df0209761c43c5a6ac7cec4a.tar.zst PeerTube-c5d31dba56d669c0df0209761c43c5a6ac7cec4a.zip |
Tests directories refractor
Diffstat (limited to 'server/tests/utils/videos/video-channels.ts')
-rw-r--r-- | server/tests/utils/videos/video-channels.ts | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/server/tests/utils/videos/video-channels.ts b/server/tests/utils/videos/video-channels.ts new file mode 100644 index 000000000..0fb80d331 --- /dev/null +++ b/server/tests/utils/videos/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 getAccountVideoChannelsList (url: string, accountId: number | string) { | ||
24 | const path = '/api/v1/videos/accounts/' + accountId + '/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 | getAccountVideoChannelsList, | ||
91 | addVideoChannel, | ||
92 | updateVideoChannel, | ||
93 | deleteVideoChannel, | ||
94 | getVideoChannel | ||
95 | } | ||