Remove empty params in PathTemplate#callable()

pull/4734/head
Alex Dik 8 years ago
parent 080e35cee4
commit 4ac4e27496
  1. 29
      frontend/app/components/api/path-builder/path-builder.service.test.ts
  2. 5
      frontend/app/components/api/path-builder/path-builder.service.ts

@ -177,11 +177,32 @@ describe('pathBuilder service', () => {
});
describe('when the path is a child of a path with a parent', () => {
testCallablePath(() => {
beforeEach(() => {
path = pathCollection.withParentAndChild.child;
params = {child: 'childId', parent: 'parentId'};
withParams = 'parent/parentId/world/child/childId';
withoutParams = 'world/child';
});
describe('when only the child id is set', () => {
testCallablePath(() => {
params = {child: 'childId', parent: null};
withParams = 'world/child/childId';
withoutParams = 'world/child';
});
});
describe('when only the parent id is set', () => {
testCallablePath(() => {
params = {parent: 'parentId', child: null};
withParams = 'parent/parentId/world/child';
withoutParams = 'world/child';
});
});
describe('when both ids are set', () => {
testCallablePath(() => {
params = {child: 'childId', parent: 'parentId'};
withParams = 'parent/parentId/world/child/childId';
withoutParams = 'world/child';
});
});
});
});

@ -77,6 +77,7 @@ class PathTemplate {
*/
public callable() {
const callable = (params = {}) => {
params = _.pick(params, value => !!value);
return URI.expand(this.build(params), params).valueOf();
};
@ -95,10 +96,6 @@ class PathTemplate {
*/
public build(params) {
Object.keys(params).forEach(name => {
if (!params[name]) {
delete params[name];
return;
}
const parent = this.parents[name];
if (parent) {

Loading…
Cancel
Save