Skip to content

Commit

Permalink
Merge pull request #495 from dadi/feature/collections-endpoint-schemas
Browse files Browse the repository at this point in the history
Add collection schemas to collections endpoint
  • Loading branch information
eduardoboucas authored Sep 27, 2018
2 parents aacad3d + 4a79ce9 commit dbc1a35
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
6 changes: 5 additions & 1 deletion dadi/lib/controller/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ Collections.prototype.get = function (req, res, next) {
database: parts[2],
name: (model.settings && model.settings.displayName) || model.name,
slug: model.name,
path: key
path: key,
fields: model.schema,
settings: Object.assign({}, model.settings, {
database: undefined
})
}

if (model.settings) {
Expand Down
3 changes: 2 additions & 1 deletion features.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[
"aclv1",
"i18nv1",
"i18nv2"
"i18nv2",
"collectionsv1"
]
37 changes: 37 additions & 0 deletions test/acceptance/collections-endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,43 @@ describe('Collections endpoint', function () {
})
})

it('should include the fields and settings for each collection', done => {
help.getBearerTokenWithPermissions({
accessType: 'admin'
}).then(token => {
client
.get(`/api/collections`)
.set('content-type', 'application/json')
.set('Authorization', `Bearer ${token}`)
.end((err, res) => {
let allCollections = help.getCollectionMap()

res.body.collections.length.should.eql(
Object.keys(allCollections).length
)

Object.keys(allCollections).forEach(key => {
let match = res.body.collections.some(collection => {
if (collection.path === key) {
collection.fields.should.eql(allCollections[key].fields)
Object.keys(collection.settings).should.eql(
Object.keys(allCollections[key].settings)
)

return true
}

return false
})

match.should.eql(true)
})

done()
})
})
})

it('should return only the collections the requesting client has read access to', done => {
help.getBearerTokenWithPermissions({
resources: {
Expand Down

0 comments on commit dbc1a35

Please sign in to comment.