Skip to content

Commit

Permalink
Merge pull request #31 from pmould/replaceLodashMergeForWhereMerge
Browse files Browse the repository at this point in the history
Replace lodash merge with merge-options
  • Loading branch information
scott-wyatt authored Jan 10, 2019
2 parents 1a1e130 + dfc19c0 commit f103e07
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/api/services/SequelizeService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { FabrixService as Service } from '@fabrix/fabrix/dist/common'

import { defaults, omitBy, isArray, isObject, isString, isNil, merge } from 'lodash'
import { defaults, omitBy, isArray, isObject, isString, isNil } from 'lodash'

const merge = require('merge-options')

export class SequelizeService extends Service {
/**
Expand Down
15 changes: 15 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"@types/lodash": "^4.14.109",
"@types/node": "~10.3.4",
"@types/sequelize": "^4.27.31",
"merge-options": "^1.0.1",
"mocha": "^5",
"nyc": "^13.1.0",
"pg": "^6.4.2",
Expand Down
16 changes: 16 additions & 0 deletions test/unit/services/SequelizeService.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

const assert = require('assert')
const sequelize = require('sequelize')

describe('api.services.SequelizeService', () => {
it.skip('should do stringify sort', (done) => {
Expand Down Expand Up @@ -66,6 +67,21 @@ describe('api.services.SequelizeService', () => {
assert.equal(newOptions.where.created_at, 'now')
done()
})
it('should merge wheres with operator symbol', (done) => {
const newOptions = global.app.services.SequelizeService.mergeOptionDefaults({
where: {}
}, {
where: {
name: {
[sequelize.Op.in]: [1, 2, 3]
}}
})
assert.equal(newOptions.where.name[sequelize.Op.in][0], 1)
assert.equal(newOptions.where.name[sequelize.Op.in][1], 2)
assert.equal(newOptions.where.name[sequelize.Op.in][2], 3)
done()
})

it('should merge limit', (done) => {
const newOptions = global.app.services.SequelizeService.mergeOptionDefaults({
limit: null
Expand Down

0 comments on commit f103e07

Please sign in to comment.