diff --git a/test_sdk/openrpc/advanced.json b/test_sdk/openrpc/event-extension.json similarity index 64% rename from test_sdk/openrpc/advanced.json rename to test_sdk/openrpc/event-extension.json index 317807e9..e836af9c 100644 --- a/test_sdk/openrpc/advanced.json +++ b/test_sdk/openrpc/event-extension.json @@ -1,13 +1,13 @@ { "openrpc": "1.2.4", "info": { - "title": "Advanced", - "description": "Module for testing advanced firebolt-openrpc features", + "title": "EventExtension", + "description": "Module for testing firebolt-openrpc event extension.", "version": "0.0.0" }, "methods": [ { - "name": "onPlainEvent", + "name": "onBasicEvent", "tags": [ { "name": "notifier" @@ -156,7 +156,7 @@ ] } ] - }, + }, { "name": "onEventWithContext", "tags": [ @@ -212,7 +212,7 @@ ] }, { - "name": "onEventWithTwoContext", + "name": "onEventWithTwoContextParams", "tags": [ { "name": "notifier", @@ -274,145 +274,9 @@ ] } ] - }, - { - "name": "propertyWithContext", - "summary": "", - "tags": [ - { - "name": "property" - }, - { - "name": "capabilities", - "x-uses": [ - "xrn:firebolt:capability:test:test" - ] - } - ], - "params": [ - { - "name": "appId", - "required": true, - "schema": { - "type": "string" - } - } - ], - "result": { - "name": "value", - "schema": { - "type": "boolean" - } - }, - "examples": [ - { - "name": "Get the property for hulu", - "params": [ - { - "name": "appId", - "value": "hulu" - } - ], - "result": { - "name": "value", - "value": false - } - }, - { - "name": "Get the property for peacock", - "params": [ - { - "name": "appId", - "value": "peacock" - } - ], - "result": { - "name": "value", - "value": true - } - } - ] - }, - { - "name": "action", - "summary": "A method that takes an Advanced object.", - "tags": [ - { - "name": "capabilities", - "x-uses": [ - "xrn:firebolt:capability:test:test" - ] - } - ], - "description": "A method for testing advanced method generation.", - "params": [ - { - "name": "advanced", - "required": true, - "schema": { - "$ref": "#/components/schemas/Advanced" - }, - "summary": "A test parameter." - } - ], - "result": { - "name": "result", - "summary": "A result for testing basic method generation.", - "schema": { - "type": "object", - "required": [ - "foo" - ], - "properties": { - "foo": { - "type": "string", - "description": "A required field in the result." - }, - "bar": { - "type": "number", - "description": "An optional field in the result." - } - }, - "additionalProperties": false - } - }, - "examples": [ - { - "name": "Default Example", - "params": [ - { - "name": "advanced", - "value": { - "aString": "Here's a string", - "aNumber": 123 - } - } - ], - "result": { - "name": "Default Result", - "value": { - "foo": "here's foo", - "bar": 1 - } - } - } - ] } ], "components": { - "schemas": { - "Advanced": { - "title": "Advanced", - "type": "object", - "properties": { - "aString": { - "type": "string" - }, - "aNumber": { - "type": "number" - } - } - } - } + "schemas": {} } } \ No newline at end of file diff --git a/test_sdk/openrpc/property-extension.json b/test_sdk/openrpc/property-extension.json new file mode 100644 index 00000000..f31084af --- /dev/null +++ b/test_sdk/openrpc/property-extension.json @@ -0,0 +1,331 @@ +{ + "openrpc": "1.2.4", + "info": { + "title": "PropertyExtension", + "description": "Module for testing firebolt-openrpc property extension.", + "version": "0.0.0" + }, + "methods": [ + { + "name": "basicProperty", + "summary": "A property.", + "tags": [ + { + "name": "property" + }, + { + "name": "capabilities", + "x-uses": [ + "xrn:firebolt:capability:test:test" + ] + } + ], + "description": "A property for testing property generation.", + "params": [], + "result": { + "name": "result", + "summary": "A result for testing property generation.", + "schema": { + "type": "object", + "required": [ + "foo" + ], + "properties": { + "foo": { + "type": [ + "string", + "null" + ], + "description": "A required field in the result." + }, + "bar": { + "type": "number", + "description": "An optional field in the result." + } + }, + "additionalProperties": false + } + }, + "examples": [ + { + "name": "Default Example", + "params": [], + "result": { + "name": "Default Result", + "value": { + "foo": "here's foo" + } + } + }, + { + "name": "Another Example", + "params": [], + "result": { + "name": "Another Result", + "value": { + "foo": "here's bar" + } + } + }, + { + "name": "Example to set null value", + "params": [], + "result": { + "name": "Another Result", + "value": { + "foo": null + } + } + } + ] + }, + { + "name": "readOnlyProperty", + "summary": "Get the property readonly", + "params": [], + "tags": [ + { + "name": "property:readonly" + }, + { + "name": "capabilities", + "x-uses": [ + "xrn:firebolt:capability:test:test" + ] + } + ], + "result": { + "name": "read_only_property", + "summary": "the read only property", + "schema": { + "type": "boolean" + } + }, + "examples": [ + { + "name": "Default Example", + "params": [], + "result": { + "name": "Default Result", + "value": true + } + } + ] + }, + { + "name": "propertyWithContext", + "summary": "", + "tags": [ + { + "name": "property" + }, + { + "name": "capabilities", + "x-uses": [ + "xrn:firebolt:capability:test:test" + ] + } + ], + "params": [ + { + "name": "appId", + "required": true, + "schema": { + "type": "string" + } + } + ], + "result": { + "name": "value", + "schema": { + "type": "boolean" + } + }, + "examples": [ + { + "name": "Get the property for hulu", + "params": [ + { + "name": "appId", + "value": "hulu" + } + ], + "result": { + "name": "value", + "value": false + } + }, + { + "name": "Get the property for peacock", + "params": [ + { + "name": "appId", + "value": "peacock" + } + ], + "result": { + "name": "value", + "value": true + } + } + ] + }, + { + "name": "propertyWithNotifierParamsFlattened", + "summary": "A property.", + "tags": [ + { + "name": "property", + "x-notifier-params-flattening": true + }, + { + "name": "capabilities", + "x-uses": [ + "xrn:firebolt:capability:test:test" + ] + } + ], + "description": "A property for testing basic property generation.", + "params": [], + "result": { + "name": "result", + "summary": "A result for testing basic method generation.", + "schema": { + "type": "object", + "required": [ + "foo" + ], + "properties": { + "foo": { + "type": [ + "string", + "null" + ], + "description": "A required field in the result." + }, + "bar": { + "type": "number", + "description": "An optional field in the result." + } + }, + "additionalProperties": false + } + }, + "examples": [ + { + "name": "Default Example", + "params": [], + "result": { + "name": "Default Result", + "value": { + "foo": "here's foo", + "bar": 42 + } + } + }, + { + "name": "Another Example", + "params": [], + "result": { + "name": "Another Result", + "value": { + "foo": "here's foo2", + "bar": 84 + } + } + }, + { + "name": "Example to set null value", + "params": [], + "result": { + "name": "Another Result", + "value": { + "foo": null, + "bar": 0 + } + } + } + ] + }, + { + "name": "propertyWithSetterParamsFlattened", + "summary": "A property.", + "tags": [ + { + "name": "property", + "x-setter-params-flattening": true + }, + { + "name": "capabilities", + "x-uses": [ + "xrn:firebolt:capability:test:test" + ] + } + ], + "description": "A property for testing basic property generation.", + "params": [], + "result": { + "name": "result", + "summary": "A result for testing basic method generation.", + "schema": { + "type": "object", + "required": [ + "foo" + ], + "properties": { + "foo": { + "type": [ + "string", + "null" + ], + "description": "A required field in the result." + }, + "bar": { + "type": "number", + "description": "An optional field in the result." + } + }, + "additionalProperties": false + } + }, + "examples": [ + { + "name": "Default Example", + "params": [], + "result": { + "name": "Default Result", + "value": { + "foo": "here's foo", + "bar": 42 + } + } + }, + { + "name": "Another Example", + "params": [], + "result": { + "name": "Another Result", + "value": { + "foo": "here's bar", + "bar": 84 + } + } + }, + { + "name": "Example to set null value", + "params": [], + "result": { + "name": "Another Result", + "value": { + "foo": null, + "bar": 0 + } + } + } + ] + } + ], + "components": { + "schemas": {} + } +} \ No newline at end of file diff --git a/test_sdk/openrpc/provider.json b/test_sdk/openrpc/provider.json index 3b3e2187..f4d67a76 100644 --- a/test_sdk/openrpc/provider.json +++ b/test_sdk/openrpc/provider.json @@ -7,7 +7,7 @@ }, "methods": [ { - "name": "requestSimpleMethod", + "name": "requestBasicMethod", "tags": [ { "name": "capabilities", diff --git a/test_sdk/openrpc/simple.json b/test_sdk/openrpc/simple.json index b881bb28..a8a2ce3b 100644 --- a/test_sdk/openrpc/simple.json +++ b/test_sdk/openrpc/simple.json @@ -7,7 +7,7 @@ }, "methods": [ { - "name": "method", + "name": "testBasicMethod", "summary": "A method.", "tags": [ { @@ -17,7 +17,7 @@ ] } ], - "description": "A method for testing basic method generation.", + "description": "Validates basic method generation with a single boolean parameter and a simple object result.", "params": [ { "name": "parameter", @@ -68,269 +68,7 @@ ] }, { - "name": "plainProperty", - "summary": "A property.", - "tags": [ - { - "name": "property" - }, - { - "name": "capabilities", - "x-uses": [ - "xrn:firebolt:capability:test:test" - ] - } - ], - "description": "A property for testing basic property generation.", - "params": [], - "result": { - "name": "result", - "summary": "A result for testing basic method generation.", - "schema": { - "type": "object", - "required": [ - "foo" - ], - "properties": { - "foo": { - "type": [ - "string", - "null" - ], - "description": "A required field in the result." - }, - "bar": { - "type": "number", - "description": "An optional field in the result." - } - }, - "additionalProperties": false - } - }, - "examples": [ - { - "name": "Default Example", - "params": [], - "result": { - "name": "Default Result", - "value": { - "foo": "here's foo" - } - } - }, - { - "name": "Another Example", - "params": [], - "result": { - "name": "Another Result", - "value": { - "foo": "here's bar" - } - } - }, - { - "name": "Example to set null value", - "params": [], - "result": { - "name": "Another Result", - "value": { - "foo": null - } - } - } - ] - }, - { - "name": "propertyWithNotifierParamsFlattening", - "summary": "A property.", - "tags": [ - { - "name": "property", - "x-notifier-params-flattening": true - }, - { - "name": "capabilities", - "x-uses": [ - "xrn:firebolt:capability:test:test" - ] - } - ], - "description": "A property for testing basic property generation.", - "params": [], - "result": { - "name": "result", - "summary": "A result for testing basic method generation.", - "schema": { - "type": "object", - "required": [ - "foo" - ], - "properties": { - "foo": { - "type": [ - "string", - "null" - ], - "description": "A required field in the result." - }, - "bar": { - "type": "number", - "description": "An optional field in the result." - } - }, - "additionalProperties": false - } - }, - "examples": [ - { - "name": "Default Example", - "params": [], - "result": { - "name": "Default Result", - "value": { - "foo": "here's foo", - "bar": 42 - } - } - }, - { - "name": "Another Example", - "params": [], - "result": { - "name": "Another Result", - "value": { - "foo": "here's foo2", - "bar": 84 - - } - } - }, - { - "name": "Example to set null value", - "params": [], - "result": { - "name": "Another Result", - "value": { - "foo": null, - "bar": 0 - } - } - } - ] - }, - { - "name": "propertyWithSetterParamsFlattening", - "summary": "A property.", - "tags": [ - { - "name": "property", - "x-setter-params-flattening": true - }, - { - "name": "capabilities", - "x-uses": [ - "xrn:firebolt:capability:test:test" - ] - } - ], - "description": "A property for testing basic property generation.", - "params": [], - "result": { - "name": "result", - "summary": "A result for testing basic method generation.", - "schema": { - "type": "object", - "required": [ - "foo" - ], - "properties": { - "foo": { - "type": [ - "string", - "null" - ], - "description": "A required field in the result." - }, - "bar": { - "type": "number", - "description": "An optional field in the result." - } - }, - "additionalProperties": false - } - }, - "examples": [ - { - "name": "Default Example", - "params": [], - "result": { - "name": "Default Result", - "value": { - "foo": "here's foo", - "bar": 42 - } - } - }, - { - "name": "Another Example", - "params": [], - "result": { - "name": "Another Result", - "value": { - "foo": "here's bar", - "bar": 84 - } - } - }, - { - "name": "Example to set null value", - "params": [], - "result": { - "name": "Another Result", - "value": { - "foo": null, - "bar": 0 - } - } - } - ] - }, - { - "name": "readonlyProperty", - "summary": "Get the property readonly", - "params": [], - "tags": [ - { - "name": "property:readonly" - }, - { - "name": "capabilities", - "x-uses": [ - "xrn:firebolt:capability:test:test" - ] - } - ], - "result": { - "name": "read_only_property", - "summary": "the read only property", - "schema": { - "type": "boolean" - } - }, - "examples": [ - { - "name": "Default Example", - "params": [], - "result": { - "name": "Default Result", - "value": true - } - } - ] - }, - - { - "name": "methodWithMarkdownDescription", + "name": "testMarkdownDescription", "summary": "A method that pulls it's description from an external markdown file.", "description": { "$ref": "file:../descriptions/modules/Simple/methodWithMarkdownDescription.md" @@ -393,56 +131,9 @@ ] }, { - "name": "methodWithSchema", - "summary": "A method using a schema.", - "description": "A method for testing schema-dependent method generation.", - "tags": [ - { - "name": "capabilities", - "x-uses": [ - "xrn:firebolt:capability:test:test" - ] - } - ], - "params": [ - { - "name": "title", - "required": true, - "schema": { - "$ref": "https://meta.comcast.com/firebolt/types#/definitions/LocalizedString" - }, - "summary": "A localized string test parameter." - } - ], - "result": { - "name": "result", - "summary": "A result for testing basic method generation.", - "schema": { - "$ref": "https://meta.comcast.com/firebolt/types#/definitions/LocalizedString" - } - }, - "examples": [ - { - "name": "Default Example", - "params": [ - { - "name": "title", - "value": "test" - } - ], - "result": { - "name": "Default Result", - "value": { - "foo": "here's foo" - } - } - } - ] - }, - { - "name": "methodWithMultipleParams", - "summary": "A method that takes two parameters", - "description": "A method that takes two parameters", + "name": "testMultipleRequiredParams", + "summary": "Validates handling of multiple required parameters.", + "description": "Validates handling of multiple required parameters of different primitive types (number and string)", "tags": [ { "name": "capabilities", @@ -497,9 +188,9 @@ ] }, { - "name": "methodWithOneOptionalParam", - "summary": "A method that takes two parameters with one optional", - "description": "A method that takes two parameters with one optional", + "name": "testSingleOptionalParam", + "summary": "Test single optional parameter.", + "description": "Validates a method where the only provided parameter is marked as optional.", "tags": [ { "name": "capabilities", @@ -542,9 +233,9 @@ ] }, { - "name": "methodWithOneRequiredOneOptionalParam", - "summary": "A method that takes two parameters with one optional", - "description": "A method that takes two parameters with one optional", + "name": "testMixedOptionalityParams", + "summary": "Test required and optional parameters.", + "description": "Validates parameter ordering and validation when a required parameter is followed by an optional one.", "tags": [ { "name": "capabilities", @@ -595,7 +286,7 @@ ] }, { - "name": "methodWithTwoOptionalParam", + "name": "testMultipleOptionalParams", "summary": "A method that takes three parameters with two optional", "description": "A method that takes three parameters with two optional", "tags": [ @@ -660,9 +351,9 @@ ] }, { - "name": "methodWithTwoOptionalParamInWrongOrder", - "summary": "A method that takes two optional in wrong order - starting with optional then required then optional", - "description": "A method that takes two optional in wrong order - starting with optional then required then optional", + "name": "testMultipleOptionalParamsInWrongOrder", + "summary": "Test parameters with optional and required in wrong order.", + "description": "Test case for non-standard parameter ordering (Optional -> Required -> Optional) to ensure generator robustness.", "tags": [ { "name": "capabilities", @@ -727,9 +418,134 @@ } } ] + }, + { + "name": "testExternalSchemaRef", + "summary": "A method using an external schema.", + "description": "Validates resolution of external schema definitions (via URI) for both parameters and results.", + "tags": [ + { + "name": "capabilities", + "x-uses": [ + "xrn:firebolt:capability:test:test" + ] + } + ], + "params": [ + { + "name": "title", + "required": true, + "schema": { + "$ref": "https://meta.comcast.com/firebolt/types#/definitions/LocalizedString" + }, + "summary": "A localized string test parameter." + } + ], + "result": { + "name": "result", + "summary": "A result for testing basic method generation.", + "schema": { + "$ref": "https://meta.comcast.com/firebolt/types#/definitions/LocalizedString" + } + }, + "examples": [ + { + "name": "Default Example", + "params": [ + { + "name": "title", + "value": "test" + } + ], + "result": { + "name": "Default Result", + "value": { + "foo": "here's foo" + } + } + } + ] + }, + { + "name": "testInternalSchemaRef", + "summary": "Validates resolution of local component schemas (via JSON pointer) using a complex object type.", + "tags": [ + { + "name": "capabilities", + "x-uses": [ + "xrn:firebolt:capability:test:test" + ] + } + ], + "description": "A method for testing advanced method generation.", + "params": [ + { + "name": "advanced", + "required": true, + "schema": { + "$ref": "#/components/schemas/Advanced" + }, + "summary": "A test parameter." + } + ], + "result": { + "name": "result", + "summary": "A result for testing basic method generation.", + "schema": { + "type": "object", + "required": [ + "foo" + ], + "properties": { + "foo": { + "type": "string", + "description": "A required field in the result." + }, + "bar": { + "type": "number", + "description": "An optional field in the result." + } + }, + "additionalProperties": false + } + }, + "examples": [ + { + "name": "Default Example", + "params": [ + { + "name": "advanced", + "value": { + "aString": "Here's a string", + "aNumber": 123 + } + } + ], + "result": { + "name": "Default Result", + "value": { + "foo": "here's foo", + "bar": 1 + } + } + } + ] } ], "components": { - "schemas": {} + "schemas": { + "Advanced": { + "title": "Advanced", + "type": "object", + "properties": { + "aString": { + "type": "string" + }, + "aNumber": { + "type": "number" + } + } + } + } } } \ No newline at end of file diff --git a/test_sdk/sdk/configOverride/languages/javascript/language.config.json b/test_sdk/sdk/configOverride/languages/javascript/language.config.json new file mode 100644 index 00000000..fde1d698 --- /dev/null +++ b/test_sdk/sdk/configOverride/languages/javascript/language.config.json @@ -0,0 +1,3 @@ +{ + "enableListenAndOnceDeclarations": true +} \ No newline at end of file diff --git a/test_sdk/sdk/configOverride/languages/markdown/language.config.json b/test_sdk/sdk/configOverride/languages/markdown/language.config.json new file mode 100644 index 00000000..fde1d698 --- /dev/null +++ b/test_sdk/sdk/configOverride/languages/markdown/language.config.json @@ -0,0 +1,3 @@ +{ + "enableListenAndOnceDeclarations": true +} \ No newline at end of file diff --git a/test_sdk/suite/event-with-context.test.js b/test_sdk/suite/event-with-context.test.js new file mode 100644 index 00000000..1ff11b12 --- /dev/null +++ b/test_sdk/suite/event-with-context.test.js @@ -0,0 +1,65 @@ +/* + * Copyright 2026 Comcast Cable Communications Management, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +import { transport } from '../TransportHarness.js' +import MockTransport from '../../build/sdk/javascript/src/Transport/MockTransport.mjs' +import { EventExtension } from '../../build/sdk/javascript/src/sdk.mjs' + + +import { expect } from '@jest/globals'; + +let contextSentToEvent = false +let bothContextSentToEvent = false + +beforeAll(() => { + + transport.onSend((json) => { + let [module, method] = json.method.split('.') + + //assert that module is EventExtension + expect(module).toBe('EventExtension') + + if (method === "onEventWithContext") { + if (json.params.appId === 'some-app') { + contextSentToEvent = true + } + } + else if (method === "onEventWithTwoContextParams") { + if (json.params.appId === 'some-app' && json.params.state === 'inactive') { + bothContextSentToEvent = true + } + } + }); + + return new Promise((resolve, reject) => { + setTimeout(resolve, 100) + }) +}) + + +test('Event with single context param', () => { + EventExtension.listen("onEventWithContext", "some-app", (data) => { + expect(contextSentToEvent).toBe(true) + }) +}) + +test('Event with two context params', () => { + EventExtension.listen("onEventWithTwoContextParams", "some-app", "inactive", (data) => { + expect(bothContextSentToEvent).toBe(true) + }) +}) \ No newline at end of file diff --git a/test_sdk/suite/properties.test.js b/test_sdk/suite/properties.test.js index 8ecb3c0c..f3e846fe 100644 --- a/test_sdk/suite/properties.test.js +++ b/test_sdk/suite/properties.test.js @@ -1,5 +1,5 @@ /* - * Copyright 2021 Comcast Cable Communications Management, LLC + * Copyright 2026 Comcast Cable Communications Management, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,21 +18,20 @@ import { transport } from '../TransportHarness.js' import MockTransport from '../../build/sdk/javascript/src/Transport/MockTransport.mjs' -import { Simple } from '../../build/sdk/javascript/src/sdk.mjs' +import { PropertyExtension } from '../../build/sdk/javascript/src/sdk.mjs' import { expect } from '@jest/globals'; - let propertySetterWasTriggered = false let propertySetterWasTriggeredWithValue = false beforeAll(() => { - transport.onSend ((json) => { + transport.onSend((json) => { let [module, method] = json.method.split('.') - expect(module).toBe('Simple') + expect(module).toBe('PropertyExtension') - if (method === 'plainProperty') { + if (method === 'basicProperty') { /* transport.response(json.id, { foo: "here's foo" @@ -40,12 +39,12 @@ beforeAll(() => { */ MockTransport.receiveMessage(JSON.stringify({ jsonrpc: "2.0", result: { foo: "here's foo" }, id: json.id })) } - else if (method === 'onPlainPropertyChanged') { + else if (method === 'onBasicPropertyChanged') { // Confirm the listener is on MockTransport.receiveMessage(JSON.stringify({ jsonrpc: "2.0", result: { listening: true, event: method }, id: json.id })) } - else if (method === 'setPlainProperty') { + else if (method === 'setBasicProperty') { propertySetterWasTriggered = true if (json.params.value.foo === 'a new foo!' || json.params.value.foo === null) { propertySetterWasTriggeredWithValue = true @@ -60,32 +59,32 @@ beforeAll(() => { test('Basic Property get', () => { - return Simple.plainProperty().then(result => { + return PropertyExtension.basicProperty().then(result => { expect(result.foo).toBe("here's foo") }) }); test('Basic Property subscribe', () => { - let p = Simple.plainProperty(value => { + let p = PropertyExtension.basicProperty(value => { expect(value).toBe("value 123") - Simple.clear(); + PropertyExtension.clear(); }) - MockTransport.event("Simple","onPlainPropertyChanged", "value 123"); + MockTransport.event("PropertyExtension", "onBasicPropertyChanged", "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 => { + let p = PropertyExtension.basicProperty(value => { expect(Array.isArray(value)).toBe(true) - Simple.clear(); + PropertyExtension.clear(); }) - MockTransport.event("Simple","onPlainPropertyChanged", [1,2,3]); + MockTransport.event("PropertyExtension", "onBasicPropertyChanged", [1, 2, 3]); return p; }); test('Basic Property set', () => { - Simple.plainProperty({ + PropertyExtension.basicProperty({ foo: 'a new foo!' }) @@ -94,19 +93,19 @@ test('Basic Property set', () => { }); test('Basic Property set with null', () => { - Simple.plainProperty({ + PropertyExtension.basicProperty({ foo: null }) expect(propertySetterWasTriggered).toBe(true) expect(propertySetterWasTriggeredWithValue).toBe(true) }); -//test listen to "onPlainPropertyChanged" event +//test listen to "onBasicPropertyChanged" event test('Basic Property subscribe to event', () => { - Simple.clear("onPlainPropertyChanged"); - let p = Simple.listen("onPlainPropertyChanged", value => { - expect(value).toBe( "value 123") + PropertyExtension.clear("onBasicPropertyChanged"); + let p = PropertyExtension.listen("onBasicPropertyChanged", value => { + expect(value).toBe("value 123") }) - MockTransport.event("Simple","onPlainPropertyChanged", "value 123"); + MockTransport.event("PropertyExtension", "onBasicPropertyChanged", "value 123"); return p; }); \ No newline at end of file diff --git a/test_sdk/suite/properties-context.test.js b/test_sdk/suite/property-with-context.test.js similarity index 70% rename from test_sdk/suite/properties-context.test.js rename to test_sdk/suite/property-with-context.test.js index 17583e19..38faec43 100644 --- a/test_sdk/suite/properties-context.test.js +++ b/test_sdk/suite/property-with-context.test.js @@ -1,5 +1,5 @@ /* - * Copyright 2021 Comcast Cable Communications Management, LLC + * Copyright 2026 Comcast Cable Communications Management, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,7 @@ import { transport } from '../TransportHarness.js' import MockTransport from '../../build/sdk/javascript/src/Transport/MockTransport.mjs' -import { Advanced } from '../../build/sdk/javascript/src/sdk.mjs' +import { PropertyExtension } from '../../build/sdk/javascript/src/sdk.mjs' import { expect } from '@jest/globals'; @@ -28,16 +28,14 @@ let propertySetterWasTriggeredWithValue = false let contextSentToGetter = false let contextSentToSetter = false let contextSentToSubscriber = false -let contextSentToEvent = false -let bothContextSentToEvent = false beforeAll(() => { - transport.onSend ((json) => { + transport.onSend((json) => { let [module, method] = json.method.split('.') - //assert that module is Advanced - expect(module).toBe('Advanced') + //assert that module is PropertyExtension + expect(module).toBe('PropertyExtension') if (method === 'propertyWithContext') { if (json.params.appId === 'some-app') { @@ -74,19 +72,9 @@ beforeAll(() => { propertySetterWasTriggeredWithValue = true } } - else if (method === "onEventWithContext") { - if (json.params.appId === 'some-app') { - contextSentToEvent = true - } - } - else if (method === "onEventWithTwoContext") { - if (json.params.appId === 'some-app' && json.params.state === 'inactive') { - bothContextSentToEvent = true - } - } }); - Advanced.propertyWithContext('some-app', true) + PropertyExtension.propertyWithContext('some-app', true) return new Promise((resolve, reject) => { setTimeout(resolve, 100) @@ -94,14 +82,14 @@ beforeAll(() => { }) test('Context Property get', () => { - return Advanced.propertyWithContext("some-app").then(result => { + return PropertyExtension.propertyWithContext("some-app").then(result => { expect(result).toBe(true) expect(contextSentToGetter).toBe(true) }) }); test('Context Property subscribe', () => { - return Advanced.propertyWithContext("some-app", value => { + return PropertyExtension.propertyWithContext("some-app", value => { expect(value).toBe(false) expect(contextSentToSubscriber).toBe(true) }) @@ -111,16 +99,4 @@ test('Context Property set', () => { expect(propertySetterWasTriggered).toBe(true) expect(propertySetterWasTriggeredWithValue).toBe(true) expect(contextSentToSetter).toBe(true) -}); - -test('Event with single context param', () => { - Advanced.listen("onEventWithContext", "some-app", (data) => { - expect(contextSentToEvent).toBe(true) - }) -}) - -test('Event with two context params', () => { - Advanced.listen("onEventWithTwoContext", "some-app", "inactive", (data) => { - expect(bothContextSentToEvent).toBe(true) - }) -}) \ No newline at end of file +}); \ No newline at end of file diff --git a/test_sdk/suite/provider-errors.test.js b/test_sdk/suite/provider-errors.test.js index 9d508b5e..e66f60fc 100644 --- a/test_sdk/suite/provider-errors.test.js +++ b/test_sdk/suite/provider-errors.test.js @@ -1,5 +1,5 @@ /* - * Copyright 2021 Comcast Cable Communications Management, LLC + * Copyright 2026 Comcast Cable Communications Management, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,7 +47,7 @@ beforeAll(() => { }) class SimpleProvider { - requestSimpleMethod(...args) { + requestBasicMethod(...args) { providerMethodRequestReceived = true throw { @@ -62,7 +62,7 @@ beforeAll(() => { Provider.provide(new SimpleProvider()) //call the provider method to trigger the error - MockTransport.receiveMessage(JSON.stringify({ jsonrpc: "2.0", method: "Provider.requestSimpleMethod", id: 1 })) + MockTransport.receiveMessage(JSON.stringify({ jsonrpc: "2.0", method: "Provider.requestBasicMethod", id: 1 })) return new Promise((resolve, reject) => { setTimeout(resolve, 100) diff --git a/test_sdk/suite/provider.with-multiple-methods.test.js b/test_sdk/suite/provider.with-multiple-methods.test.js index 273c5591..975f52dd 100644 --- a/test_sdk/suite/provider.with-multiple-methods.test.js +++ b/test_sdk/suite/provider.with-multiple-methods.test.js @@ -1,8 +1,5 @@ /* - * If not stated otherwise in this file or this component's LICENSE file the - * following copyright and licenses apply: - * - * Copyright 2025 Sky UK + * Copyright 2026 Comcast Cable Communications Management, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/test_sdk/suite/simple.test.js b/test_sdk/suite/simple.test.js index 86cf993f..2e2a374b 100644 --- a/test_sdk/suite/simple.test.js +++ b/test_sdk/suite/simple.test.js @@ -15,6 +15,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ + import { transport } from '../TransportHarness.js' import MockTransport from '../../build/sdk/javascript/src/Transport/MockTransport.mjs' import { Simple } from '../../build/sdk/javascript/src/sdk.mjs' @@ -33,7 +34,7 @@ beforeAll(() => { MockTransport.receiveMessage(JSON.stringify({ jsonrpc: "2.0", result: { foo: "here's foo", value: 5 }, id: json.id })) //}) } - else if (method === 'methodWithMultipleParams') { + else if (method === 'testMultipleRequiredParams') { //setTimeout( _ => { MockTransport.receiveMessage(JSON.stringify({ jsonrpc: "2.0", result: true, id: json.id })) @@ -48,13 +49,13 @@ beforeAll(() => { }) test('Basic', () => { - return Simple.method(true).then(result => { + return Simple.testBasicMethod(true).then(result => { expect(result.foo).toBe("here's foo") }) }); test('Calls method with required parameter and validates payload', async () => { - return Simple.methodWithMultipleParams(5, 'foo').then(result => { + return Simple.testMultipleRequiredParams(5, 'foo').then(result => { expect(result).toBe(true) }) @@ -66,11 +67,11 @@ test('Handles method call with no optional parameter provided', async () => { let [module, method] = json.method.split('.') expect(module).toBe('Simple') - expect(method).toBe('methodWithOneOptionalParam') + expect(method).toBe('testSingleOptionalParam') expect(Object.keys(json.params).length).toBe(0) MockTransport.receiveMessage(JSON.stringify({ jsonrpc: "2.0", result: {}, id: json.id })) }) - Simple.methodWithOneOptionalParam() + Simple.testSingleOptionalParam() }); @@ -80,11 +81,11 @@ test('Handles method call with optional parameter provided', async () => { let [module, method] = json.method.split('.') expect(module).toBe('Simple') - expect(method).toBe('methodWithOneOptionalParam') + expect(method).toBe('testSingleOptionalParam') expect(json.params.param1).toBe('foo') MockTransport.receiveMessage(JSON.stringify({ jsonrpc: "2.0", result: {}, id: json.id })) }) - Simple.methodWithOneOptionalParam('foo') + Simple.testSingleOptionalParam('foo') }); test('Handles method call with optional parameter explicitly set to null', async () => { @@ -93,11 +94,11 @@ test('Handles method call with optional parameter explicitly set to null', async let [module, method] = json.method.split('.') expect(module).toBe('Simple') - expect(method).toBe('methodWithOneOptionalParam') + expect(method).toBe('testSingleOptionalParam') expect(Object.keys(json.params).length).toBe(0) MockTransport.receiveMessage(JSON.stringify({ jsonrpc: "2.0", result: {}, id: json.id })) }) - Simple.methodWithOneOptionalParam(null) + Simple.testSingleOptionalParam(null) }); test('Handles method with one required parameter, optional parameter omitted', async () => { @@ -106,11 +107,11 @@ test('Handles method with one required parameter, optional parameter omitted', a let [module, method] = json.method.split('.') expect(module).toBe('Simple') - expect(method).toBe('methodWithOneRequiredOneOptionalParam') + expect(method).toBe('testMixedOptionalityParams') expect(Object.keys(json.params).length).toBe(1) MockTransport.receiveMessage(JSON.stringify({ jsonrpc: "2.0", result: {}, id: json.id })) }) - Simple.methodWithOneRequiredOneOptionalParam("foo") + Simple.testMixedOptionalityParams("foo") }); test('Handles method with one required parameter, optional parameter set to null', async () => { @@ -119,12 +120,12 @@ test('Handles method with one required parameter, optional parameter set to null let [module, method] = json.method.split('.') expect(module).toBe('Simple') - expect(method).toBe('methodWithOneRequiredOneOptionalParam') + expect(method).toBe('testMixedOptionalityParams') expect(json.params.param1).toBe('foo') expect(Object.keys(json.params).length).toBe(1) MockTransport.receiveMessage(JSON.stringify({ jsonrpc: "2.0", result: {}, id: json.id })) }) - Simple.methodWithOneRequiredOneOptionalParam('foo', null) + Simple.testMixedOptionalityParams('foo', null) }); test('Handles method with both required and optional parameters set to null', async () => { @@ -133,12 +134,12 @@ test('Handles method with both required and optional parameters set to null', as let [module, method] = json.method.split('.') expect(module).toBe('Simple') - expect(method).toBe('methodWithOneRequiredOneOptionalParam') + expect(method).toBe('testMixedOptionalityParams') expect(json.params.param1).toBe(null) expect(Object.keys(json.params).length).toBe(1) MockTransport.receiveMessage(JSON.stringify({ jsonrpc: "2.0", result: {}, id: json.id })) }) - Simple.methodWithOneRequiredOneOptionalParam(null, null) + Simple.testMixedOptionalityParams(null, null) }); test('Handles method call with both required and optional parameters provided', async () => { @@ -147,13 +148,13 @@ test('Handles method call with both required and optional parameters provided', let [module, method] = json.method.split('.') expect(module).toBe('Simple') - expect(method).toBe('methodWithOneRequiredOneOptionalParam') + expect(method).toBe('testMixedOptionalityParams') expect(json.params.param1).toBe('foo') expect(json.params.param2).toBe('bar') expect(Object.keys(json.params).length).toBe(2) MockTransport.receiveMessage(JSON.stringify({ jsonrpc: "2.0", result: {}, id: json.id })) }) - Simple.methodWithOneRequiredOneOptionalParam('foo', 'bar') + Simple.testMixedOptionalityParams('foo', 'bar') }); test('Handles method with two optional parameters: only required provided', async () => { @@ -162,12 +163,12 @@ test('Handles method with two optional parameters: only required provided', asyn let [module, method] = json.method.split('.') expect(module).toBe('Simple') - expect(method).toBe('methodWithTwoOptionalParam') + expect(method).toBe('testMultipleOptionalParams') expect(json.params.param1).toBe('foo') expect(Object.keys(json.params).length).toBe(1) MockTransport.receiveMessage(JSON.stringify({ jsonrpc: "2.0", result: {}, id: json.id })) }) - Simple.methodWithTwoOptionalParam("foo") + Simple.testMultipleOptionalParams("foo") }); test('Handles method with two optional parameters: first optional param set to null', async () => { @@ -176,12 +177,12 @@ test('Handles method with two optional parameters: first optional param set to n let [module, method] = json.method.split('.') expect(module).toBe('Simple') - expect(method).toBe('methodWithTwoOptionalParam') + expect(method).toBe('testMultipleOptionalParams') expect(json.params.param1).toBe('foo') expect(Object.keys(json.params).length).toBe(1) MockTransport.receiveMessage(JSON.stringify({ jsonrpc: "2.0", result: {}, id: json.id })) }) - Simple.methodWithTwoOptionalParam('foo', null) + Simple.testMultipleOptionalParams('foo', null) }); test('Handles method with two optional parameters: both set to null', async () => { @@ -190,12 +191,12 @@ test('Handles method with two optional parameters: both set to null', async () = let [module, method] = json.method.split('.') expect(module).toBe('Simple') - expect(method).toBe('methodWithTwoOptionalParam') + expect(method).toBe('testMultipleOptionalParams') expect(json.params.param1).toBe('foo') expect(Object.keys(json.params).length).toBe(1) MockTransport.receiveMessage(JSON.stringify({ jsonrpc: "2.0", result: {}, id: json.id })) }) - Simple.methodWithTwoOptionalParam('foo', null, null) + Simple.testMultipleOptionalParams('foo', null, null) }); test('Handles method with two optional parameters: first provided, second not', async () => { @@ -204,13 +205,13 @@ test('Handles method with two optional parameters: first provided, second not', let [module, method] = json.method.split('.') expect(module).toBe('Simple') - expect(method).toBe('methodWithTwoOptionalParam') + expect(method).toBe('testMultipleOptionalParams') expect(json.params.param1).toBe('foo') expect(json.params.param2).toBe('bar') expect(Object.keys(json.params).length).toBe(2) MockTransport.receiveMessage(JSON.stringify({ jsonrpc: "2.0", result: {}, id: json.id })) }) - Simple.methodWithTwoOptionalParam('foo', 'bar') + Simple.testMultipleOptionalParams('foo', 'bar') }); test('Handles method with two optional parameters: first param set to null, second provided', async () => { @@ -219,14 +220,14 @@ test('Handles method with two optional parameters: first param set to null, seco let [module, method] = json.method.split('.') expect(module).toBe('Simple') - expect(method).toBe('methodWithTwoOptionalParam') + expect(method).toBe('testMultipleOptionalParams') expect(json.params.param1).toBe('foo') expect(json.params.param2).toBe(null) expect(json.params.param3).toBe('bar') expect(Object.keys(json.params).length).toBe(3) MockTransport.receiveMessage(JSON.stringify({ jsonrpc: "2.0", result: {}, id: json.id })) }) - Simple.methodWithTwoOptionalParam('foo', null, "bar") + Simple.testMultipleOptionalParams('foo', null, "bar") }); test('Handles optional parameters in wrong order', async () => { @@ -235,12 +236,12 @@ test('Handles optional parameters in wrong order', async () => { let [module, method] = json.method.split('.') expect(module).toBe('Simple') - expect(method).toBe('methodWithTwoOptionalParamInWrongOrder') + expect(method).toBe('testMultipleOptionalParamsInWrongOrder') expect(json.params.param1).toBe(null) expect(json.params.param2).toBe('foo') expect(json.params.param3).toBe('bar') expect(Object.keys(json.params).length).toBe(3) MockTransport.receiveMessage(JSON.stringify({ jsonrpc: "2.0", result: {}, id: json.id })) }) - Simple.methodWithTwoOptionalParamInWrongOrder(null, 'foo', "bar") + Simple.testMultipleOptionalParamsInWrongOrder(null, 'foo', "bar") }); \ No newline at end of file