Skip to content

Commit

Permalink
Merge pull request #52 from orestes/action-transport
Browse files Browse the repository at this point in the history
fix(transport): Store multiple action calls
  • Loading branch information
orestes authored Nov 17, 2017
2 parents 15bf3f0 + 095eb4c commit 0b96f6a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
23 changes: 21 additions & 2 deletions sdk/action.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,26 @@ describe('Action', () => {
'id': 1
};
assert.ok(action.setEntity(entity));
assert.deepEqual(transport.getData('dev', '1.0', 'read'), entity);
assert.deepEqual(transport.getData('dev', '1.0', 'read'), [entity]);
});

it('should register multiple action calls in the transport', () => {
const mockTransport = {[m.meta]: {[m.origin]: ['users', '1.0'], [m.gateway]: ['', '']}};
const transport = new Transport(mockTransport);
const action = new Action(null, null, 'dev', '1.0', null, {}, false, 'read', {}, transport);
const entity =
{
'user': 'James',
'id': 1
};
const entity2 =
{
'user': 'Orestes',
'id': 1
};
assert.ok(action.setEntity(entity));
assert.ok(action.setEntity(entity2));
assert.deepEqual(transport.getData('dev', '1.0', 'read'), [entity, entity2]);
});

it('should throw an error if the `entity` is not specified', () => {
Expand All @@ -400,7 +419,7 @@ describe('Action', () => {
}
];
assert.ok(action.setCollection(collection));
assert.deepEqual(transport.getData('dev', '1.0', 'list'), collection);
assert.deepEqual(transport.getData('dev', '1.0', 'list'), [collection]);
});

it('should throw an error if the `collection` is not specified', () => {
Expand Down
8 changes: 7 additions & 1 deletion sdk/transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,13 @@ class Transport {
const gatewayPublicAddress = this._getGatewayPublicAddress();
const path = [m.data, gatewayPublicAddress, service, version, action];

this[_data] = this[_data].setIn(path, Immutable.fromJS(source));
if (!this[_data].hasIn(path)) {
this[_data] = this[_data].setIn(path, Immutable.fromJS([]));
}

this[_data] = this[_data].updateIn(path, function(list) {
return list.push(Immutable.fromJS(source));
});
}

/**
Expand Down

0 comments on commit 0b96f6a

Please sign in to comment.