Skip to content

Commit

Permalink
fix: query parameters are not added to custom routes (#528)
Browse files Browse the repository at this point in the history
* Add whitelisted query parameters to custom routes

* Add test for query parameters on custom model-less routes

* Remove unused parameters
  • Loading branch information
nickschot authored and zacharygolba committed Nov 15, 2016
1 parent 4530d0c commit dbdcc5a
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/packages/router/route/params/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import getDefaultCollectionParams from './utils/get-default-collection-params';
import type { Params$opts } from './interfaces';
import {
getMemberQueryParams,
getCollectionQueryParams
getCollectionQueryParams,
getCustomParams
} from './utils/get-query-params';

/**
Expand Down Expand Up @@ -47,6 +48,11 @@ export function paramsFor({
getDataParams(controller, false)
];
}
} else if (type === 'custom') {
params = [
...params,
...getCustomParams(controller)
];
}

return new ParameterGroup(params, {
Expand Down
31 changes: 30 additions & 1 deletion src/packages/router/route/params/test/params.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,43 @@
import { expect } from 'chai';
import { it, describe, before } from 'mocha';

import { defaultParamsFor } from '../index';
import { paramsFor, defaultParamsFor } from '../index';

import setType from '../../../../../utils/set-type';
import { getTestApp } from '../../../../../../test/utils/get-test-app';

import type Controller from '../../../../controller';

describe('module "router/route/params"', () => {
describe('#paramsFor()', () => {
let getController;

before(async () => {
const { controllers } = await getTestApp();

getController = (name: string): Controller => setType(() => {
return controllers.get(name);
});
});

describe('with model-less controller', () => {
let params;

before(() => {
params = paramsFor({
type: 'custom',
method: 'GET',
controller: getController('custom'),
dynamicSegments: []
});
});

it('contains query', () => {
expect(params.has('userId')).to.be.true;
});
});
});

describe('#defaultParamsFor()', () => {
let getController;

Expand Down
2 changes: 1 addition & 1 deletion src/packages/router/route/params/utils/get-query-params.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function getIncludeParam({
/**
* @private
*/
function getCustomParams({
export function getCustomParams({
query
}: Controller): Array<[string, ParameterLike]> {
return query.map(param => [param, new Parameter({
Expand Down
13 changes: 13 additions & 0 deletions test/test-app/app/controllers/custom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Controller } from 'LUX_LOCAL';

class CustomController extends Controller {
query = [
'userId'
];

index() {
return 204;
};
}

export default CustomController;
6 changes: 6 additions & 0 deletions test/test-app/app/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ export default function routes() {
only: ['index']
});

this.resource('custom', {
only: []
}, function(){
this.get('/', 'index');
});

this.resource('images');

this.resource('notifications', {
Expand Down

0 comments on commit dbdcc5a

Please sign in to comment.