51 lines
1.2 KiB
JavaScript
Raw Normal View History

2020-03-06 18:02:08 +01:00
/*
* Copyright (C) Sapphirecode - All Rights Reserved
* This file is part of auth-server-helper which is released under MIT.
* See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, March 2020
*/
// @ts-nocheck
'use strict';
const test = require ('ava');
2020-03-07 17:56:41 +01:00
const mock_server = require ('../mock_server');
const client = require ('@scode/auth-client-helper');
2020-03-08 14:03:18 +01:00
const consts = require ('@scode/consts');
const fetch = require ('node-fetch');
2020-03-06 18:02:08 +01:00
2020-03-07 17:56:41 +01:00
test.before (async () => {
await mock_server.start_server ();
});
test ('login', async (t) => {
const session = await client.login (
'testuser',
'foo',
'http://localhost:3000'
);
t.is (typeof session, 'string');
2020-03-08 14:03:18 +01:00
const resp = await fetch ('http://localhost:3000', { headers: { session } });
t.is (await resp.status, consts.http.status_ok);
t.is (await resp.text (), 'foo');
2020-03-07 17:56:41 +01:00
});
test ('reject invalid user', async (t) => {
2020-03-07 18:29:18 +01:00
await t.throwsAsync (client.login (
2020-03-07 17:56:41 +01:00
'foo',
'foo',
'http://localhost:3000'
2020-03-07 18:29:18 +01:00
));
2020-03-07 17:56:41 +01:00
});
test ('reject invalid password', async (t) => {
2020-03-07 18:29:18 +01:00
await t.throwsAsync (client.login (
2020-03-07 17:56:41 +01:00
'testuser',
'bar',
'http://localhost:3000'
2020-03-07 18:29:18 +01:00
));
2020-03-06 18:02:08 +01:00
});