Skip to content

Commit fd0c608

Browse files
authored
Merge pull request #131 from micro-toolkit/fix/130-embeds-without-nil-values
embeds shouldnt send nil values to batch operation
2 parents 127e021 + e59c777 commit fd0c608

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/embed.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function fetchEmbed(relations, config, data, headers){
3737
var toModel = model(config, metadata);
3838
var payloadKey = isResource ? parent.idKey : relation.modelFk;
3939
var payload = {};
40-
payload[payloadKey] = _.map(data, idKey);
40+
payload[payloadKey] = _.reject(_.map(data, idKey), _.isNil);
4141

4242
log.debug('Embeds subresource %s in request', relation.name);
4343
return client.batch(payload, headers)

tests/embeds_test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,16 @@ describe('Unit | embeds', function() {
144144
.should.eventually.have.deep.property('0.user');
145145
});
146146

147+
it('should embed resource in a collection without null values', function() {
148+
sinon.stub(serviceStub, 'batch')
149+
.withArgs({id: ['u1']})
150+
.resolves({payload: [{id: 'u1', data: userData}] });
151+
152+
var tasks = [taskData, { id: 't2', userId: null }];
153+
return target(metadata.v1.task, config, {query:{embeds: 'user'}}, tasks)
154+
.should.eventually.have.deep.property('1.user', null);
155+
});
156+
147157
it('should embed resource in a resource', function() {
148158
sinon.stub(serviceStub, 'batch')
149159
.withArgs({id: ['u1']})

0 commit comments

Comments
 (0)