Skip to content

Commit

Permalink
feat(router): add two more corner case tests for clarification
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Miaskowski committed Oct 18, 2018
1 parent 07a31a1 commit 23dc242
Showing 1 changed file with 45 additions and 2 deletions.
47 changes: 45 additions & 2 deletions packages/http/src/router/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,10 @@ describe('http router', () => {
const url = 'concrete.com';
const resourceWithConcreteMatch = createResource(method, path, [
{ url },
{ url: '{template}', variables: { template: { default: url, enum: [ url ] } } },
{ url: '{template}', variables: { template: { default: url, enum: [url] } } },
]);
const resourceWithTemplatedMatch = createResource(method, path, [
{ url: '{template}', variables: { template: { default: url, enum: [ url ] } } },
{ url: '{template}', variables: { template: { default: url, enum: [url] } } },
]);
const resource = await router.route({
resources: [
Expand Down Expand Up @@ -270,6 +270,49 @@ describe('http router', () => {

expect(resource).toBe(resourceWithMatchingPath);
});

test('given empty baseUrl and concrete server it should not match', async () => {
const path = randomPath({ includeTemplates: false });
const url = 'concrete.com';
const resource = await router.route({
resources: [
createResource(method, path, [
{ url },
])
],
input: {
method,
url: {
baseUrl: '',
path,
}
}
});

expect(resource).toBeNull();
});

test('given empty baseUrl and empty server url it should match', async () => {
const path = randomPath({ includeTemplates: false });
const url = '';
const expectedResource = createResource(method, path, [
{ url },
]);
const resource = await router.route({
resources: [
expectedResource
],
input: {
method,
url: {
baseUrl: '',
path,
}
}
});

expect(resource).toBe(expectedResource);
});
});
});
});
Expand Down

0 comments on commit 23dc242

Please sign in to comment.