add basic tests
This commit is contained in:
49
test/index.js
Normal file
49
test/index.js
Normal file
@ -0,0 +1,49 @@
|
||||
// @ts-nocheck
|
||||
'use strict';
|
||||
|
||||
const test = require ('ava');
|
||||
const http = require ('http');
|
||||
const client = require ('../index');
|
||||
const consts = require ('@scode/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);
|
||||
})
|
||||
.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', (t) => {
|
||||
t.throwsAsync (async () => {
|
||||
await client.login ('fail', 'bar', 'http://localhost:3000');
|
||||
});
|
||||
});
|
||||
|
||||
test ('fail password', (t) => {
|
||||
t.throwsAsync (async () => {
|
||||
await client.login ('foo', 'fail', 'http://localhost:3000');
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user