]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/utils/pods.ts
Fix video removing when it is corrupted
[github/Chocobozzz/PeerTube.git] / server / tests / utils / pods.ts
CommitLineData
0e1dc3e7
C
1import * as request from 'supertest'
2
3import { wait } from './miscs'
4
5function getFriendsList (url: string) {
6 const path = '/api/v1/pods/'
7
8 return request(url)
9 .get(path)
10 .set('Accept', 'application/json')
11 .expect(200)
12 .expect('Content-Type', /json/)
13}
14
15async function makeFriends (url: string, accessToken: string, expectedStatus = 204) {
16 // Which pod makes friends with which pod
17 const friendsMatrix = {
18 'http://localhost:9001': [
19 'localhost:9002'
20 ],
21 'http://localhost:9002': [
22 'localhost:9003'
23 ],
24 'http://localhost:9003': [
25 'localhost:9001'
26 ],
27 'http://localhost:9004': [
28 'localhost:9002'
29 ],
30 'http://localhost:9005': [
31 'localhost:9001',
32 'localhost:9004'
33 ],
34 'http://localhost:9006': [
35 'localhost:9001',
36 'localhost:9002',
37 'localhost:9003'
38 ]
39 }
aa2e7f15 40 const path = '/api/v1/pods/make-friends'
0e1dc3e7
C
41
42 // The first pod make friend with the third
43 const res = await request(url)
44 .post(path)
45 .set('Accept', 'application/json')
46 .set('Authorization', 'Bearer ' + accessToken)
47 .send({ 'hosts': friendsMatrix[url] })
48 .expect(expectedStatus)
49
50 // Wait request propagation
51 await wait(1000)
52
53 return res
54}
55
56async function quitFriends (url: string, accessToken: string, expectedStatus = 204) {
aa2e7f15 57 const path = '/api/v1/pods/quit-friends'
0e1dc3e7
C
58
59 // The first pod make friend with the third
60 const res = await request(url)
61 .get(path)
62 .set('Accept', 'application/json')
63 .set('Authorization', 'Bearer ' + accessToken)
64 .expect(expectedStatus)
65
66 // Wait request propagation
67 await wait(1000)
68
69 return res
70}
71
72function quitOneFriend (url: string, accessToken: string, friendId: number, expectedStatus = 204) {
73 const path = '/api/v1/pods/' + friendId
74
75 return request(url)
76 .delete(path)
77 .set('Accept', 'application/json')
78 .set('Authorization', 'Bearer ' + accessToken)
79 .expect(expectedStatus)
80}
81
82// ---------------------------------------------------------------------------
83
84export {
85 getFriendsList,
86 makeFriends,
87 quitFriends,
88 quitOneFriend
89}