From 7293247a4ba5fb1851134924ec6b57d4f9d774b9 Mon Sep 17 00:00:00 2001 From: Ricardo Gomez_Ulmke Date: Mon, 13 Feb 2023 10:05:44 +0100 Subject: [PATCH 1/5] bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cd78ff971..e3b39533b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@solace-labs/solace-tools-typescript", - "version": "2.9.0", + "version": "2.9.1", "private": true, "workspaces": [ "packages/*" From fd7cd7d9747e2eb138c1461f27bcc7c77b724d8c Mon Sep 17 00:00:00 2001 From: Ricardo Gomez_Ulmke Date: Mon, 13 Feb 2023 13:56:35 +0100 Subject: [PATCH 2/5] ep apim api app registration tests --- packages/ep-apim-openapi-node/package.json | 6 +- .../test/specs/appRegistrations.x-spec.ts | 324 ++++++++++++++++++ packages/tools/package.json | 4 +- packages/tools/src/testLib/TestUtils.ts | 13 +- yarn.lock | 13 + 5 files changed, 350 insertions(+), 10 deletions(-) create mode 100644 packages/ep-apim-openapi-node/test/specs/appRegistrations.x-spec.ts diff --git a/packages/ep-apim-openapi-node/package.json b/packages/ep-apim-openapi-node/package.json index 121cbb4b3..8e43223de 100644 --- a/packages/ep-apim-openapi-node/package.json +++ b/packages/ep-apim-openapi-node/package.json @@ -61,7 +61,7 @@ "@internal/tools": "*", "@rsql/builder": "^1.5.2", "@rsql/emitter": "^1.5.2", - "openapi-typescript-codegen": "^0.19.0", - "@solace-labs/ep-asyncapi": "^0.53.1" + "@solace-labs/ep-asyncapi": "^0.53.1", + "openapi-typescript-codegen": "^0.19.0" } -} \ No newline at end of file +} diff --git a/packages/ep-apim-openapi-node/test/specs/appRegistrations.x-spec.ts b/packages/ep-apim-openapi-node/test/specs/appRegistrations.x-spec.ts new file mode 100644 index 000000000..1fde06198 --- /dev/null +++ b/packages/ep-apim-openapi-node/test/specs/appRegistrations.x-spec.ts @@ -0,0 +1,324 @@ +import 'mocha'; +import { expect } from 'chai'; +import path from 'path'; +import { emit } from '@rsql/emitter'; +import { + TestContext, TestUtils, +} from '@internal/tools/src'; +import { + TestLogger, + TestConfig, + EpSdkRsqlQueryBuilder, +} from '../lib'; +import { + ApiError, + ApplicationRegistrationResponse, + ApplicationRegistrationsResponse, + ApplicationRegistrationView, + Credentials, + CredentialsResponse, + EventApiProduct, + EventApiProductRegistration, + EventApiProductRegistrationResponse, + EventApiProductRegistrationsResponse, + EventApiProductsResponse, + EventApiProductsService, + EventApisResponse, + EventApiVersion, + Plan, + RegistrationsService, +} from '../../generated-src'; +import { TestHelpers } from '../lib/TestHelpers'; + +const scriptName: string = path.basename(__filename); +TestLogger.logMessage(scriptName, ">>> starting ..."); + +// pre-defined in EP +const ApplicationDomainName = "TEST_APIM_API"; +const ApplicationDomainId = "gb2ila1uhoj"; + +const AppRegistrationName_1 = "AppRegistrationName_1"; +const AppRegistrationId_1 = "AppRegistrationId_1"; +const AppRegistrationSource = "AppRegistrationSource"; + +let AutoGeneratedCredentialsConsumerKey: string | undefined; +let ConsumerCreatedCredentialSet_1: Credentials = { + name: "ConsumerCreatedCredentialSet_1", + // expiresAt: -1, + secret: { + consumerKey: "consumerKey", + consumerSecret: "consumerSecret" + } +} +let ConsumerCreatedCredentialSet_2: Credentials = { + name: "ConsumerCreatedCredentialSet_2", + // expiresAt: -1, +} + +// let AppRegistrationId_1: string; + +// const PublishDestiationsAttributeName = 'PUBLISH_DESTINATIONS'; +// const PublishDestinationValue = 'TEST_APIM_API'; +const EventApiProductName_1 = "EventApiProduct_1"; +let EventApiProduct_1: EventApiProduct; + +// const EventApiProductList: Array = []; + + +const initializeGlobals = () => { + // initialize parameterized globals +}; + +describe(`${scriptName}`, () => { + + before(async () => { + TestContext.newItId(); + initializeGlobals(); + // absent the appRegistrations + const xvoid: void = await RegistrationsService.deleteAppRegistration({ + registrationId: AppRegistrationId_1, + }); + }); + + beforeEach(() => { + TestContext.newItId(); + }); + + + it(`${scriptName}: should list app registrations with paging`, async () => { + const PageSize = 1; + try { + const applicationRegistrationViewList: Array = []; + let nextPage: number | null = 1; + while(nextPage !== null) { + const queryAst = EpSdkRsqlQueryBuilder.eq(TestUtils.nameOf("applicationDomainId"), ApplicationDomainId); + const applicationRegistrationsResponse: ApplicationRegistrationsResponse = await RegistrationsService.listAppRegistrations({ + pageSize: PageSize, + pageNumber: nextPage, + query: emit(queryAst) + }); + expect(applicationRegistrationsResponse.data, TestLogger.createApiTestFailMessage('failed')).to.not.be.undefined; + expect(applicationRegistrationsResponse.data.length, TestLogger.createApiTestFailMessage('failed')).to.be.lessThanOrEqual(PageSize); + const meta = applicationRegistrationsResponse.meta; + expect(meta, TestLogger.createApiTestFailMessage('failed')).to.not.be.undefined; + // // DEBUG + // expect(false,TestLogger.createLogMessage('meta', meta)).to.be.true; + // expect(meta.pagination.nextPage,TestLogger.createApiTestFailMessage(TestLogger.createLogMessage('meta', meta))).to.be.greaterThan(0); + nextPage = meta.pagination.nextPage; + if(nextPage === 0) nextPage = null; + applicationRegistrationViewList.push(...applicationRegistrationsResponse.data); + // // DEBUG + // expect(false,TestLogger.createLogMessage('DEBUG: applicationRegistrationsResponse', applicationRegistrationsResponse)).to.be.true; + } + // // DEBUG + // expect(false, TestLogger.createLogMessage('full list', eventApiProductList)).to.be.true; + } catch(e) { + expect(e instanceof ApiError, TestLogger.createNotApiErrorMessage(e.message)).to.be.true; + expect(false, TestLogger.createApiTestFailMessage('failed', e)).to.be.true; + } + }); + + it(`${scriptName}: should create new app registration`, async () => { + try { + const applicationRegistrationResponse: ApplicationRegistrationResponse = await RegistrationsService.createAppRegistration({ + requestBody: { + name: AppRegistrationName_1, + registrationId: AppRegistrationId_1, + source: AppRegistrationSource, + applicationDomainId: ApplicationDomainId, + } + }); + // // DEBUG + // expect(false,TestLogger.createLogMessage('DEBUG: applicationRegistrationResponse', applicationRegistrationResponse)).to.be.true; + // should not have an auto generated credetials set in it + AutoGeneratedCredentialsConsumerKey = applicationRegistrationResponse.data.credentials[0].secret?.consumerKey; + expect(AutoGeneratedCredentialsConsumerKey, 'not defined').to.not.be.undefined; + } catch(e) { + expect(e instanceof ApiError, TestLogger.createNotApiErrorMessage(e.message)).to.be.true; + expect(false, TestLogger.createApiTestFailMessage('failed', e)).to.be.true; + } + }); + + it(`${scriptName}: should remove auto generated credentials`, async () => { + try { + if(AutoGeneratedCredentialsConsumerKey === undefined) throw new Error('CredentialsConsumerKey_1 === undefined'); + const xvoid: void = await RegistrationsService.deleteAppRegistrationCredentials({ + registrationId: AppRegistrationId_1, + consumerKey: AutoGeneratedCredentialsConsumerKey, + }); + // get the app + const applicationRegistrationResponse: ApplicationRegistrationResponse = await RegistrationsService.getAppRegistration({ + registrationId: AppRegistrationId_1, + }); + expect(applicationRegistrationResponse.data.credentials, 'applicationRegistrationResponse.data.credentials').to.not.be.undefined; + // // DEBUG + // expect(false,TestLogger.createLogMessage('DEBUG: applicationRegistrationResponse', applicationRegistrationResponse)).to.be.true; + } catch(e) { + expect(e instanceof ApiError, TestLogger.createNotApiErrorMessage(e.message)).to.be.true; + expect(false, TestLogger.createApiTestFailMessage('failed', e)).to.be.true; + } + }); + + it(`${scriptName}: should create 2 sets of credentials`, async () => { + try { + const credentialsResponse_1: CredentialsResponse = await RegistrationsService.createAppRegistrationCredentials({ + registrationId: AppRegistrationId_1, + requestBody: ConsumerCreatedCredentialSet_1 + }); + ConsumerCreatedCredentialSet_1 = credentialsResponse_1.data; + // // DEBUG + // expect(false,TestLogger.createLogMessage('DEBUG: credentialsResponse_1', credentialsResponse_1)).to.be.true; + const credentialsResponse_2: CredentialsResponse = await RegistrationsService.createAppRegistrationCredentials({ + registrationId: AppRegistrationId_1, + requestBody: { + ...ConsumerCreatedCredentialSet_2, + secret: { + consumerKey: TestUtils.getKey(), + consumerSecret: TestUtils.getKey() + } + } + }); + ConsumerCreatedCredentialSet_2 = credentialsResponse_2.data; + // get the app + const applicationRegistrationResponse: ApplicationRegistrationResponse = await RegistrationsService.getAppRegistration({ + registrationId: AppRegistrationId_1, + }); + expect(applicationRegistrationResponse.data.credentials, 'applicationRegistrationResponse.data.credentials').to.not.be.undefined; + // // DEBUG + // expect(false,TestLogger.createLogMessage('DEBUG: applicationRegistrationResponse', applicationRegistrationResponse)).to.be.true; + } catch(e) { + expect(e instanceof ApiError, TestLogger.createNotApiErrorMessage(e.message)).to.be.true; + expect(false, TestLogger.createApiTestFailMessage('failed', e)).to.be.true; + } + }); + + it(`${scriptName}: should request access to eventApiProduct with plan`, async () => { + try { + // select EventApiProduct + const queryAst = EpSdkRsqlQueryBuilder.eq(TestUtils.nameOf("name"), EventApiProductName_1); + const eventApiProductsResponse: EventApiProductsResponse = await EventApiProductsService.listEventApiProducts({ + query: emit(queryAst) + }); + expect(eventApiProductsResponse.data.length, 'eventApiProductsResponse.data.length').to.equal(1); + EventApiProduct_1 = eventApiProductsResponse.data[0]; + // // DEBUG + // expect(false,TestLogger.createLogMessage('DEBUG: eventApiProductsResponse.data', eventApiProductsResponse.data)).to.be.true; + expect(EventApiProduct_1.plans.length, 'EventApiProduct_1.plans.length').to.be.greaterThanOrEqual(2); + // create the access request plan 0 + const plan_0: Plan = EventApiProduct_1.plans[0]; + const eventApiProductRegistrationResponse: EventApiProductRegistrationResponse = await RegistrationsService.createAppRegistrationAccessRequest({ + registrationId: AppRegistrationId_1, + requestBody: { + accessRequestId: TestUtils.getShortUUID(), + eventApiProductId: EventApiProduct_1.id, + planId: plan_0.id, + registrationId: AppRegistrationId_1 + } + }); + // // DEBUG + // expect(false,TestLogger.createLogMessage('DEBUG: eventApiProductRegistrationResponse', eventApiProductRegistrationResponse)).to.be.true; + // create the access request plan 1 + const plan_1: Plan = EventApiProduct_1.plans[1]; + const eventApiProductRegistrationResponse_1: EventApiProductRegistrationResponse = await RegistrationsService.createAppRegistrationAccessRequest({ + registrationId: AppRegistrationId_1, + requestBody: { + accessRequestId: TestUtils.getShortUUID(), + eventApiProductId: EventApiProduct_1.id, + planId: plan_1.id, + registrationId: AppRegistrationId_1 + } + }); + // // DEBUG + // expect(false,TestLogger.createLogMessage('DEBUG: eventApiProductRegistrationResponse_1', eventApiProductRegistrationResponse_1)).to.be.true; + + // get all access requests + const eventApiProductRegistrationsResponse: EventApiProductRegistrationsResponse = await RegistrationsService.getAppRegistrationAccessRequests({ + registrationId: AppRegistrationId_1 + }); + // // DEBUG + // expect(false,TestLogger.createLogMessage('DEBUG: eventApiProductRegistrationsResponse', eventApiProductRegistrationsResponse)).to.be.true; + } catch(e) { + expect(e instanceof ApiError, TestLogger.createNotApiErrorMessage(e.message)).to.be.true; + expect(false, TestLogger.createApiTestFailMessage('failed', e)).to.be.true; + } + }); + + it(`${scriptName}: should get list eventApis for access requests`, async () => { + try { + // get all access requestrs + const eventApiProductRegistrationsResponse: EventApiProductRegistrationsResponse = await RegistrationsService.getAppRegistrationAccessRequests({ + registrationId: AppRegistrationId_1 + }); + const list: Array<{ + eventApiProductRegistration: EventApiProductRegistration; + eventApiVersionList: Array; + }> = []; + const eventApiVersionList: Array = []; + for(const eventApiProductRegistration of eventApiProductRegistrationsResponse.data) { + const eventApisResponse: EventApisResponse = await RegistrationsService.getAppRegistrationAccessRequestApis({ + registrationId: eventApiProductRegistration.registrationId, + accessRequestId: eventApiProductRegistration.accessRequestId + }); + eventApiVersionList.push(...eventApisResponse.data); + list.push({ + eventApiProductRegistration: eventApiProductRegistration, + eventApiVersionList: eventApisResponse.data + }); + // get the eventApi + for(const eventApiVersion of eventApisResponse.data) { + const asyncApiAny: any = await RegistrationsService.getAppRegistrationAccessRequestApi({ + registrationId: eventApiProductRegistration.registrationId, + accessRequestId: eventApiProductRegistration.accessRequestId, + eventApiId: eventApiVersion.id, + }); + // // DEBUG + // expect(false,TestLogger.createLogMessage('DEBUG: asyncApiAny', asyncApiAny)).to.be.true; + } + } + // // DEBUG + // expect(false,TestLogger.createLogMessage('DEBUG: eventApiVersionList', eventApiVersionList)).to.be.true; + // // DEBUG + // expect(false,TestLogger.createLogMessage('DEBUG: list', list)).to.be.true; + } catch(e) { + expect(e instanceof ApiError, TestLogger.createNotApiErrorMessage(e.message)).to.be.true; + expect(false, TestLogger.createApiTestFailMessage('failed', e)).to.be.true; + } + }); + + + + it(`${scriptName}: should list app registrations with paging`, async () => { + const PageSize = 1; + try { + const applicationRegistrationViewList: Array = []; + let nextPage: number | null = 1; + while(nextPage !== null) { + const queryAst = EpSdkRsqlQueryBuilder.eq(TestUtils.nameOf("applicationDomainId"), ApplicationDomainId); + const applicationRegistrationsResponse: ApplicationRegistrationsResponse = await RegistrationsService.listAppRegistrations({ + pageSize: PageSize, + pageNumber: nextPage, + query: emit(queryAst) + }); + expect(applicationRegistrationsResponse.data, TestLogger.createApiTestFailMessage('failed')).to.not.be.undefined; + expect(applicationRegistrationsResponse.data.length, TestLogger.createApiTestFailMessage('failed')).to.be.lessThanOrEqual(PageSize); + const meta = applicationRegistrationsResponse.meta; + expect(meta, TestLogger.createApiTestFailMessage('failed')).to.not.be.undefined; + // // DEBUG + // expect(false,TestLogger.createLogMessage('meta', meta)).to.be.true; + // expect(meta.pagination.nextPage,TestLogger.createApiTestFailMessage(TestLogger.createLogMessage('meta', meta))).to.be.greaterThan(0); + nextPage = meta.pagination.nextPage; + if(nextPage === 0) nextPage = null; + applicationRegistrationViewList.push(...applicationRegistrationsResponse.data); + // // DEBUG + // expect(false,TestLogger.createLogMessage('DEBUG: applicationRegistrationsResponse', applicationRegistrationsResponse)).to.be.true; + } + // // DEBUG + // expect(false, TestLogger.createLogMessage('full list', eventApiProductList)).to.be.true; + } catch(e) { + expect(e instanceof ApiError, TestLogger.createNotApiErrorMessage(e.message)).to.be.true; + expect(false, TestLogger.createApiTestFailMessage('failed', e)).to.be.true; + } + }); + +}); + diff --git a/packages/tools/package.json b/packages/tools/package.json index 1831788b9..2479dd26d 100644 --- a/packages/tools/package.json +++ b/packages/tools/package.json @@ -12,5 +12,7 @@ "build:test": "yarn build" }, "dependencies": {}, - "devDependencies": {} + "devDependencies": { + "short-uuid": "^4.2.2" + } } diff --git a/packages/tools/src/testLib/TestUtils.ts b/packages/tools/src/testLib/TestUtils.ts index ced701768..916ec211c 100644 --- a/packages/tools/src/testLib/TestUtils.ts +++ b/packages/tools/src/testLib/TestUtils.ts @@ -1,4 +1,5 @@ import { v4 as uuidv4 } from 'uuid'; +import short from 'short-uuid'; // use with // @ts-ignore if getting Type instantiation is excessively deep and possibly infinite. TS2589 type DotPrefix = T extends "" ? "" : `.${T}`; @@ -11,13 +12,13 @@ type DeepPartial = T extends object ? { export class TestUtils { - public static nameOf(name: DotNestedKeys>) { - return name; - } + public static nameOf(name: DotNestedKeys>) { return name; } - public static getUUID = (): string => { - return uuidv4(); - } + public static getUUID = (): string => { return uuidv4(); } + + public static getShortUUID = (): string => { return short.generate(); } + + public static getKey = (): string => { return btoa(TestUtils.getUUID()); } public static assertNever = (extLogName: string, x: never): never => { const funcName = 'assertNever'; diff --git a/yarn.lock b/yarn.lock index 332e54f5b..1a92956fc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2074,6 +2074,11 @@ ansi-styles@^4.0.0, ansi-styles@^4.1.0: dependencies: color-convert "^2.0.1" +any-base@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/any-base/-/any-base-1.1.0.tgz#ae101a62bc08a597b4c9ab5b7089d456630549fe" + integrity sha512-uMgjozySS8adZZYePpaWs8cxB9/kdzmpX6SgJZ+wbz1K5eYk5QMYDVJaZKhxyIHUdnnJkfR7SVgStgH7LkGUyg== + any-promise@^1.0.0: version "1.3.0" resolved "https://registry.yarnpkg.com/any-promise/-/any-promise-1.3.0.tgz#abc6afeedcea52e809cdc0376aed3ce39635d17f" @@ -6622,6 +6627,14 @@ shiki@^0.11.1: vscode-oniguruma "^1.6.1" vscode-textmate "^6.0.0" +short-uuid@^4.2.2: + version "4.2.2" + resolved "https://registry.yarnpkg.com/short-uuid/-/short-uuid-4.2.2.tgz#4bb3d926da04a4a5f34420d17b5551fd6d9d535c" + integrity sha512-IE7hDSGV2U/VZoCsjctKX6l5t5ak2jE0+aeGJi3KtvjIUNuZVmHVYUjNBhmo369FIWGDtaieRaO8A83Lvwfpqw== + dependencies: + any-base "^1.1.0" + uuid "^8.3.2" + side-channel@^1.0.4: version "1.0.4" resolved "https://registry.yarnpkg.com/side-channel/-/side-channel-1.0.4.tgz#efce5c8fdc104ee751b25c58d4290011fa5ea2cf" From ca107d11949c6dfaa6db427a3bc75577636030e8 Mon Sep 17 00:00:00 2001 From: Ricardo Gomez_Ulmke Date: Mon, 13 Feb 2023 13:57:31 +0100 Subject: [PATCH 3/5] changesets --- .changeset/purple-students-build.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/purple-students-build.md diff --git a/.changeset/purple-students-build.md b/.changeset/purple-students-build.md new file mode 100644 index 000000000..68f82557b --- /dev/null +++ b/.changeset/purple-students-build.md @@ -0,0 +1,6 @@ +--- +"@solace-labs/ep-apim-openapi-node": patch +"@internal/tools": patch +--- + +added ep apim app registration tests From 77a3f037df9bded175798a68e094e6a56071b141 Mon Sep 17 00:00:00 2001 From: Ricardo Gomez_Ulmke Date: Mon, 13 Feb 2023 16:39:27 +0100 Subject: [PATCH 4/5] ep-sdk: environment service --- .changeset/funny-stingrays-sing.md | 5 ++ .../src/services/EpSdkEnvironmentsService.ts | 90 +++++++++++++++++++ packages/ep-sdk/src/services/index.ts | 3 + .../services/environmentsService.spec.ts | 68 ++++++++++++++ 4 files changed, 166 insertions(+) create mode 100644 .changeset/funny-stingrays-sing.md create mode 100644 packages/ep-sdk/src/services/EpSdkEnvironmentsService.ts create mode 100644 packages/ep-sdk/test/specs/services/environmentsService.spec.ts diff --git a/.changeset/funny-stingrays-sing.md b/.changeset/funny-stingrays-sing.md new file mode 100644 index 000000000..8f8f05f1c --- /dev/null +++ b/.changeset/funny-stingrays-sing.md @@ -0,0 +1,5 @@ +--- +"@solace-labs/ep-sdk": minor +--- + +added Environment Service diff --git a/packages/ep-sdk/src/services/EpSdkEnvironmentsService.ts b/packages/ep-sdk/src/services/EpSdkEnvironmentsService.ts new file mode 100644 index 000000000..43f057bb7 --- /dev/null +++ b/packages/ep-sdk/src/services/EpSdkEnvironmentsService.ts @@ -0,0 +1,90 @@ +import { + ApplicationDomain, + ApplicationDomainResponse, + ApplicationDomainsResponse, + ApplicationDomainsService, + Environment, + EnvironmentResponse, + EnvironmentsResponse, + EnvironmentsService, + Pagination, +} from '@solace-labs/ep-openapi-node'; +import { + EpSdkApiContentError, + EpSdkServiceError, + EpSdkLogger, + EEpSdkLoggerCodes, +} from '../utils'; +import { + EpApiMaxPageSize +} from '../constants'; +import { EpSdkServiceClass } from './EpSdkService'; + + +/** @category Services */ +export class EpSdkEnvironmentsServiceClass extends EpSdkServiceClass { + + public listAll = async({ pageSize = EpApiMaxPageSize }:{ + pageSize?: number; /** for testing */ + }): Promise => { + const funcName = 'listAll'; + const logName = `${EpSdkEnvironmentsServiceClass.name}.${funcName}()`; + + const environmentList: Array = []; + + let nextPage: number | undefined | null = 1; + while(nextPage !== undefined && nextPage !== null) { + const environmentsResponse: EnvironmentsResponse = await EnvironmentsService.getEnvironments({ + pageSize: pageSize, + pageNumber: nextPage, + }); + if(environmentsResponse.data === undefined || environmentsResponse.data.length === 0) nextPage = undefined; + else { + environmentList.push(...environmentsResponse.data); + /* istanbul ignore next */ + if(environmentsResponse.meta === undefined) throw new EpSdkApiContentError(logName, this.constructor.name,'environmentsResponse.meta === undefined', { + environmentsResponse: environmentsResponse + }); + /* istanbul ignore next */ + if(environmentsResponse.meta.pagination === undefined) throw new EpSdkApiContentError(logName, this.constructor.name,'environmentsResponse.meta.pagination === undefined', { + environmentsResponse: environmentsResponse + }); + const pagination: Pagination = environmentsResponse.meta.pagination; + nextPage = pagination.nextPage; + } + } + const environmentsResponse: EnvironmentsResponse = { + data: environmentList, + meta: { + pagination: { + count: environmentList.length, + } + } + }; + return environmentsResponse; + } + + /** + * @param object + * @returns Environment + * @throws {@link EpSdkApiContentError} - if api response data is undefined + */ + public getById = async ({ environmentId }: { + environmentId: string; + }): Promise => { + const funcName = 'getById'; + const logName = `${EpSdkEnvironmentsServiceClass.name}.${funcName}()`; + + const environmentResponse: EnvironmentResponse = await EnvironmentsService.getEnvironment({ id: environmentId }); + /* istanbul ignore next */ + if (environmentResponse.data === undefined) throw new EpSdkApiContentError(logName, this.constructor.name, "environmentResponse.data === undefined", { + environmentId: environmentId + }); + const environment: Environment = environmentResponse.data; + return environment; + } + +} +/** @category Services */ +export default new EpSdkEnvironmentsServiceClass(); + diff --git a/packages/ep-sdk/src/services/index.ts b/packages/ep-sdk/src/services/index.ts index 5413e3c84..eb7ed7f7a 100644 --- a/packages/ep-sdk/src/services/index.ts +++ b/packages/ep-sdk/src/services/index.ts @@ -6,6 +6,9 @@ export { default as EpSdkApplicationsService } from './EpSdkApplicationsService' export * from './EpSdkApplicationDomainsService'; export { default as EpSdkApplicationDomainsService } from './EpSdkApplicationDomainsService'; +export * from './EpSdkEnvironmentsService'; +export { default as EpSdkEnvironmentsService } from './EpSdkEnvironmentsService'; + export * from './EpSdkCustomAttributeDefinitionsService'; export { default as EpSdkCustomAttributeDefinitionsService } from './EpSdkCustomAttributeDefinitionsService'; diff --git a/packages/ep-sdk/test/specs/services/environmentsService.spec.ts b/packages/ep-sdk/test/specs/services/environmentsService.spec.ts new file mode 100644 index 000000000..1df57aab3 --- /dev/null +++ b/packages/ep-sdk/test/specs/services/environmentsService.spec.ts @@ -0,0 +1,68 @@ +import "mocha"; +import { expect } from "chai"; +import path from "path"; +import { + ApiError, + Environment, + EnvironmentsResponse, +} from "@solace-labs/ep-openapi-node"; +import { TestContext, TestUtils } from "@internal/tools/src"; +import { TestLogger } from "../../lib"; +import { + EpSdkError, + EpSdkEnvironmentsService, +} from "../../../src"; + +const scriptName: string = path.basename(__filename); +TestLogger.logMessage(scriptName, ">>> starting ..."); +const TestSpecName = scriptName; +const TestSpecId: string = TestUtils.getUUID(); + +const initializeGlobals = () => { +}; + +describe(`${scriptName}`, () => { + before(async () => { + TestContext.newItId(); + initializeGlobals(); + }); + + beforeEach(() => { + TestContext.newItId(); + }); + + after(async () => { + TestContext.newItId(); + }); + + it(`${scriptName}: should list all environments`, async () => { + try { + const environmentsResponse: EnvironmentsResponse = await EpSdkEnvironmentsService.listAll({ pageSize: 1 }); + const message = `environmentsResponse=\n${JSON.stringify(environmentsResponse, null, 2 )}`; + expect(environmentsResponse.meta.pagination.count, TestLogger.createApiTestFailMessage(message)).to.be.greaterThanOrEqual(1); + expect(environmentsResponse.data, TestLogger.createApiTestFailMessage(message)).to.not.be.undefined; + expect(environmentsResponse.data.length, TestLogger.createApiTestFailMessage(message)).to.be.greaterThanOrEqual(1); + // // DEBUG + // expect(false, TestLogger.createApiTestFailMessage(message)).to.be.true; + } catch (e) { + if (e instanceof ApiError) expect(false, TestLogger.createApiTestFailMessage("failed")).to.be.true; + expect(e instanceof EpSdkError, TestLogger.createNotEpSdkErrorMessage(e)).to.be.true; + expect(false, TestLogger.createEpSdkTestFailMessage("failed", e)).to.be.true; + } + }); + + it(`${scriptName}: should get each environment by Id`, async () => { + try { + const environmentsResponse: EnvironmentsResponse = await EpSdkEnvironmentsService.listAll({}); + if(environmentsResponse.data === undefined) throw new Error('environmentsResponse.data === undefined'); + for(const environment of environmentsResponse.data) { + const env: Environment = await EpSdkEnvironmentsService.getById({ environmentId: environment.id }); + } + } catch (e) { + if (e instanceof ApiError) expect(false, TestLogger.createApiTestFailMessage("failed")).to.be.true; + expect(e instanceof EpSdkError, TestLogger.createNotEpSdkErrorMessage(e)).to.be.true; + expect(false, TestLogger.createEpSdkTestFailMessage("failed", e)).to.be.true; + } + }); + +}); From 0eea123d55b3f93d4e9074e98f73d265957d58ea Mon Sep 17 00:00:00 2001 From: Ricardo Gomez_Ulmke Date: Mon, 13 Feb 2023 17:09:29 +0100 Subject: [PATCH 5/5] env service added --- packages/ep-apim-openapi-node/package.json | 2 +- packages/ep-sdk/src/services/EpSdkEnvironmentsService.ts | 7 ------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/packages/ep-apim-openapi-node/package.json b/packages/ep-apim-openapi-node/package.json index 8e43223de..18ae7f5b9 100644 --- a/packages/ep-apim-openapi-node/package.json +++ b/packages/ep-apim-openapi-node/package.json @@ -64,4 +64,4 @@ "@solace-labs/ep-asyncapi": "^0.53.1", "openapi-typescript-codegen": "^0.19.0" } -} +} \ No newline at end of file diff --git a/packages/ep-sdk/src/services/EpSdkEnvironmentsService.ts b/packages/ep-sdk/src/services/EpSdkEnvironmentsService.ts index 43f057bb7..ca8e6e3a1 100644 --- a/packages/ep-sdk/src/services/EpSdkEnvironmentsService.ts +++ b/packages/ep-sdk/src/services/EpSdkEnvironmentsService.ts @@ -1,8 +1,4 @@ import { - ApplicationDomain, - ApplicationDomainResponse, - ApplicationDomainsResponse, - ApplicationDomainsService, Environment, EnvironmentResponse, EnvironmentsResponse, @@ -11,9 +7,6 @@ import { } from '@solace-labs/ep-openapi-node'; import { EpSdkApiContentError, - EpSdkServiceError, - EpSdkLogger, - EEpSdkLoggerCodes, } from '../utils'; import { EpApiMaxPageSize