import chai from "chai"; import chaiAsPromised from "chai-as-promised"; import { createBearerAuthenticationConfig } from "../utils/config"; import { PromiseRolesApi } 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 PromiseRolesApi(config); describe('RolesApi', function() { describe('createRole', function() { const testReqBodies = requestBodies.filter( (body: any) => body.Metadata.operationId === "createRole" ); 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.createRole( // createRoleRequest CreateRoleRequest test.Body ) } catch (er) { console.error(er, "Response", data) expect(er).to.be.undefined } } else { await expect( instance.createRole( // createRoleRequest CreateRoleRequest test.Body ) ).to.be.rejectedWith(Error); } }); }); }); describe('deleteRole', function() { const testReqBodies = requestBodies.filter( (body: any) => body.Metadata.operationId === "deleteRole" ); 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.deleteRole( // roleIdentifier role_identifier test.Path_Variables.role_identifier ) } catch (er) { console.error(er, "Response", data) expect(er).to.be.undefined } } else { await expect( instance.deleteRole( // roleIdentifier role_identifier test.Path_Variables.role_identifier ) ).to.be.rejectedWith(Error); } }); }); }); describe('searchRoles', function() { const testReqBodies = requestBodies.filter( (body: any) => body.Metadata.operationId === "searchRoles" ); 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.searchRoles( // searchRolesRequest SearchRolesRequest test.Body ) } catch (er) { console.error(er, "Response", data) expect(er).to.be.undefined } } else { await expect( instance.searchRoles( // searchRolesRequest SearchRolesRequest test.Body ) ).to.be.rejectedWith(Error); } }); }); }); describe('updateRole', function() { const testReqBodies = requestBodies.filter( (body: any) => body.Metadata.operationId === "updateRole" ); 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.updateRole( // roleIdentifier role_identifier test.Path_Variables.role_identifier , // updateRoleRequest UpdateRoleRequest test.Body ) } catch (er) { console.error(er, "Response", data) expect(er).to.be.undefined } } else { await expect( instance.updateRole( // roleIdentifier role_identifier test.Path_Variables.role_identifier , // updateRoleRequest UpdateRoleRequest test.Body ) ).to.be.rejectedWith(Error); } }); }); }); });