1 import * as request from 'supertest'
3 import { wait } from './miscs'
5 function getFriendsList (url: string) {
6 const path = '/api/v1/pods/'
10 .set('Accept', 'application/json')
12 .expect('Content-Type', /json/)
15 async function makeFriends (url: string, accessToken: string, expectedStatus = 204) {
16 // Which pod makes friends with which pod
17 const friendsMatrix = {
18 'http://localhost:9001': [
21 'http://localhost:9002': [
24 'http://localhost:9003': [
27 'http://localhost:9004': [
30 'http://localhost:9005': [
34 'http://localhost:9006': [
40 const path = '/api/v1/pods/makefriends'
42 // The first pod make friend with the third
43 const res = await request(url)
45 .set('Accept', 'application/json')
46 .set('Authorization', 'Bearer ' + accessToken)
47 .send({ 'hosts': friendsMatrix[url] })
48 .expect(expectedStatus)
50 // Wait request propagation
56 async function quitFriends (url: string, accessToken: string, expectedStatus = 204) {
57 const path = '/api/v1/pods/quitfriends'
59 // The first pod make friend with the third
60 const res = await request(url)
62 .set('Accept', 'application/json')
63 .set('Authorization', 'Bearer ' + accessToken)
64 .expect(expectedStatus)
66 // Wait request propagation
72 function quitOneFriend (url: string, accessToken: string, friendId: number, expectedStatus = 204) {
73 const path = '/api/v1/pods/' + friendId
77 .set('Accept', 'application/json')
78 .set('Authorization', 'Bearer ' + accessToken)
79 .expect(expectedStatus)
82 // ---------------------------------------------------------------------------