From 0e1dc3e7c69995c691e1dd82e3c2bc68748661ca Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 4 Sep 2017 21:21:47 +0200 Subject: Convert tests to typescript --- server/tests/utils/pods.ts | 89 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 server/tests/utils/pods.ts (limited to 'server/tests/utils/pods.ts') 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 @@ +import * as request from 'supertest' + +import { wait } from './miscs' + +function getFriendsList (url: string) { + const path = '/api/v1/pods/' + + return request(url) + .get(path) + .set('Accept', 'application/json') + .expect(200) + .expect('Content-Type', /json/) +} + +async function makeFriends (url: string, accessToken: string, expectedStatus = 204) { + // Which pod makes friends with which pod + const friendsMatrix = { + 'http://localhost:9001': [ + 'localhost:9002' + ], + 'http://localhost:9002': [ + 'localhost:9003' + ], + 'http://localhost:9003': [ + 'localhost:9001' + ], + 'http://localhost:9004': [ + 'localhost:9002' + ], + 'http://localhost:9005': [ + 'localhost:9001', + 'localhost:9004' + ], + 'http://localhost:9006': [ + 'localhost:9001', + 'localhost:9002', + 'localhost:9003' + ] + } + const path = '/api/v1/pods/makefriends' + + // The first pod make friend with the third + const res = await request(url) + .post(path) + .set('Accept', 'application/json') + .set('Authorization', 'Bearer ' + accessToken) + .send({ 'hosts': friendsMatrix[url] }) + .expect(expectedStatus) + + // Wait request propagation + await wait(1000) + + return res +} + +async function quitFriends (url: string, accessToken: string, expectedStatus = 204) { + const path = '/api/v1/pods/quitfriends' + + // The first pod make friend with the third + const res = await request(url) + .get(path) + .set('Accept', 'application/json') + .set('Authorization', 'Bearer ' + accessToken) + .expect(expectedStatus) + + // Wait request propagation + await wait(1000) + + return res +} + +function quitOneFriend (url: string, accessToken: string, friendId: number, expectedStatus = 204) { + const path = '/api/v1/pods/' + friendId + + return request(url) + .delete(path) + .set('Accept', 'application/json') + .set('Authorization', 'Bearer ' + accessToken) + .expect(expectedStatus) +} + +// --------------------------------------------------------------------------- + +export { + getFriendsList, + makeFriends, + quitFriends, + quitOneFriend +} -- cgit v1.2.3