Skip to content

Commit 8f80f69

Browse files
committed
test(relations): add additional integration test
1 parent f5f1eb4 commit 8f80f69

File tree

1 file changed

+36
-34
lines changed

1 file changed

+36
-34
lines changed

test/relationship-utils.test.js

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
// const request = require('supertest')
3+
const request = require('supertest')
44
const loopback = require('loopback')
55
const expect = require('chai').expect
66
const JSONAPIComponent = require('../')
@@ -64,39 +64,41 @@ describe('relationship utils', () => {
6464
startApp()
6565
})
6666

67-
// describe('Ensure correct hasMany model linkages updated', function () {
68-
// it('should update model linkages', () => {
69-
// const payload = {
70-
// data: {
71-
// type: 'posts',
72-
// attributes: { title: 'my post', content: 'my post content' },
73-
// relationships: {
74-
// comments: {
75-
// data: [
76-
// { type: 'comments', id: 2 },
77-
// { type: 'comments', id: 3 },
78-
// { type: 'comments', id: 4 }
79-
// ]
80-
// }
81-
// }
82-
// }
83-
// }
84-
// return Comment.create([{id: 1, postId: 1}, {id: 2, postId: 1}, {id: 3, postId: 1}, {id: 4}])
85-
// .then(() => {
86-
// return request(app).post('/posts')
87-
// .send(payload)
88-
// .set('Accept', 'application/vnd.api+json')
89-
// .set('Content-Type', 'application/json')
90-
// .then(res => Comment.find({ postId: 1 }))
91-
// .then(comments => {
92-
// expect(comments.length).to.equal(3)
93-
// expect(comments[0].id).to.equal(2)
94-
// expect(comments[1].id).to.equal(3)
95-
// expect(comments[2].id).to.equal(4)
96-
// })
97-
// })
98-
// })
99-
// })
67+
describe('Ensure correct hasMany model linkages updated', function () {
68+
it('should update model linkages', () => {
69+
setupHasMany()
70+
const payload = {
71+
data: {
72+
type: 'posts',
73+
attributes: { title: 'my post', content: 'my post content' },
74+
relationships: {
75+
comments: {
76+
data: [
77+
{ type: 'comments', id: 2 },
78+
{ type: 'comments', id: 3 },
79+
{ type: 'comments', id: 4 }
80+
]
81+
}
82+
}
83+
}
84+
}
85+
return Comment.create([{ postId: 1 }, { postId: 1 }, { postId: 1 }, {}])
86+
.then(() => {
87+
return request(app)
88+
.post('/posts')
89+
.send(payload)
90+
.set('Accept', 'application/vnd.api+json')
91+
.set('Content-Type', 'application/json')
92+
.then(res => Comment.find({ where: { postId: res.body.data.id } }))
93+
.then(comments => {
94+
expect(comments.length).to.equal(3)
95+
expect(comments[0].id).to.equal(2)
96+
expect(comments[1].id).to.equal(3)
97+
expect(comments[2].id).to.equal(4)
98+
})
99+
})
100+
})
101+
})
100102

101103
describe('updateHasMany()', function () {
102104
it('should update model linkages', () => {

0 commit comments

Comments
 (0)