Skip to content

Commit

Permalink
tests(router): jest does not like object rest/spread without transpil…
Browse files Browse the repository at this point in the history
…ation...
  • Loading branch information
reel committed Nov 23, 2017
1 parent bf595f7 commit d14d1ab
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 31 deletions.
45 changes: 20 additions & 25 deletions packages/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,38 +35,31 @@ async function init(reload = false) {
if (verb === 'ressources') {
const scope = controller.scope ? `/${controller.scope}/` : '/';
controller.ressources = route;
routes[`get ${scope}${route}`] = {
...controller,
routes[`get ${scope}${route}`] = Object.assign(controller, {
controller: `${controller.controller}#index`,
};
routes[`get ${scope}${route}/new`] = {
...controller,
});
routes[`get ${scope}${route}/new`] = Object.assign(controller, {
controller: `${controller.controller}#new`,
};
routes[`post ${scope}${route}`] = {
...controller,
});
routes[`post ${scope}${route}`] = Object.assign(controller, {
controller: `${controller.controller}#create`,
};
routes[`get ${scope}${route}/:id`] = {
...controller,
});
routes[`get ${scope}${route}/:id`] = Object.assign(controller, {
controller: `${controller.controller}#show`,
};
routes[`get ${scope}${route}/:id/edit`] = {
...controller,
});
routes[`get ${scope}${route}/:id/edit`] = Object.assign(controller, {
controller: `${controller.controller}#edit`,
};
routes[`patch ${scope}${route}/:id`] = {
...controller,
});
routes[`patch ${scope}${route}/:id`] = Object.assign(controller, {
controller: `${controller.controller}#update`,
};
routes[`put ${scope}${route}/:id`] = {
...controller,
});
routes[`put ${scope}${route}/:id`] = Object.assign(controller, {
controller: `${controller.controller}#update`,
};
routes[`delete ${scope}${route}/:id`] = {
...controller,
});
routes[`delete ${scope}${route}/:id`] = Object.assign(controller, {
controller: `${controller.controller}#destroy`,
};
});

delete routes[key];
} else {
routes[key] = controller;
Expand Down Expand Up @@ -139,7 +132,9 @@ function register(verb, route, opts, fn, roles) {
}
}
const name = `${verb} ${route}`;
henri._routes[name] = { ...opts, active: typeof fn === 'function' };
henri._routes[name] = Object.assign(opts, {
active: typeof fn === 'function',
});
}
/* istanbul ignore next */
function middlewares(router) {
Expand Down
12 changes: 6 additions & 6 deletions packages/router/tests/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ describe('router', () => {
});
test('fs routes', () => {
const routes = henri._routes;
expect(routes['get /fs']).toBe('main#fs (unknown controller)');
expect(routes['get /unfs']).toBe('main#fs (unknown controller)');
expect(routes['get /fs'].active).toBeFalsy();
expect(routes['get /unfs'].active).toBeFalsy();
});
test('config routes', () => {
const routes = henri._routes;
expect(routes['get /abc']).toBe('a#bc (ok)');
expect(routes['get /def']).toBe('main#def (unknown controller)');
expect(routes['get /abc'].active).toBeTruthy();
expect(routes['get /def'].active).toBeFalsy();
});
test('normalize verbs', () => {
const routes = henri._routes;
Expand All @@ -30,8 +30,8 @@ describe('router', () => {
});
test('create data routes', () => {
const routes = henri._routes;
expect(routes['get /abc']).toBe('a#bc (ok)');
expect(routes['get /_data/abc']).toBe('a#bc (ok)');
expect(routes['get /abc'].active).toBeTruthy();
expect(routes['get /_data/abc'].active).toBeTruthy();
});
test('should reload', async () => {
henri.log.warn = jest.fn();
Expand Down

0 comments on commit d14d1ab

Please sign in to comment.