import chai from "chai"; import chaiAsPromised from "chai-as-promised"; import { createBearerAuthenticationConfig } from "../utils/config"; import { PromiseCustomActionApi } from "../types/PromiseAPI"; import requestBodies from "./testDataUpdated.json"; chai.use(chaiAsPromised); const expect = chai.expect; const baseUrlFromCli = process.argv.filter(s => s.startsWith("--baseUrl="))?.[0]?.split("=")?.[1] const BASE_URL = baseUrlFromCli || "http://127.0.0.1:4123" const config = createBearerAuthenticationConfig(BASE_URL, { username: "tsadmin", password: "admin", }); const instance = new PromiseCustomActionApi(config); describe('CustomActionApi', function() { describe('createCustomAction', function() { const testReqBodies = requestBodies.filter( (body: any) => body.Metadata.operationId === "createCustomAction" ); testReqBodies.forEach(async (test: any) => { it(`${test.Metadata.operationId} - ${test.Metadata.scenario} : Testid - ${test.Metadata.testId}`, async function () { if (test.Metadata.scenario === "positive") { var data; try { data = await instance.createCustomAction( // createCustomActionRequest CreateCustomActionRequest test.Body ) } catch (er) { console.error(er, "Response", data) expect(er).to.be.undefined } } else { await expect( instance.createCustomAction( // createCustomActionRequest CreateCustomActionRequest test.Body ) ).to.be.rejectedWith(Error); } }); }); }); describe('deleteCustomAction', function() { const testReqBodies = requestBodies.filter( (body: any) => body.Metadata.operationId === "deleteCustomAction" ); testReqBodies.forEach(async (test: any) => { it(`${test.Metadata.operationId} - ${test.Metadata.scenario} : Testid - ${test.Metadata.testId}`, async function () { if (test.Metadata.scenario === "positive") { var data; try { data = await instance.deleteCustomAction( // customActionIdentifier custom_action_identifier test.Path_Variables.custom_action_identifier ) } catch (er) { console.error(er, "Response", data) expect(er).to.be.undefined } } else { await expect( instance.deleteCustomAction( // customActionIdentifier custom_action_identifier test.Path_Variables.custom_action_identifier ) ).to.be.rejectedWith(Error); } }); }); }); describe('searchCustomActions', function() { const testReqBodies = requestBodies.filter( (body: any) => body.Metadata.operationId === "searchCustomActions" ); testReqBodies.forEach(async (test: any) => { it(`${test.Metadata.operationId} - ${test.Metadata.scenario} : Testid - ${test.Metadata.testId}`, async function () { if (test.Metadata.scenario === "positive") { var data; try { data = await instance.searchCustomActions( // searchCustomActionsRequest SearchCustomActionsRequest test.Body ) } catch (er) { console.error(er, "Response", data) expect(er).to.be.undefined } } else { await expect( instance.searchCustomActions( // searchCustomActionsRequest SearchCustomActionsRequest test.Body ) ).to.be.rejectedWith(Error); } }); }); }); describe('updateCustomAction', function() { const testReqBodies = requestBodies.filter( (body: any) => body.Metadata.operationId === "updateCustomAction" ); testReqBodies.forEach(async (test: any) => { it(`${test.Metadata.operationId} - ${test.Metadata.scenario} : Testid - ${test.Metadata.testId}`, async function () { if (test.Metadata.scenario === "positive") { var data; try { data = await instance.updateCustomAction( // customActionIdentifier custom_action_identifier test.Path_Variables.custom_action_identifier , // updateCustomActionRequest UpdateCustomActionRequest test.Body ) } catch (er) { console.error(er, "Response", data) expect(er).to.be.undefined } } else { await expect( instance.updateCustomAction( // customActionIdentifier custom_action_identifier test.Path_Variables.custom_action_identifier , // updateCustomActionRequest UpdateCustomActionRequest test.Body ) ).to.be.rejectedWith(Error); } }); }); }); });