From 4e2a4b54bbb67a84f7f13f61c685b02c0bfa0081 Mon Sep 17 00:00:00 2001 From: Will Barnett Date: Tue, 19 Mar 2024 21:55:24 +0000 Subject: [PATCH] EducationPlatform testing, added test for functionRegistry_call() --- .../test/spec/testEducationPlatfomSpec.js | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/platform/test/spec/testEducationPlatfomSpec.js b/platform/test/spec/testEducationPlatfomSpec.js index 501a41a..cfe3930 100644 --- a/platform/test/spec/testEducationPlatfomSpec.js +++ b/platform/test/spec/testEducationPlatfomSpec.js @@ -6,6 +6,7 @@ export var TOKEN_SERVER_URL = "test://ts.url"; import {EducationPlatform} from"../../src/EducationPlatform.js"; import { ActionFunction } from "../../src/ActionFunction.js"; import { Panel } from "../../src/Panel.js"; +import "jasmine-ajax"; describe("EducationPlatform", () => { @@ -582,6 +583,63 @@ describe("EducationPlatform", () => { }) }) + describe("functionRegistry_call()", () => { + const TOOL_URL = "test://t1.url/toolfunction"; + const TOOL_RESPONSE = '{ "validationResult": "PASS", "output": "Test" }'; + const CONVERSION_FUNCTION_ID = "test-function-id"; + + const PARAMETER_1_NAME = "test-param-1"; + const PARAMETER_2_NAME = "language"; + + const PARAMETERS_INPUT = { + [PARAMETER_1_NAME]: "Parameter 1 value", + [PARAMETER_2_NAME]: "Parameter 2 value" + }; + + let platform; + + + beforeEach(()=>{ + // Setup + jasmine.Ajax.install(); + + platform = new EducationPlatform(); + + jasmine.Ajax.stubRequest(TOOL_URL).andReturn({ + "responseText": TOOL_RESPONSE, + "status": 200 + }); + + // platform - toolsManager + let toolsManagerSpy = jasmine.createSpyObj(['getActionFunction']); + toolsManagerSpy.getActionFunction.and.returnValue(new ActionFunction({ + path: TOOL_URL + })); + platform.toolsManager= toolsManagerSpy; + + }) + + afterEach(function() { + jasmine.Ajax.uninstall(); + }); + + it("returns the result via promise", async () => { + // Call the target object + const functionResponse = platform.functionRegistry_call(CONVERSION_FUNCTION_ID, PARAMETERS_INPUT); + + // Check the expected results + await expectAsync(functionResponse).toBeResolvedTo(TOOL_RESPONSE); + }) + + it("sends a request to the tool service url", async () => { + // Call the target object + platform.functionRegistry_call(CONVERSION_FUNCTION_ID, PARAMETERS_INPUT); + + // Check the expected results + const request = jasmine.Ajax.requests.mostRecent(); + expect(request.data()).toEqual( PARAMETERS_INPUT ); + }) + }) describe("notification", () => {