|
1 | 1 | 'use strict' |
2 | 2 |
|
3 | | -// const request = require('supertest') |
| 3 | +const request = require('supertest') |
4 | 4 | const loopback = require('loopback') |
5 | 5 | const expect = require('chai').expect |
6 | 6 | const JSONAPIComponent = require('../') |
@@ -64,39 +64,41 @@ describe('relationship utils', () => { |
64 | 64 | startApp() |
65 | 65 | }) |
66 | 66 |
|
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 | + }) |
100 | 102 |
|
101 | 103 | describe('updateHasMany()', function () { |
102 | 104 | it('should update model linkages', () => { |
|
0 commit comments