aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/utils/pods.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-09-04 21:21:47 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-09-04 21:30:18 +0200
commit0e1dc3e7c69995c691e1dd82e3c2bc68748661ca (patch)
treef2a4b5cffc72e33c902b67083bbaa35b6f22f0ca /server/tests/utils/pods.ts
parentb0f9f39ed70299a208d1b388c72de8b7f3510cb7 (diff)
downloadPeerTube-0e1dc3e7c69995c691e1dd82e3c2bc68748661ca.tar.gz
PeerTube-0e1dc3e7c69995c691e1dd82e3c2bc68748661ca.tar.zst
PeerTube-0e1dc3e7c69995c691e1dd82e3c2bc68748661ca.zip
Convert tests to typescript
Diffstat (limited to 'server/tests/utils/pods.ts')
-rw-r--r--server/tests/utils/pods.ts89
1 files changed, 89 insertions, 0 deletions
diff --git a/server/tests/utils/pods.ts b/server/tests/utils/pods.ts
new file mode 100644
index 000000000..0bea6db97
--- /dev/null
+++ b/server/tests/utils/pods.ts
@@ -0,0 +1,89 @@
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 }
40 const path = '/api/v1/pods/makefriends'
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) {
57 const path = '/api/v1/pods/quitfriends'
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}