Skip to content

Commit

Permalink
feat: pass compose parameter from datasource to endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
jimlambie committed Apr 16, 2019
1 parent 2e55e77 commit 6d61f1a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
5 changes: 5 additions & 0 deletions dadi/lib/providers/dadiapi.js
Expand Up @@ -369,6 +369,11 @@ DadiApiProvider.prototype.processDatasourceParameters = function (
params.push({ cache: datasourceParams.cache })
}

// pass compose parameter to API endpoint
if (datasourceParams.hasOwnProperty('compose')) {
params.push({ compose: datasourceParams.compose })
}

// pass language to api endpoint
if (datasourceParams.lang) {
params.push({ lang: datasourceParams.lang })
Expand Down
30 changes: 30 additions & 0 deletions test/unit/datasource.js
Expand Up @@ -858,6 +858,36 @@ describe('Datasource', done => {
})
})

it('should pass compose param to the endpoint', done => {
const name = 'test'
const schema = TestHelper.getPageSchema()
const p = page(name, schema)
const dsName = 'car_makes'
const options = TestHelper.getPathOptions()
const dsSchema = TestHelper.getSchemaFromFile(
options.datasourcePath,
dsName
)

// modify the endpoint to give it a compose setting
dsSchema.datasource.compose = 'all'

sinon
.stub(Datasource.Datasource.prototype, 'loadDatasource')
.yields(null, dsSchema)

const req = { params: {}, url: '/1.0/makes/ford/2' }

new Datasource(p, dsName, options).init((err, ds) => {
Datasource.Datasource.prototype.loadDatasource.restore()
ds.processRequest(dsName, req)
ds.provider.endpoint.should.eql(
'http://127.0.0.1:3000/1.0/cars/makes?count=20&page=1&filter={}&fields={"name":1,"_id":0}&sort={"name":1}&compose=all'
)
done()
})
})

it('should pass page param to the endpoint when page.passFilters is true', done => {
const name = 'test'
const schema = TestHelper.getPageSchema()
Expand Down

0 comments on commit 6d61f1a

Please sign in to comment.