Skip to content

Commit 56ee087

Browse files
committed
improved setRequestedIncludes F, added tests
1 parent 022303a commit 56ee087

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

lib/utils.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -246,14 +246,16 @@ function setRequestedIncludes (include) {
246246
if (typeof include === 'string') {
247247
return include
248248
}
249+
if (include instanceof Array) {
250+
return include.map(function (inc) {
251+
if (typeof inc === 'string') {
252+
return inc
253+
}
249254

250-
return include.map(function (inc) {
251-
if (typeof inc === 'string') {
252-
return inc
253-
}
254-
255-
if (inc instanceof Object) {
256-
return inc.relation
257-
}
258-
})
255+
if (inc instanceof Object) {
256+
return inc.relation
257+
}
258+
})
259+
}
260+
return include
259261
}

test/scopeInclude.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,28 @@ describe('include option', function () {
127127
done()
128128
})
129129
})
130+
it('should include comments', function (done) {
131+
request(app)
132+
.get('/posts/1?filter={"include":["comments"]}')
133+
.end(function (err, res) {
134+
expect(err).to.equal(null)
135+
expect(res.body.included.length).equal(2)
136+
expect(res.body.included[0].type).equal('comments')
137+
expect(res.body.included[1].type).equal('comments')
138+
done()
139+
})
140+
})
141+
it('should include categories with empty attributes object', function (done) {
142+
request(app)
143+
.get('/posts/1?filter={"include":[{"relation":"category", "scope": {"fields": ["id"]}}]}')
144+
.end(function (err, res) {
145+
expect(err).to.equal(null)
146+
expect(res.body.included.length).equal(3)
147+
expect(res.body.included[0].type).equal('categories')
148+
expect(res.body.included[0].attributes).to.include({})
149+
done()
150+
})
151+
})
130152
})
131153
})
132154
})

0 commit comments

Comments
 (0)