it('should add mix route names as sub-routes', () => { let parentRoute = new Route(); parentRoute.get('/a', () => {}); parentRoute.get('/b', () => {}); let subRoute = new Route(); subRoute.get('/aa', () => {}); subRoute.get('/ab', () => {}); parentRoute.add('/a', subRoute); parentRoute.add('b/', subRoute); parentRoute.add(' c', subRoute); assert.hasAllKeys(parentRoute.nextRoute, ['a', 'b', 'c'], 'Sub route not added'); assert.hasAnyKeys( parentRoute.nextRoute['a'].nextRoute, ['aa', 'ab'], 'Sub-sub route `a` not added' ); assert.hasAnyKeys( parentRoute.nextRoute['b'].nextRoute, ['aa', 'ab'], 'Sub-sub route `b` not added' ); assert.hasAnyKeys( parentRoute.nextRoute['c'].nextRoute, ['aa', 'ab'], 'Sub-sub route `c` not added' ); });
it('should add a sub-route', () => { let parentRoute = new Route(); parentRoute.get('/one-get', () => {}); parentRoute.get('/two-get', () => {}); parentRoute.put('/one-put', () => {}); parentRoute.post('/one-post', () => {}); parentRoute.delete('/one-delete', () => {}); let subRoute = new Route(); subRoute.get('/sub-one-get', () => {}); subRoute.get('/sub-one-get/hello', () => {}); subRoute.get('/sub-two-get', () => {}); subRoute.put('/sub-one-put', () => {}); subRoute.post('/sub-one-post', () => {}); subRoute.delete('/sub-one-delete', () => {}); let otherSub = new Route(); otherSub.get('/test', () => {}); otherSub.get('/my-test-sub', () => {}); otherSub.get('/my-other-sub', () => {}); parentRoute.add('sub', subRoute); parentRoute.add('sub-one-get', otherSub); assert.hasAnyKeys(parentRoute.nextRoute, ['sub'], 'Sub route not added'); assert.hasAnyKeys( parentRoute.nextRoute['sub'].nextRoute, ['sub-one-get', 'sub-two-get', 'sub-one-put', 'sub-one-post', 'sub-one-delete'], 'Subs sub route not added' ); assert.hasAnyKeys(parentRoute.nextRoute, ['sub-one-get'], 'OtherSub route not added'); assert.hasAnyKeys( parentRoute.nextRoute['sub-one-get'].nextRoute, ['test', 'my-test-sub', 'my-other-sub', 'hello'], 'OtherSubs sub route not added' ); });