Skip to content

Commit

Permalink
Merge pull request #37 from SolaceLabs/ep-apps
Browse files Browse the repository at this point in the history
Ep apps
  • Loading branch information
ricardojosegomezulmke authored Feb 13, 2023
2 parents ee38a61 + 0eea123 commit 485ced1
Show file tree
Hide file tree
Showing 11 changed files with 515 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/funny-stingrays-sing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@solace-labs/ep-sdk": minor
---

added Environment Service
6 changes: 6 additions & 0 deletions .changeset/purple-students-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@solace-labs/ep-apim-openapi-node": patch
"@internal/tools": patch
---

added ep apim app registration tests
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@solace-labs/solace-tools-typescript",
"version": "2.9.0",
"version": "2.9.1",
"private": true,
"workspaces": [
"packages/*"
Expand Down
4 changes: 2 additions & 2 deletions packages/ep-apim-openapi-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
324 changes: 324 additions & 0 deletions packages/ep-apim-openapi-node/test/specs/appRegistrations.x-spec.ts
Original file line number Diff line number Diff line change
@@ -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<EventApiProduct> = [];


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<ApplicationRegistrationView> = [];
let nextPage: number | null = 1;
while(nextPage !== null) {
const queryAst = EpSdkRsqlQueryBuilder.eq(TestUtils.nameOf<ApplicationRegistrationView>("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<EventApiProduct>("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<EventApiVersion>;
}> = [];
const eventApiVersionList: Array<EventApiVersion> = [];
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<ApplicationRegistrationView> = [];
let nextPage: number | null = 1;
while(nextPage !== null) {
const queryAst = EpSdkRsqlQueryBuilder.eq(TestUtils.nameOf<ApplicationRegistrationView>("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;
}
});

});

Loading

0 comments on commit 485ced1

Please sign in to comment.