-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored href-builder to reflect the code review notes
- prepareServerGet was changed to use querystring.stringify for addign the component parameters as URL query params. - change the returned URL to include a trailing '/' before the URL query params (and thus making it to follow the same pattern as in client method) - changed the client.js acceptance test according to the aforementioned changes - added client-href-builder.js unit test
- Loading branch information
1 parent
6e9d087
commit ada38c0
Showing
4 changed files
with
68 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,4 +143,4 @@ describe('client : get-component-data', () => { | |
}); | ||
}); | ||
|
||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
'use strict'; | ||
|
||
var expect = require('chai').expect; | ||
var hrefBuilderPrototype = require('../../client/src/href-builder'); | ||
|
||
describe('client : href-builder :', () => { | ||
|
||
describe('server method - ', () => { | ||
describe('when the server rendering endpoint is set in both the options and in the configuration', () => { | ||
it('should get the result from the options', () => { | ||
let hrefBuilder = new hrefBuilderPrototype({registries: {serverRendering: 'from configuration'}}); | ||
expect(hrefBuilder.server({registries: {serverRendering: 'from options'}})).to.equal('from options'); | ||
}); | ||
}); | ||
|
||
describe('when the server rendering endpoint is not set in the options param', () => { | ||
it('it should get the result from the configuration', () => { | ||
let hrefBuilder = new hrefBuilderPrototype({registries: {serverRendering: 'from configuration'}}); | ||
expect(hrefBuilder.server({})).to.equal('from configuration'); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('prepareServerGet method - ', () => { | ||
describe('when only the component name is set', () => { | ||
it('it should return a valid request for the component', () => { | ||
let hrefBuilder = new hrefBuilderPrototype({}); | ||
expect(hrefBuilder.prepareServerGet('http://localhost:3030', {name: 'hello-world'}, {})) | ||
.to.equal('http://localhost:3030/hello-world'); | ||
}); | ||
}); | ||
|
||
describe('when the component name and version are set', () => { | ||
it('it should return a valid request for the component', () => { | ||
let hrefBuilder = new hrefBuilderPrototype({}); | ||
expect(hrefBuilder.prepareServerGet('http://localhost:3030', {name: 'hello-world', version: '1.0.0'}, {})) | ||
.to.equal('http://localhost:3030/hello-world/1.0.0'); | ||
}); | ||
}); | ||
|
||
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 hrefBuilder = new hrefBuilderPrototype({}); | ||
|
||
expect(hrefBuilder.prepareServerGet('http://localhost:3030', component, options)) | ||
.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 hrefBuilder = new hrefBuilderPrototype({}); | ||
|
||
expect(hrefBuilder.prepareServerGet('http://localhost:3030', component, options)) | ||
.to.equal('http://localhost:3030/hello-world/1.0.0/?p1=v1&p2=v%202'); | ||
}); | ||
}); | ||
}); | ||
}); |