Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion languages/javascript/src/shared/Gateway/Bidirectional.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,15 @@ function processMessage(json) {
if (json.id !== undefined) {
PlatformApi.request(json.id, json.method, json.params);
} else {
PlatformApi.notify(json.method, json.params);
let params = json.params;
// TODO: Check if json.params is an array and if so, convert to a key-value object
// This is necessary because for Ripple, if params is an array this means that
// the callback function is expected to have one argument - the array itself.
// This is not compliant with the JSON-RPC specification, i.e. it should be removed.
if (Array.isArray(params)) {
params = { "value": json.params };
}
PlatformApi.notify(json.method, params);
}
} else if (json.id !== undefined) {
AppApi.response(json.id, json.result, json.error);
Expand Down
12 changes: 5 additions & 7 deletions languages/javascript/src/shared/Transport/MockTransport.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,14 @@ function receive(_callback) {
}
}

function event(module, event, value) {
function event(module, event, data) {
callback(JSON.stringify({
jsonrpc: '2.0',
method: `${module}.${event}`,
params: [
{
name: 'value',
value: value
}
]
params:
{
value: data
}
}))
}

Expand Down
15 changes: 13 additions & 2 deletions test_sdk/suite/properties.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,23 @@ test('Basic Property get', () => {

test('Basic Property subscribe', () => {
let p = Simple.plainProperty(value => {
expect(value.value).toBe("value 123")
expect(value).toBe("value 123")
Simple.clear();
})
MockTransport.event("Simple","onPlainPropertyChanged", "value 123");
return p;
});

// This is to test the patch in Bidirectional gateway that handles event payloads that are arrays
test('Test event payload and array should be handled as a single argument array', () => {
let p = Simple.plainProperty(value => {
expect(Array.isArray(value)).toBe(true)
Simple.clear();
})
MockTransport.event("Simple","onPlainPropertyChanged", [1,2,3]);
return p;
});

test('Basic Property set', () => {
Simple.plainProperty({
foo: 'a new foo!'
Expand All @@ -94,7 +105,7 @@ test('Basic Property set with null', () => {
test('Basic Property subscribe to event', () => {
Simple.clear("onPlainPropertyChanged");
let p = Simple.listen("onPlainPropertyChanged", value => {
expect(value.value).toBe( "value 123")
expect(value).toBe( "value 123")
})
MockTransport.event("Simple","onPlainPropertyChanged", "value 123");
return p;
Expand Down
Loading