import chai from "chai"; import chaiAsPromised from "chai-as-promised"; import { createBearerAuthenticationConfig } from "../utils/config"; import { PromiseWebhooksApi } 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 PromiseWebhooksApi(config); describe('WebhooksApi', function() { describe('createWebhookConfiguration', function() { const testReqBodies = requestBodies.filter( (body: any) => body.Metadata.operationId === "createWebhookConfiguration" ); 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.createWebhookConfiguration( // createWebhookConfigurationRequest CreateWebhookConfigurationRequest test.Body ) } catch (er) { console.error(er, "Response", data) expect(er).to.be.undefined } } else { await expect( instance.createWebhookConfiguration( // createWebhookConfigurationRequest CreateWebhookConfigurationRequest test.Body ) ).to.be.rejectedWith(Error); } }); }); }); describe('deleteWebhookConfigurations', function() { const testReqBodies = requestBodies.filter( (body: any) => body.Metadata.operationId === "deleteWebhookConfigurations" ); 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.deleteWebhookConfigurations( // deleteWebhookConfigurationsRequest DeleteWebhookConfigurationsRequest test.Body ) } catch (er) { console.error(er, "Response", data) expect(er).to.be.undefined } } else { await expect( instance.deleteWebhookConfigurations( // deleteWebhookConfigurationsRequest DeleteWebhookConfigurationsRequest test.Body ) ).to.be.rejectedWith(Error); } }); }); }); describe('searchWebhookConfigurations', function() { const testReqBodies = requestBodies.filter( (body: any) => body.Metadata.operationId === "searchWebhookConfigurations" ); 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.searchWebhookConfigurations( // searchWebhookConfigurationsRequest SearchWebhookConfigurationsRequest test.Body ) } catch (er) { console.error(er, "Response", data) expect(er).to.be.undefined } } else { await expect( instance.searchWebhookConfigurations( // searchWebhookConfigurationsRequest SearchWebhookConfigurationsRequest test.Body ) ).to.be.rejectedWith(Error); } }); }); }); describe('updateWebhookConfiguration', function() { const testReqBodies = requestBodies.filter( (body: any) => body.Metadata.operationId === "updateWebhookConfiguration" ); 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.updateWebhookConfiguration( // webhookIdentifier webhook_identifier test.Path_Variables.webhook_identifier , // updateWebhookConfigurationRequest UpdateWebhookConfigurationRequest test.Body ) } catch (er) { console.error(er, "Response", data) expect(er).to.be.undefined } } else { await expect( instance.updateWebhookConfiguration( // webhookIdentifier webhook_identifier test.Path_Variables.webhook_identifier , // updateWebhookConfigurationRequest UpdateWebhookConfigurationRequest test.Body ) ).to.be.rejectedWith(Error); } }); }); }); });