Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prepare-server-get-component-parameters #432

Merged
merged 10 commits into from
Apr 4, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/src/get-components-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ module.exports = function(config){

var performGet = function(endpoint, serverRendering, options, callback) {
var component = serverRendering.components[0];
var requestUrl = hrefBuilder.prepareServerGet(endpoint, component, options);
var requestUrl = hrefBuilder.prepareServerGet(endpoint, component);

var requestDetails = {
url: requestUrl,
Expand Down
4 changes: 2 additions & 2 deletions client/src/href-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ module.exports = function(config){
}
},

prepareServerGet: function(baseUrl, component, options) {
prepareServerGet: function(baseUrl, component) {
var urlPath = component.name + (component.version ? '/' + component.version : '');
var qs = options.parameters ? ('/?' + querystring.stringify(options.parameters)) : '';
var qs = component.parameters ? ('/?' + querystring.stringify(component.parameters)) : '';

return url.resolve(baseUrl, urlPath + qs);
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"oc": "./src/oc-cli.js"
},
"scripts": {
"test": "grunt test"
"test": "grunt test",
"test:unit": "mocha test/unit"
},
"engines": {
"node": ">=4"
Expand Down
5 changes: 3 additions & 2 deletions test/unit/client-get-component-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ describe('client : get-component-data', () => {

const component = {
name: 'hello-world',
version: '1.0.0'
version: '1.0.0',
parameters: options.parameters
};

getComponentData([{
Expand All @@ -54,7 +55,7 @@ describe('client : get-component-data', () => {
it('href-builder prepareServerGet method is invoked', () => {
sinon.assert.calledOnce(serverStub);
sinon.assert.calledOnce(prepareServerGetStub);
sinon.assert.calledWith(prepareServerGetStub, baseUrl, {name: 'hello-world', version: '1.0.0'}, options);
sinon.assert.calledWith(prepareServerGetStub, baseUrl, { name: 'hello-world', version: '1.0.0', parameters: options.parameters });
});

it('a GET request is made with the URL returned by href-builder.prepareServerGet method', () => {
Expand Down
10 changes: 4 additions & 6 deletions test/unit/client-href-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,20 @@ describe('client : href-builder :', () => {

describe('when there is one component parameter set in the options', () => {
it('it should return a valid request for the component with the parameter set as URL query param', () => {
let options = {parameters: {p1: 'v1'}};
let component = {name: 'hello-world', version: '1.0.0'};
let component = { name: 'hello-world', version: '1.0.0', parameters: { p1: 'v1' } };
let hrefBuilder = new hrefBuilderPrototype({});

expect(hrefBuilder.prepareServerGet('http://localhost:3030', component, options))
expect(hrefBuilder.prepareServerGet('http://localhost:3030', component))
.to.equal('http://localhost:3030/hello-world/1.0.0/?p1=v1');
});
});

describe('when there are more than one component parameters set in the options', () => {
it('it should return a valid request for the component with the parameters set as URL query params', () => {
let options = {parameters: {p1: 'v1', p2: 'v 2'}};
let component = {name: 'hello-world', version: '1.0.0'};
let component = { name: 'hello-world', version: '1.0.0', parameters: { p1: 'v1', p2: 'v 2' } };
let hrefBuilder = new hrefBuilderPrototype({});

expect(hrefBuilder.prepareServerGet('http://localhost:3030', component, options))
expect(hrefBuilder.prepareServerGet('http://localhost:3030', component))
.to.equal('http://localhost:3030/hello-world/1.0.0/?p1=v1&p2=v%202');
});
});
Expand Down