From f7bb6b477bf78d33faa851434c79effed3af11af Mon Sep 17 00:00:00 2001 From: DaddyWarbucks Date: Wed, 23 Sep 2020 17:52:01 -0500 Subject: [PATCH 1/6] Use idList strategy --- lib/index.js | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/lib/index.js b/lib/index.js index 9b818e2..582ecee 100644 --- a/lib/index.js +++ b/lib/index.js @@ -212,15 +212,30 @@ class Service extends AdapterService { query = Object.assign(query, { collation: params.collation }); } - const findParams = Object.assign({}, params, { - paginate: false - }); const remapModifier = this._remapModifiers(this._normalizeId(id, data)); - return this.Model.updateMany(query, remapModifier, options) - .then(() => this._findOrGet(id, findParams)) - .then(select(params, this.id)) - .catch(errorHandler); + const idParams = Object.assign({}, params, { + paginate: false, + query: Object.assign({}, query, { $select: [this.id] }) + }); + + const ids = this._findOrGet(id, idParams) + .then(result => { + const items = Array.isArray(result) ? result : [result]; + return items.map(item => item[this.id]); + }); + + return ids.then(idList => { + const findParams = Object.assign({}, params, { + paginate: false, + query: { [this.id]: { $in: idList } } + }); + + return this.Model.updateMany(query, remapModifier, options) + .then(() => this._findOrGet(id, findParams)) + .then(select(params, this.id)) + .catch(errorHandler); + }); } _update (id, data, params = {}) { From 5a84ee9c4d1913fdbbf9a484e61e9fc93b0de75b Mon Sep 17 00:00:00 2001 From: DaddyWarbucks Date: Wed, 23 Sep 2020 18:34:57 -0500 Subject: [PATCH 2/6] Remove $select --- lib/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index 582ecee..7537015 100644 --- a/lib/index.js +++ b/lib/index.js @@ -216,7 +216,6 @@ class Service extends AdapterService { const idParams = Object.assign({}, params, { paginate: false, - query: Object.assign({}, query, { $select: [this.id] }) }); const ids = this._findOrGet(id, idParams) From 07e9f795f619bf1d254ff8d3368fdf3b55f4ae1a Mon Sep 17 00:00:00 2001 From: DaddyWarbucks Date: Wed, 23 Sep 2020 19:22:05 -0500 Subject: [PATCH 3/6] Add .patch multi query changed test --- test/index.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/index.test.js b/test/index.test.js index 15cd6b6..c96db98 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -33,6 +33,7 @@ const testSuite = adapterTests([ '.patch + id + query', '.patch multiple', '.patch multi query', + '.patch multi query changed', '.patch + NotFound', '.create', '.create + $select', From b5b8e782bce07415858f8a6c8800d6eb25d607fd Mon Sep 17 00:00:00 2001 From: DaddyWarbucks Date: Wed, 23 Sep 2020 19:35:16 -0500 Subject: [PATCH 4/6] Leave commented test --- test/index.test.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/test/index.test.js b/test/index.test.js index c96db98..37d9762 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -189,6 +189,41 @@ describe('Feathers MongoDB Service', () => { }); }); + // describe('.patch multi query changed', () => { + // let peopleService, people; + + // beforeEach(async () => { + // peopleService = app.service('/people'); + // peopleService.options.multi = true; + // people = await Promise.all([ + // peopleService.create({ name: 'AAA' }), + // peopleService.create({ name: 'aaa' }), + // peopleService.create({ name: 'ccc' }) + // ]); + // }); + + // afterEach(async () => { + // peopleService.options.multi = false; + // await Promise.all([ + // peopleService.remove(people[0]._id), + // peopleService.remove(people[1]._id), + // peopleService.remove(people[2]._id) + // ]).catch(() => {}); + // }); + + // it('Returns correct result when queried props are patched',async () => { + // const result = await peopleService.patch(null, { name: 'patched' }, { + // query: { name: { $gt: 'AAA' } } + // }); + + // expect(result).to.be.an('array'); + // expect(result).to.have.lengthOf(2); + // result.forEach(person => { + // expect(person.name).to.equal('patched'); + // }); + // }); + // }); + describe('Special collation param', () => { let peopleService, people; From ae5448b38fb340525271545e072c70142cc033e3 Mon Sep 17 00:00:00 2001 From: DaddyWarbucks Date: Wed, 23 Sep 2020 19:44:20 -0500 Subject: [PATCH 5/6] Add test --- test/index.test.js | 69 +++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 35 deletions(-) diff --git a/test/index.test.js b/test/index.test.js index 37d9762..a417f29 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -33,7 +33,6 @@ const testSuite = adapterTests([ '.patch + id + query', '.patch multiple', '.patch multi query', - '.patch multi query changed', '.patch + NotFound', '.create', '.create + $select', @@ -189,40 +188,40 @@ describe('Feathers MongoDB Service', () => { }); }); - // describe('.patch multi query changed', () => { - // let peopleService, people; - - // beforeEach(async () => { - // peopleService = app.service('/people'); - // peopleService.options.multi = true; - // people = await Promise.all([ - // peopleService.create({ name: 'AAA' }), - // peopleService.create({ name: 'aaa' }), - // peopleService.create({ name: 'ccc' }) - // ]); - // }); - - // afterEach(async () => { - // peopleService.options.multi = false; - // await Promise.all([ - // peopleService.remove(people[0]._id), - // peopleService.remove(people[1]._id), - // peopleService.remove(people[2]._id) - // ]).catch(() => {}); - // }); - - // it('Returns correct result when queried props are patched',async () => { - // const result = await peopleService.patch(null, { name: 'patched' }, { - // query: { name: { $gt: 'AAA' } } - // }); - - // expect(result).to.be.an('array'); - // expect(result).to.have.lengthOf(2); - // result.forEach(person => { - // expect(person.name).to.equal('patched'); - // }); - // }); - // }); + describe('.patch multi query changed', () => { + let peopleService, people; + + beforeEach(async () => { + peopleService = app.service('/people'); + peopleService.options.multi = true; + people = await Promise.all([ + peopleService.create({ name: 'AAA' }), + peopleService.create({ name: 'aaa' }), + peopleService.create({ name: 'ccc' }) + ]); + }); + + afterEach(async () => { + peopleService.options.multi = false; + await Promise.all([ + peopleService.remove(people[0]._id), + peopleService.remove(people[1]._id), + peopleService.remove(people[2]._id) + ]).catch(() => {}); + }); + + it('Returns correct result when queried props are patched',async () => { + const result = await peopleService.patch(null, { name: 'patched' }, { + query: { name: { $gt: 'AAA' } } + }); + + expect(result).to.be.an('array'); + expect(result).to.have.lengthOf(2); + result.forEach(person => { + expect(person.name).to.equal('patched'); + }); + }); + }); describe('Special collation param', () => { let peopleService, people; From e181d459c948f2b689fb47b57348a8bd58c65914 Mon Sep 17 00:00:00 2001 From: DaddyWarbucks Date: Sun, 27 Sep 2020 17:10:00 -0500 Subject: [PATCH 6/6] Use latest @feathersjs/adapter-tests --- package-lock.json | 6 +++--- package.json | 2 +- test/index.test.js | 36 +----------------------------------- 3 files changed, 5 insertions(+), 39 deletions(-) diff --git a/package-lock.json b/package-lock.json index 34dedbe..b34d126 100644 --- a/package-lock.json +++ b/package-lock.json @@ -43,9 +43,9 @@ } }, "@feathersjs/adapter-tests": { - "version": "4.5.2", - "resolved": "https://registry.npmjs.org/@feathersjs/adapter-tests/-/adapter-tests-4.5.2.tgz", - "integrity": "sha512-CvOqxreuM9hyyd3M5mYDUFoone/ZdX95OEewZtzyaaTutygl8s6XVOYdwzWlANuYFM12pGq0hBAQrgAszwdEqg==", + "version": "4.5.4", + "resolved": "https://registry.npmjs.org/@feathersjs/adapter-tests/-/adapter-tests-4.5.4.tgz", + "integrity": "sha512-VoBCFAa2NPsEPWqblom1kkY04w1vLkumUdwmvM0nk2oPGRYU5h7gsBipMt04v8mLKR+7vLOOnTLpPod7eyhmgw==", "dev": true }, "@feathersjs/commons": { diff --git a/package.json b/package.json index 3dcceac..bc6903a 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "@feathersjs/errors": "^4.5.3" }, "devDependencies": { - "@feathersjs/adapter-tests": "^4.5.2", + "@feathersjs/adapter-tests": "^4.5.4", "@feathersjs/express": "^4.5.4", "@feathersjs/feathers": "^4.5.3", "@feathersjs/socketio": "^4.5.4", diff --git a/test/index.test.js b/test/index.test.js index a417f29..c96db98 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -33,6 +33,7 @@ const testSuite = adapterTests([ '.patch + id + query', '.patch multiple', '.patch multi query', + '.patch multi query changed', '.patch + NotFound', '.create', '.create + $select', @@ -188,41 +189,6 @@ describe('Feathers MongoDB Service', () => { }); }); - describe('.patch multi query changed', () => { - let peopleService, people; - - beforeEach(async () => { - peopleService = app.service('/people'); - peopleService.options.multi = true; - people = await Promise.all([ - peopleService.create({ name: 'AAA' }), - peopleService.create({ name: 'aaa' }), - peopleService.create({ name: 'ccc' }) - ]); - }); - - afterEach(async () => { - peopleService.options.multi = false; - await Promise.all([ - peopleService.remove(people[0]._id), - peopleService.remove(people[1]._id), - peopleService.remove(people[2]._id) - ]).catch(() => {}); - }); - - it('Returns correct result when queried props are patched',async () => { - const result = await peopleService.patch(null, { name: 'patched' }, { - query: { name: { $gt: 'AAA' } } - }); - - expect(result).to.be.an('array'); - expect(result).to.have.lengthOf(2); - result.forEach(person => { - expect(person.name).to.equal('patched'); - }); - }); - }); - describe('Special collation param', () => { let peopleService, people;