Skip to content

Commit 50d68e9

Browse files
committed
Add edge case
1 parent 3ceeef2 commit 50d68e9

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

test/create.test.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var query = require('./util/query')
55
var JSONAPIComponent = require('../')
66
var app
77
var Post
8+
var Comment
89

910
describe('loopback json api component create method', function () {
1011
beforeEach(function () {
@@ -17,6 +18,13 @@ describe('loopback json api component create method', function () {
1718
content: String
1819
})
1920
app.model(Post)
21+
22+
Comment = ds.createModel('comment', {
23+
id: {type: Number, id: true},
24+
content: String
25+
})
26+
app.model(Comment)
27+
2028
app.use(loopback.rest())
2129
JSONAPIComponent(app, { restApiRoot: '' })
2230
})
@@ -152,5 +160,33 @@ describe('loopback json api component create method', function () {
152160
done()
153161
})
154162
})
163+
164+
it('POST /models with null relationship data', function (done) {
165+
request(app).post('/posts').send({
166+
data: {
167+
type: 'posts',
168+
attributes: {
169+
title: 'my post',
170+
content: 'my post content'
171+
},
172+
relationships: {
173+
comments: {
174+
data: null
175+
}
176+
}
177+
}
178+
})
179+
.set('Content-Type', 'application/json')
180+
.end(function (err, res) {
181+
expect(err).to.equal(null)
182+
expect(res.body).to.have.all.keys('data')
183+
expect(res.body.data).to.have.all.keys('id', 'type', 'attributes', 'links')
184+
expect(res.body.data.id).to.equal('1')
185+
expect(res.body.data.type).to.equal('posts')
186+
expect(res.body.data.attributes).to.have.all.keys('title', 'content')
187+
expect(res.body.data.attributes).to.not.have.keys('id')
188+
done()
189+
})
190+
})
155191
})
156192
})

0 commit comments

Comments
 (0)