From 9639bd175726b73f8fe664b5ced12a72407b1f0b Mon Sep 17 00:00:00 2001 From: buoyantair Date: Mon, 29 Oct 2018 22:18:31 +0530 Subject: Move utils to /shared Move utils used by /server/tools/* & /server/tests/**/* into /shared folder. Issue: #1336 --- server/tests/utils/users/login.ts | 62 --------------------------------------- 1 file changed, 62 deletions(-) delete mode 100644 server/tests/utils/users/login.ts (limited to 'server/tests/utils/users/login.ts') diff --git a/server/tests/utils/users/login.ts b/server/tests/utils/users/login.ts deleted file mode 100644 index ddeb9df2a..000000000 --- a/server/tests/utils/users/login.ts +++ /dev/null @@ -1,62 +0,0 @@ -import * as request from 'supertest' - -import { ServerInfo } from '../server/servers' - -type Client = { id: string, secret: string } -type User = { username: string, password: string } -type Server = { url: string, client: Client, user: User } - -function login (url: string, client: Client, user: User, expectedStatus = 200) { - const path = '/api/v1/users/token' - - const body = { - client_id: client.id, - client_secret: client.secret, - username: user.username, - password: user.password, - response_type: 'code', - grant_type: 'password', - scope: 'upload' - } - - return request(url) - .post(path) - .type('form') - .send(body) - .expect(expectedStatus) -} - -async function serverLogin (server: Server) { - const res = await login(server.url, server.client, server.user, 200) - - return res.body.access_token as string -} - -async function userLogin (server: Server, user: User, expectedStatus = 200) { - const res = await login(server.url, server.client, user, expectedStatus) - - return res.body.access_token as string -} - -function setAccessTokensToServers (servers: ServerInfo[]) { - const tasks: Promise[] = [] - - for (const server of servers) { - const p = serverLogin(server).then(t => server.accessToken = t) - tasks.push(p) - } - - return Promise.all(tasks) -} - -// --------------------------------------------------------------------------- - -export { - login, - serverLogin, - userLogin, - setAccessTokensToServers, - Server, - Client, - User -} -- cgit v1.2.3