use jasmine
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2020-09-28 11:10:15 +02:00
parent 3d93b0cd9a
commit b54068954c
5 changed files with 708 additions and 1235 deletions

View File

@ -1,57 +0,0 @@
/*
* 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 <timo@scode.ovh>, May 2020
*/
// @ts-nocheck
'use strict';
const test = require ('ava');
const http = require ('http');
const client = require ('../index');
const consts = require ('@sapphirecode/consts');
test.before (() => {
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);
});
test ('send request', async (t) => {
const session = await client.login ('foo', 'bar', 'http://localhost:3000');
t.is (
session,
// eslint-disable-next-line max-len
'foo39082c11afda7a927fe4e23c5ba81b64186c33f7e58adf492be5a5c64ddc9db459e0778d573000a5ebaeeae902b6c8641198406b58bf9c53ce48ecdef73a33d1'
);
});
test ('fail salt', async (t) => {
await t.throwsAsync (
client.login ('fail', 'bar', 'http://localhost:3000')
);
});
test ('fail password', async (t) => {
await t.throwsAsync (
client.login ('foo', 'fail', 'http://localhost:3000')
);
});

62
test/spec/index.js Normal file
View File

@ -0,0 +1,62 @@
/*
* 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 <timo@scode.ovh>, 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');
});
});