Skip to content

Commit

Permalink
path templates matched incorrectly #214
Browse files Browse the repository at this point in the history
  • Loading branch information
Carmine DiMascio committed Jan 13, 2020
1 parent 12c49bf commit c811dfa
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions test/paths.sort.spec.ts
@@ -0,0 +1,44 @@
import {
sortRoutes,
} from '../src/framework/openapi.spec.loader';
import { expect } from 'chai';

describe('url sorter', () => {
it('should sort dynamic leafs after static leafs', async () => {
const urls = asRouteMetadatas(['/my/:id', '/my/path']);
const expected = ['/my/path', '/my/:id'];

urls.sort(sortRoutes);

expect(urls[0].expressRoute).to.equal(expected[0]);
expect(urls[1].expressRoute).to.equal(expected[1]);
});

it('should sort dynamic inner paths after static inner paths', async () => {
const urls = asRouteMetadatas([
'/my/:id/test',
'/my/path/test',
'/a/:b/c/:d',
'/a/:b/c/d',
]);
const expected = [
'/a/:b/c/d',
'/a/:b/c/:d',
'/my/path/test',
'/my/:id/test',
];

urls.sort(sortRoutes);

expect(urls[0].expressRoute).to.equal(expected[0]);
expect(urls[1].expressRoute).to.equal(expected[1]);
expect(urls[2].expressRoute).to.equal(expected[2]);
expect(urls[3].expressRoute).to.equal(expected[3]);
});
});

function asRouteMetadatas(urls: string[]) {
return urls.map(u => ({
expressRoute: u,
}));
}

0 comments on commit c811dfa

Please sign in to comment.