From 4e644b2157a851dfb2c2f3f7e55049981f7aedc2 Mon Sep 17 00:00:00 2001 From: Kevin Pearson Date: Tue, 7 Nov 2023 22:19:35 -0800 Subject: [PATCH] fix: Provider openrpc response and error methods have a wrapper object --- test/openrpc/simple.json | 55 +++++++++++++++++++++++++++++++++++++++ test/suite/simple.test.js | 42 +++++++++++++++++++++++++++++- 2 files changed, 96 insertions(+), 1 deletion(-) diff --git a/test/openrpc/simple.json b/test/openrpc/simple.json index 0d7f41c7..7d009546 100644 --- a/test/openrpc/simple.json +++ b/test/openrpc/simple.json @@ -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": { diff --git a/test/suite/simple.test.js b/test/suite/simple.test.js index e9ca5fd7..971bc48e 100644 --- a/test/suite/simple.test.js +++ b/test/suite/simple.test.js @@ -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)) +});