/* * Copyright (C) Sapphirecode - All Rights Reserved * This file is part of auth-client-helper which is released under MIT. * See file 'LICENSE' for full license details. * Created by Timo Hocker , May 2020 */ /* eslint-disable no-undef */ // @ts-nocheck 'use strict'; const http = require ('http'); const client = require ('../../index'); const consts = require ('@sapphirecode/consts'); describe ('client helper', () => { beforeAll (() => { http.createServer ((req, res) => { let str = ''; if (req.headers.user) str += req.headers.user; if (req.headers.key) str += req.headers.key; res.writeHead ( req.headers.user === 'fail' // eslint-disable-next-line max-len || req.headers.key === '73192367f6dde83a7e3c0bb412dff8e1b7dfbdb5e5010f00057f317b8eab68e8e448528303142c1455dfe72e062bb2e48f07441b38c7b65329ba7e5acbea6126' ? consts.http.status_forbidden : consts.http.status_ok ); res.end (str); }) // eslint-disable-next-line no-magic-numbers .listen (3000); }); it ('should send request', async () => { const session = await client.login ('foo', 'bar', 'http://localhost:3000'); expect ( session ) .toEqual ( // eslint-disable-next-line max-len 'foo39082c11afda7a927fe4e23c5ba81b64186c33f7e58adf492be5a5c64ddc9db459e0778d573000a5ebaeeae902b6c8641198406b58bf9c53ce48ecdef73a33d1' ); }); it ('should fail salt', async () => { await expectAsync ( client.login ('fail', 'bar', 'http://localhost:3000') ) .toBeRejectedWithError ('user or password invalid'); }); it ('should fail password', async () => { await expectAsync ( client.login ('foo', 'fail', 'http://localhost:3000') ) .toBeRejectedWithError ('user or password invalid'); }); });