fixes
This commit is contained in:
48
test/main.ts
48
test/main.ts
@ -1,5 +1,47 @@
|
||||
import test from 'ava';
|
||||
/*
|
||||
* Copyright (C) Sapphirecode - All Rights Reserved
|
||||
* This file is part of Requestor which is released under BSD-3-Clause.
|
||||
* See file 'LICENSE' for full license details.
|
||||
* Created by Timo Hocker <timo@scode.ovh>, March 2020
|
||||
*/
|
||||
|
||||
test ('testing', (t) => {
|
||||
t.is (true, true);
|
||||
/* eslint-disable max-classes-per-file */
|
||||
|
||||
import test from 'ava';
|
||||
import { Application } from 'express';
|
||||
import { http } from '@scode/consts';
|
||||
import { load_handlers, Handler, Transaction } from '../lib/index';
|
||||
|
||||
class MockServer implements Application {
|
||||
public registered: Record<string, Function> = {};
|
||||
}
|
||||
|
||||
class MockHandler extends Handler {
|
||||
public get path (): string {
|
||||
return '/mock';
|
||||
}
|
||||
|
||||
private handle_all (t: Transaction): void {
|
||||
t.status = http.status_im_a_teapot;
|
||||
t.finalize ('foo');
|
||||
}
|
||||
|
||||
public constructor () {
|
||||
super ();
|
||||
this.register_handler (this.handle_all);
|
||||
}
|
||||
}
|
||||
|
||||
test ('detect requests on root', async (t) => {
|
||||
const server = (new MockServer);
|
||||
load_handlers (server, [ (new MockHandler) ]);
|
||||
|
||||
const keys = [ 'all-mock' ];
|
||||
|
||||
t.deepEqual (Object.keys (server.registered), keys);
|
||||
const res = await Promise.all (
|
||||
Object.values (server.registered)
|
||||
.map ((val) => val ())
|
||||
);
|
||||
t.is (res.filter ((val) => val === 'foo').length, keys.length);
|
||||
});
|
||||
|
Reference in New Issue
Block a user