Added some tests

This commit is contained in:
2021-06-23 22:30:45 +02:00
parent 24f897e907
commit 3d3d7fae48
3796 changed files with 218744 additions and 3 deletions

View File

@@ -0,0 +1,14 @@
import {} from 'dotenv/config';
import got from 'got';
import test from 'tape';
import setConfig from '../test-helpers/config.js';
test('test-cases/00start.js: Wait for auth API to be ready', async t => {
setConfig({ printConfig: true });
const backendHealthCheck = await got(process.env.AUTH_URL, { retry: 2000 });
t.equal(backendHealthCheck.statusCode, 200, 'Auth API should answer with status code 200');
t.end();
});

View File

@@ -0,0 +1,48 @@
import got from 'got';
import jwt from 'jsonwebtoken'
import setConfig from '../test-helpers/config.js';
import test from 'tape';
test('test-cases/01basic.js: Basic stuff', async t => {
t.comment('Authing with configurated API KEY');
// Wrong API key
try {
await got.post(`${process.env.AUTH_URL}/auth/api-key`, {
json: 'a09ifa908wjf92fowreigaoijfaosidfđ@€£đawef',
responseType: 'json',
});
t.fail('Calling /auth/api-key with wrong api-key should result in a 403');
} catch (err) {
t.equal(err.message, 'Response code 403 (Forbidden)', 'Calling /auth/api-key with wrong api-key should result in a 403')
}
const authRes = await got.post(`${process.env.AUTH_URL}/auth/api-key`, {
json: 'hihi',
responseType: 'json',
});
t.notEqual(authRes.body.jwt, undefined, 'The body should include a jwt key');
t.notEqual(authRes.body.renewalToken, undefined, 'The body should include a renewalToken');
const adminJWT = jwt.verify(authRes.body.jwt, process.env.JWT_SHARED_SECRET);
t.equal(adminJWT.accountName, 'admin', 'The verified account name should be "admin"');
t.comment('GETting the admin account, with the token we just obtained');
try {
await got(`${process.env.AUTH_URL}/account/${adminJWT.accountId}`);
t.fail('Calling /account/{id} without proper auth token should give 403');
} catch (err) {
t.equal(err.message, 'Response code 403 (Forbidden)', 'Calling /account/{id} without proper auth token should give 403');
}
const accountRes = await got(`${process.env.AUTH_URL}/account/${adminJWT.accountId}`, {
headers: { 'Authorization': `bearer ${authRes.body.jwt}`},
responseType: 'json',
});
t.equal(adminJWT.accountId, accountRes.body.id, 'The account ids should match');
t.end();
});