Added auth and request storage
This commit is contained in:
@@ -33,13 +33,15 @@ describe('ApplicationRouter dispatch', (): void => {
|
||||
url: '/echo',
|
||||
handler: async (stream): Promise<void> => {
|
||||
expect(stream.connection).toBe(connection);
|
||||
expect(stream.path).toBe('/echo');
|
||||
expect(stream.headers).toEqual({ 'x-request-token': 'route-1' });
|
||||
await stream.send(stream.body);
|
||||
},
|
||||
},
|
||||
]),
|
||||
]);
|
||||
|
||||
await router.dispatch({ path: '/echo', body: { value: 1 }, requestId: 'request-1' }, connection);
|
||||
await router.dispatch({ path: '/echo', body: { value: 1 }, requestId: 'request-1', headers: { 'x-request-token': 'route-1' } }, connection);
|
||||
|
||||
expect(connection.messages).toEqual([
|
||||
{
|
||||
@@ -61,16 +63,23 @@ describe('ApplicationRouter dispatch', (): void => {
|
||||
url: '/delayed',
|
||||
handler: async (stream): Promise<void> => {
|
||||
const key = (stream.body as { key: string }).key;
|
||||
const token = stream.headers['x-request-token'];
|
||||
await new Promise<void>((resolve) => completions.set(key, resolve));
|
||||
await stream.send({ key });
|
||||
await stream.send({ key, token });
|
||||
},
|
||||
},
|
||||
]),
|
||||
]);
|
||||
const connection = new TestConnection(true, true);
|
||||
|
||||
const first = router.dispatch({ path: '/delayed', body: { key: 'A' }, requestId: 'A' }, connection);
|
||||
const second = router.dispatch({ path: '/delayed', body: { key: 'B' }, requestId: 'B' }, connection);
|
||||
const first = router.dispatch(
|
||||
{ path: '/delayed', body: { key: 'A' }, requestId: 'A', headers: { 'x-request-token': 'token-a' } },
|
||||
connection,
|
||||
);
|
||||
const second = router.dispatch(
|
||||
{ path: '/delayed', body: { key: 'B' }, requestId: 'B', headers: { 'x-request-token': 'token-b' } },
|
||||
connection,
|
||||
);
|
||||
|
||||
completions.get('B')?.();
|
||||
await second;
|
||||
@@ -82,13 +91,13 @@ describe('ApplicationRouter dispatch', (): void => {
|
||||
id: 'B',
|
||||
type: 'response',
|
||||
statusCode: 200,
|
||||
body: { key: 'B' },
|
||||
body: { key: 'B', token: 'token-b' },
|
||||
},
|
||||
{
|
||||
id: 'A',
|
||||
type: 'response',
|
||||
statusCode: 200,
|
||||
body: { key: 'A' },
|
||||
body: { key: 'A', token: 'token-a' },
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user