Skip to content

Commit 8a775d4

Browse files
committed
fix(utils): shouldNotApplyJsonApi and shouldApplyJsonApi were not working when no model was set and methods was an array
Adding corresponding tests
1 parent b766dd0 commit 8a775d4

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

lib/utils.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ function shouldApplyJsonApi (ctx, options) {
230230
if (!model && methods === methodName) return true
231231
if (model === modelName && methods === methodName) return true
232232
if (model === modelName && _.includes(methods, methodName)) return true
233+
if (!model && _.includes(methods, methodName)) return true
233234
}
234235
}
235236

@@ -256,6 +257,7 @@ function shouldNotApplyJsonApi (ctx, options) {
256257
if (!model && methods === methodName) return true
257258
if (model === modelName && methods === methodName) return true
258259
if (model === modelName && _.includes(methods, methodName)) return true
260+
if (!model && _.includes(methods, methodName)) return true
259261
}
260262

261263
return false

test/remoteMethods.test.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var expect = require('chai').expect
66
var JSONAPIComponent = require('../')
77
var app, Post, Archive
88

9-
describe.only('loopback json api remote methods', function () {
9+
describe('loopback json api remote methods', function () {
1010
var autocompleteTitleData = ['Post 1', 'Post 2']
1111

1212
var archiveData = {
@@ -129,6 +129,33 @@ describe.only('loopback json api remote methods', function () {
129129
testLastJsonAPI()
130130
})
131131

132+
describe('when `exclude` is set', function (done) {
133+
beforeEach(function () {
134+
JSONAPIComponent(app, {
135+
handleCustomRemote: true,
136+
exclude: [{ methods: ['last', 'autocomplete', 'archives'] }],
137+
include: [{ methods: 'last' }]
138+
})
139+
})
140+
141+
testArchivesJsonAPI()
142+
testAutocompleteJsonAPI()
143+
testLastRaw()
144+
})
145+
146+
describe('when `include` is set', function (done) {
147+
beforeEach(function () {
148+
JSONAPIComponent(app, {
149+
handleCustomRemote: false,
150+
include: [{ methods: 'last' }]
151+
})
152+
})
153+
154+
testArchivesJsonAPI()
155+
testAutocompleteJsonAPI()
156+
testLastJsonAPI()
157+
})
158+
132159
/* Static test */
133160
function testAutocompleteJsonAPI () {
134161
it(

0 commit comments

Comments
 (0)