This commit is contained in:
typicode
2018-12-25 23:31:19 +01:00
9 changed files with 3269 additions and 5326 deletions

View File

@ -3,6 +3,7 @@
## 0.14.1 - Unreleased
* Show error message if port is already used
* Upgrade to [lowdb](https://github.com/typicode/lowdb) `1.0`
## 0.14.0 - 2018-06-09

View File

@ -133,7 +133,7 @@ describe('cli', () => {
test('should use _id as foreignKeySuffix', async () => {
const response = await request.get('/posts/1/comments')
assert.equal(response.body.length, 1)
assert.strictEqual(response.body.length, 1)
})
test('should apply middlewares', done => {
@ -208,7 +208,7 @@ describe('cli', () => {
})
test('should save a snapshot in snapshots dir', () => {
assert.equal(fs.readdirSync(snapshotsDir).length, 1)
assert.strictEqual(fs.readdirSync(snapshotsDir).length, 1)
})
})

View File

@ -31,7 +31,10 @@ describe('mixins', () => {
{ name: 'comments', id: 3 }
]
assert.deepEqual(_.getRemovable(db, { foreignKeySuffix: 'Id' }), expected)
assert.deepStrictEqual(
_.getRemovable(db, { foreignKeySuffix: 'Id' }),
expected
)
})
test('should support custom foreignKeySuffix', () => {
@ -40,17 +43,20 @@ describe('mixins', () => {
{ name: 'comments', id: 3 }
]
assert.deepEqual(_.getRemovable(db, { foreignKeySuffix: 'Id' }), expected)
assert.deepStrictEqual(
_.getRemovable(db, { foreignKeySuffix: 'Id' }),
expected
)
})
})
describe('createId', () => {
test('should return a new id', () => {
assert.equal(_.createId(db.comments), 4)
assert.strictEqual(_.createId(db.comments), 4)
})
test('should return a new uuid', () => {
assert.notEqual(_.createId(db.photos), 3)
assert.notStrictEqual(_.createId(db.photos), 3)
})
})
})

View File

@ -100,7 +100,7 @@ describe('Server with custom foreign key', () => {
.post('/posts/1/comments')
.send({ body: 'foo' })
.expect('Content-Type', /json/)
.expect({ id: 4, post_id: 1, body: 'foo' })
.expect({ id: 4, post_id: '1', body: 'foo' })
.expect(201))
})
@ -110,8 +110,8 @@ describe('Server with custom foreign key', () => {
.del('/posts/1')
.expect({})
.expect(200)
assert.equal(db.posts.length, 1)
assert.equal(db.comments.length, 1)
assert.strictEqual(db.posts.length, 1)
assert.strictEqual(db.comments.length, 1)
})
})
})

View File

@ -523,7 +523,7 @@ describe('Server', () => {
.expect('Content-Type', /json/)
.expect({ id: 3, body: 'foo', booleanValue: true, integerValue: 1 })
.expect(201)
assert.equal(db.posts.length, 3)
assert.strictEqual(db.posts.length, 3)
})
test('should support x-www-form-urlencoded', async () => {
@ -535,16 +535,16 @@ describe('Server', () => {
// x-www-form-urlencoded will convert to string
.expect({ id: 3, body: 'foo', booleanValue: 'true', integerValue: '1' })
.expect(201)
assert.equal(db.posts.length, 3)
assert.strictEqual(db.posts.length, 3)
})
test('should respond with json, create a resource and generate string id', async () => {
await request(server)
.post('/refs')
.send({ url: 'http://foo.com', postId: '1' })
.send({ url: 'http://foo.com', postId: 1 })
.expect('Content-Type', /json/)
.expect(201)
assert.equal(db.refs.length, 2)
assert.strictEqual(db.refs.length, 2)
})
})
@ -554,7 +554,7 @@ describe('Server', () => {
.post('/posts/1/comments')
.send({ body: 'foo' })
.expect('Content-Type', /json/)
.expect({ id: 6, postId: 1, body: 'foo' })
.expect({ id: 6, postId: '1', body: 'foo' })
.expect(201))
})
@ -656,8 +656,8 @@ describe('Server', () => {
.del('/posts/1')
.expect({})
.expect(200)
assert.equal(db.posts.length, 1)
assert.equal(db.comments.length, 3)
assert.strictEqual(db.posts.length, 1)
assert.strictEqual(db.comments.length, 3)
})
test('should respond with 404 if resource is not found', () =>

View File

@ -7,7 +7,7 @@ describe('utils', () => {
const perPage = 2
test('should return first page', () => {
assert.deepEqual(utils.getPage(array, 1, perPage), {
assert.deepStrictEqual(utils.getPage(array, 1, perPage), {
items: [1, 2],
current: 1,
first: 1,
@ -17,7 +17,7 @@ describe('utils', () => {
})
test('should return second page', () => {
assert.deepEqual(utils.getPage(array, 2, perPage), {
assert.deepStrictEqual(utils.getPage(array, 2, perPage), {
items: [3, 4],
current: 2,
first: 1,
@ -28,7 +28,7 @@ describe('utils', () => {
})
test('should return third page (last)', () => {
assert.deepEqual(utils.getPage(array, 3, perPage), {
assert.deepStrictEqual(utils.getPage(array, 3, perPage), {
items: [5],
current: 3,
first: 1,
@ -38,19 +38,19 @@ describe('utils', () => {
})
test('should return an empty array if page is greater than the last page', () => {
assert.deepEqual(utils.getPage(array, 99, perPage), {
assert.deepStrictEqual(utils.getPage(array, 99, perPage), {
items: []
})
})
test('should return the array if perPage is greater than the array size', () => {
assert.deepEqual(utils.getPage(array, 1, 99), {
assert.deepStrictEqual(utils.getPage(array, 1, 99), {
items: array
})
})
test('should return an empty array if the array is empty', () => {
assert.deepEqual(utils.getPage([], 1, 1), {
assert.deepStrictEqual(utils.getPage([], 1, 1), {
items: []
})
})

8474
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -23,72 +23,72 @@
"chalk": "^2.4.1",
"compression": "^1.7.3",
"connect-pause": "^0.1.1",
"cors": "^2.8.4",
"cors": "^2.8.5",
"errorhandler": "^1.2.0",
"express": "^4.16.3",
"express": "^4.16.4",
"express-urlrewrite": "^1.2.0",
"json-parse-helpfulerror": "^1.0.3",
"lodash": "^4.17.10",
"lodash": "^4.17.11",
"lodash-id": "^0.14.0",
"lowdb": "^1.0.0",
"method-override": "^2.3.10",
"morgan": "^1.9.0",
"nanoid": "^1.1.1",
"method-override": "^3.0.0",
"morgan": "^1.9.1",
"nanoid": "^2.0.0",
"object-assign": "^4.0.1",
"please-upgrade-node": "^3.1.1",
"pluralize": "^7.0.0",
"request": "^2.87.0",
"request": "^2.88.0",
"server-destroy": "^1.0.1",
"update-notifier": "^2.5.0",
"yargs": "^11.1.0"
"yargs": "^12.0.2"
},
"devDependencies": {
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.0",
"@babel/cli": "^7.1.5",
"@babel/core": "^7.1.5",
"@babel/node": "^7.0.0",
"@babel/plugin-syntax-jsx": "^7.0.0",
"@babel/plugin-transform-react-jsx": "^7.0.0",
"@babel/plugin-transform-regenerator": "^7.0.0",
"@babel/polyfill": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/preset-env": "^7.1.5",
"@babel/register": "^7.0.0",
"babel-core": "^7.0.0-bridge.0",
"babel-loader": "^8.0.0",
"babel-loader": "^8.0.4",
"babel-preset-preact": "^1.1.0",
"babel-preset-react": "^6.24.1",
"clean-webpack-plugin": "^0.1.19",
"cross-env": "^5.2.0",
"css-loader": "^0.28.11",
"eslint": "^4.19.1",
"eslint-config-prettier": "^2.9.0",
"eslint-config-standard": "^11.0.0",
"css-loader": "^1.0.1",
"eslint": "^5.8.0",
"eslint-config-prettier": "^3.1.0",
"eslint-config-standard": "^12.0.0",
"eslint-config-standard-preact": "^1.1.6",
"eslint-plugin-import": "^2.13.0",
"eslint-plugin-node": "^6.0.1",
"eslint-plugin-prettier": "^2.6.2",
"eslint-plugin-promise": "^3.8.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-node": "^8.0.0",
"eslint-plugin-prettier": "^3.0.0",
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-react": "^7.10.0",
"eslint-plugin-standard": "^3.1.0",
"eslint-plugin-standard": "^4.0.0",
"html-webpack-plugin": "^3.2.0",
"husky": "^1.0.0-rc.13",
"jest": "^23.4.2",
"husky": "^1.1.3",
"jest": "^23.6.0",
"markdown-toc": "^1.2.0",
"milligram": "^1.3.0",
"mini-css-extract-plugin": "^0.4.1",
"mini-css-extract-plugin": "^0.4.4",
"mkdirp": "^0.5.1",
"npm-run-all": "^4.1.3",
"os-tmpdir": "^1.0.1",
"pkg-ok": "^2.2.0",
"preact": "^8.3.0",
"prettier": "^1.14.2",
"promise-polyfill": "^8.0.0",
"os-tmpdir": "^2.0.0",
"pkg-ok": "^2.3.1",
"preact": "^8.3.1",
"prettier": "^1.15.1",
"promise-polyfill": "^8.1.0",
"rimraf": "^2.6.2",
"server-ready": "^0.3.1",
"supertest": "^3.1.0",
"supertest": "^3.3.0",
"temp-write": "^3.4.0",
"webpack": "^4.16.5",
"webpack-cli": "^3.1.0",
"whatwg-fetch": "^2.0.4"
"webpack": "^4.25.1",
"webpack-cli": "^3.1.2",
"whatwg-fetch": "^3.0.0"
},
"repository": {
"type": "git",

View File

@ -4,7 +4,7 @@ const _ = require('lodash')
const lodashId = require('lodash-id')
const low = require('lowdb')
const Memory = require('lowdb/adapters/Memory')
const FileSync = require('lowdb/adapters/FileSync')
const FileAsync = require('lowdb/adapters/FileAsync')
const bodyParser = require('../body-parser')
const validateData = require('./validate-data')
const plural = require('./plural')
@ -14,7 +14,7 @@ const mixins = require('../mixins')
module.exports = (db, opts = { foreignKeySuffix: 'Id', _isFake: false }) => {
if (typeof db === 'string') {
db = low(new FileSync(db))
db = low(new FileAsync(db))
} else if (!_.has(db, '__chain__') || !_.has(db, '__wrapped__')) {
db = low(new Memory()).setState(db)
}