Skip to content

Commit

Permalink
fix: Provider openrpc response and error methods have a wrapper object
Browse files Browse the repository at this point in the history
  • Loading branch information
kpears201 committed Nov 8, 2023
1 parent 7e70c0b commit 4e644b2
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 1 deletion.
55 changes: 55 additions & 0 deletions test/openrpc/simple.json
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,61 @@
}
}
]
},
{
"name": "methodWithMultipleParams",
"summary": "A method that takes two parameters",
"description": "A method that takes two parameters",
"tags": [
{
"name": "capabilities",
"x-uses": ["xrn:firebolt:capability:test:test"]
}
],
"params": [
{
"name": "id",
"required": true,
"schema": {
"type": "number"
},
"summary": "A test number"
},
{
"name": "title",
"required": true,
"schema": {
"type": "string"
},
"summary": "A string test parameter."
}
],
"result": {
"name": "result",
"summary": "A result for testing basic method generation.",
"schema": {
"type": "null"
}
},
"examples": [
{
"name": "Default Example",
"params": [
{
"name": "id",
"value": 42
},
{
"name": "title",
"value": "test"
}
],
"result": {
"name": "Default Result",
"value": null
}
}
]
}
],
"components": {
Expand Down
42 changes: 41 additions & 1 deletion test/suite/simple.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,51 @@
*/

import { Simple } from '../../build/sdk/javascript/src/sdk.mjs'
import Setup from '../Setup'
import { expect } from '@jest/globals';

let state = {
spy: null,
responder: null
}

class TransportSpy {

constructor(spy) {
state.spy = spy
}

async send(msg) {
let parsed = JSON.parse(msg)
console.log(state.spy)
state.spy(parsed)
this.responder(JSON.stringify({
jsonrpc: '2.0',
id: parsed.id,
result: {}
}))
}

receive(callback) {
this.responder = callback
}
}

test('Basic', () => {
return Simple.method(true).then(result => {
expect(result.foo).toBe("here's foo")
})
});

test('Multiple Parameters', async () => {
let cb = null;
let promise = new Promise((resolve, reject) => {
cb = resolve
})
window['__firebolt'].setTransportLayer(new TransportSpy(cb))
await Simple.methodWithMultipleParams(5, 'foo')
let msg = await promise
expect(msg.method).toBe('simple.methodWithMultipleParams')
expect(msg.params.id).toBe(5)
expect(msg.params.title).toBe('foo')
console.log(JSON.stringify(msg))
});

0 comments on commit 4e644b2

Please sign in to comment.