Skip to content

Commit

Permalink
Merge branch 'release-4.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoboucas committed Sep 27, 2018
2 parents ff9d5ac + 7e7462e commit 844afd9
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 4 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [4.3.0] (2018-09-27)

### Changed

- [#490](https://github.com/dadi/api/issues/490): add i18n field character to /api/languages endpoint
- [#492](https://github.com/dadi/api/issues/492): add collection schemas and settings to /api/collections endpoint

## [4.2.2] (2018-09-04)

### Changed
Expand Down
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
2 changes: 1 addition & 1 deletion dadi/lib/controller/languages.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ Languages.prototype.get = function (req, res, next) {
}

let languages = supportedLanguages.map(this._getLanguageDetails)

let metadata = {
defaultLanguage: this._getLanguageDetails(defaultLanguage),
fieldCharacter: config.get('i18n.fieldCharacter'),
totalCount: supportedLanguages.length
}

Expand Down
4 changes: 3 additions & 1 deletion features.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
[
"aclv1",
"i18nv1"
"i18nv1",
"i18nv2",
"collectionsv1"
]
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dadi/api",
"version": "4.2.2",
"version": "4.3.0",
"main": "main.js",
"scripts": {
"create-client": "cd ../../.. && node ./node_modules/@dadi/api/utils/create-client.js",
Expand All @@ -9,6 +9,7 @@
"test:prepare": "rm -rf cache && rm -rf config/config.test.json && rm -rf test/acceptance/temp-workspace && cp -R test/acceptance/workspace test/acceptance/temp-workspace",
"test": "npm run test:prepare && standard --fix 'dadi/**/*.js' | snazzy && env NODE_ENV=test ./node_modules/.bin/istanbul cover --report cobertura --report text --report html --report lcov ./node_modules/mocha/bin/_mocha && npm run test:cleanup",
"test:cleanup": "rm -rf test/acceptance/temp-workspace",
"precommit": "node scripts/precommit.js",
"posttest": "./scripts/coverage.js",
"start": "node start.js --node_env=development"
},
Expand Down
42 changes: 42 additions & 0 deletions scripts/precommit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env node

const exec = require('child_process').exec

function currentBranch () {
return new Promise((resolve, reject) => {
exec('git branch --no-color', (err, out) => {
if (err) return reject(err)

let branches = out.split('\n')
let branch = branches.find(branch => {
return /^\*/.test(branch)
})

branch = branch.replace('*', '')
branch = branch.trim()

return resolve(branch)
})
})
}

currentBranch().then(branch => {
console.log('Checking branch name...')

if (branch !== 'master' &&
branch !== 'develop' &&
!/^feature\//.test(branch) &&
!/^patch\//.test(branch) &&
!/^release-/.test(branch)
) {
console.log()
console.log('Branch name invalid.')
console.log('Please use topic branches named "feature/...", or "patch/..."')
console.log()

process.exit(1)
} else {
console.log('Branch name OK.')
process.exit(0)
}
})
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
18 changes: 18 additions & 0 deletions test/acceptance/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,24 @@ describe('Multi-language', function () {
done()
})
})

it('should include a `fieldCharacter` property in the metadata block', done => {
config.set('i18n.fieldCharacter', '@')

client
.get('/api/languages')
.set('Authorization', `Bearer ${bearerToken}`)
.expect(200)
.end((err, res) => {
if (err) return done(err)

res.body.metadata.fieldCharacter.should.eql('@')

config.set('i18n.fieldCharacter', configBackup.i18n.fieldCharacter)

done()
})
})
})

it('should accept a language variation of a field, separated by the character configured in `i18n.fieldCharacter` (using default)', done => {
Expand Down

0 comments on commit 844afd9

Please sign in to comment.