Skip to content

Commit

Permalink
test(core): add case for MidwayWebRouterService.deleteRouter()
Browse files Browse the repository at this point in the history
  • Loading branch information
waitingsong committed Jan 26, 2024
1 parent dacc526 commit 56e9e4b
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion packages/core/test/service/webRouterService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('/test/service/webRouterService.test.ts', function () {
url: '/abc/dddd/*',
requestMethod: 'GET',
});

let routeInfo = await collector.getMatchedRouterInfo('/api', 'get');
expect(routeInfo).toBeUndefined();

Expand Down Expand Up @@ -206,4 +206,39 @@ describe('/test/service/webRouterService.test.ts', function () {
expect(result1[1].url).toEqual('/:slot');
});


it('should test delete router', async () => {
const collector = new MidwayWebRouterService();
const prefix = '/_abc'
collector.addRouter(async (ctx) => {
return 'hello world';
}, {
prefix,
url: prefix + '/dddd/efg',
requestMethod: 'GET',
});

const routerTable = await collector.getRouterTable();
expect(routerTable.has(prefix)).toEqual(true);

await collector.deleteRouter('fake_input')
expect(routerTable.has(prefix)).toEqual(true);

await collector.deleteRouter('')
expect(routerTable.has(prefix)).toEqual(true);

await collector.deleteRouter(prefix)
expect(routerTable.has(prefix)).toEqual(false);

const flattenTable = await collector.getFlattenRouterTable();
let exists = false;
flattenTable.forEach(item => {
if (item.prefix === prefix) {
exists = true;
}
});
expect(exists).toEqual(false);

});

});

0 comments on commit 56e9e4b

Please sign in to comment.