Skip to content
This repository has been archived by the owner on Nov 7, 2024. It is now read-only.

Commit

Permalink
Merge pull request #348 from milanmelisik/create-package-command
Browse files Browse the repository at this point in the history
Create package command
  • Loading branch information
roman-kupriyanov authored Dec 5, 2023
2 parents 742eb1c + 48526f9 commit f05589c
Show file tree
Hide file tree
Showing 19 changed files with 1,425 additions and 76 deletions.
140 changes: 140 additions & 0 deletions packages/endevor/__tests__/api-v1-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
getProcessorGroupsByType,
searchForProcessorGroupsInPlace,
moveElements,
createPackage,
} from '../endevor';
import { mockEndpoint } from '../testUtils';
import { toEndevorProtocol, isErrorEndevorResponse, isDefined } from '../utils';
Expand Down Expand Up @@ -64,6 +65,7 @@ import {
Value,
ErrorResponseType,
ProcessorGroupResponseObject,
PackageInformation,
} from '../_doc/Endevor';
import { join } from 'path';
import { ANY_VALUE } from '../const';
Expand Down Expand Up @@ -6883,4 +6885,142 @@ describe('endevor public api v1', () => {
expect(isErrorEndevorResponse(moveResponse)).toBe(true);
});
});

describe('creating a package', () => {
const configuration = 'TEST-INST';
const sclContent = 'MOVE SCL';
const packageInfo: PackageInformation = {
name: 'TESTPACKAGE',
description: 'DESCRIPTION',
};
const packageOptions = {
sharable: true,
backoutEnabled: true,
doNotValidateSCL: true,
isEmergency: true,
};

it('should create a package', async () => {
// arrange
// this chunked multipart/form-data request seems not available to be mocked with mockttp
// TODO: investigate ability to use mockServer.put().withForm() method instead, but it seems like it is not working
mockServer.forAnyRequest().thenJson(
200,
{
data: null,
reasonCode: '0034',
messages: null,
returnCode: '0000',
},
{
'api-version': '1.1',
'content-type': 'application/json',
}
);
const service = toService(mockServer.url);
// act
const createPackageResult = await createPackage(logger)(progress)(
service
)(configuration)(packageInfo)(packageOptions)(sclContent);
// assert
expect(createPackageResult).toEqual({
status: ResponseStatus.OK,
details: {
returnCode: 0,
messages: [],
},
});
});

it('should return error for incorrect connection details', async () => {
// arrange
const nonExistingService = toService(nonExistingServerURL);
// act
const createPackageResult = await createPackage(logger)(progress)(
nonExistingService
)(configuration)(packageInfo)(packageOptions)(sclContent);
// assert
expect(createPackageResult).toEqual({
status: ResponseStatus.ERROR,
type: 'CONNECTION_ERROR',
details: {
connectionCode: 'ECONNREFUSED',
httpStatusCode: undefined,
messages: [
`connect ECONNREFUSED ${nonExistingService.location.hostname}:${nonExistingService.location.port}`,
],
},
});
});

it('should return error for incorrect base credentials', async () => {
// arrange
// this chunked multipart/form-data request seems not available to be mocked with mockttp
// TODO: investigate ability to use mockServer.put().withForm() method instead, but it seems like it is not working
const messages = ['API0034S INVALID USERID OR PASSWORD DETECTED'];
mockServer.forAnyRequest().thenJson(
401,
{
returnCode: '0020',
reasonCode: '0034',
reports: null,
messages,
data: null,
},
{
'content-type': 'application/json',
version: '1.1',
}
);
const service = toService(mockServer.url);
// act
const createPackageResult = await createPackage(logger)(progress)(
service
)(configuration)(packageInfo)(packageOptions)(sclContent);
// assert
expect(createPackageResult).toEqual({
status: ResponseStatus.ERROR,
type: ErrorResponseType.WRONG_CREDENTIALS_ENDEVOR_ERROR,
details: {
messages: ['API0034S INVALID USERID OR PASSWORD DETECTED'],
returnCode: 20,
},
});
});

it('should return error if something goes wrong in Endevor side', async () => {
// arrange
// this chunked multipart/form-data request seems not available to be mocked with mockttp
// TODO: investigate ability to use mockServer.put().withForm() method instead, but it seems like it is not working
const messages = ['Something went really wrong....'];
mockServer.forAnyRequest().thenJson(
500,
{
returnCode: '0020',
reasonCode: '0034',
reports: null,
messages,
data: null,
},
{
'content-type': 'application/json',
version: '1.1',
}
);
const service = toService(mockServer.url);
// act
const createPackageResult = await createPackage(logger)(progress)(
service
)(configuration)(packageInfo)(packageOptions)(sclContent);
// assert
expect(createPackageResult).toEqual({
status: ResponseStatus.ERROR,
type: ErrorResponseType.GENERIC_ERROR,
details: {
messages: messages.map((message) => message.trim()),
returnCode: 20,
},
});
});
});
});
143 changes: 143 additions & 0 deletions packages/endevor/__tests__/api-v2-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
getAuthenticationToken,
downloadReportById,
moveElements,
createPackage,
printMember,
getMembersFromDataset,
} from '../endevor';
Expand Down Expand Up @@ -69,6 +70,7 @@ import {
SearchStrategies,
Value,
ErrorResponseType,
PackageInformation,
Member,
Dataset,
} from '../_doc/Endevor';
Expand Down Expand Up @@ -9433,6 +9435,147 @@ describe('endevor public api v2', () => {
});
});

describe('creating a package', () => {
const configuration = 'TEST-INST';
const sclContent = 'MOVE SCL';
const packageInfo: PackageInformation = {
name: 'TESTPACKAGE',
description: 'DESCRIPTION',
};
const packageOptions = {
sharable: true,
backoutEnabled: true,
doNotValidateSCL: true,
isEmergency: true,
};

it('should create a package', async () => {
// arrange
// this chunked multipart/form-data request seems not available to be mocked with mockttp
// TODO: investigate ability to use mockServer.put().withForm() method instead, but it seems like it is not working
const returnCode = 0;
const messages: string[] = [];
mockServer.forAnyRequest().thenJson(
200,
{
data: [],
messages,
reports: {},
returnCode,
},
{
version: '2.5',
'content-type': 'application/json',
}
);
const service = toService(mockServer.url);
// act
const createPackageResult = await createPackage(logger)(progress)(
service
)(configuration)(packageInfo)(packageOptions)(sclContent);
// assert
expect(createPackageResult).toEqual({
status: ResponseStatus.OK,
details: {
returnCode: 0,
messages: [],
},
});
});

it('should return error for incorrect connection details', async () => {
// arrange
const nonExistingService = toService(nonExistingServerURL);
// act
const createPackageResult = await createPackage(logger)(progress)(
nonExistingService
)(configuration)(packageInfo)(packageOptions)(sclContent);
// assert
expect(createPackageResult).toEqual({
status: ResponseStatus.ERROR,
type: 'CONNECTION_ERROR',
details: {
connectionCode: 'ECONNREFUSED',
httpStatusCode: undefined,
messages: [
`connect ECONNREFUSED ${nonExistingService.location.hostname}:${nonExistingService.location.port}`,
],
},
});
});

it('should return error for incorrect base credentials', async () => {
// arrange
// this chunked multipart/form-data request seems not available to be mocked with mockttp
// TODO: investigate ability to use mockServer.put().withForm() method instead, but it seems like it is not working
const messages = ['API0034S INVALID USERID OR PASSWORD DETECTED'];
const returnCode = 20;
mockServer.forAnyRequest().thenJson(
401,
{
returnCode,
reasonCode: 34,
reports: null,
messages,
data: [],
},
{
'content-type': 'application/json',
version: '2.5',
}
);
const service = toService(mockServer.url);
// act
const createPackageResult = await createPackage(logger)(progress)(
service
)(configuration)(packageInfo)(packageOptions)(sclContent);
// assert
expect(createPackageResult).toEqual({
status: ResponseStatus.ERROR,
type: ErrorResponseType.WRONG_CREDENTIALS_ENDEVOR_ERROR,
details: {
messages: ['API0034S INVALID USERID OR PASSWORD DETECTED'],
returnCode: 20,
},
});
});

it('should return error if something goes wrong in Endevor side', async () => {
// arrange
// this chunked multipart/form-data request seems not available to be mocked with mockttp
// TODO: investigate ability to use mockServer.put().withForm() method instead, but it seems like it is not working
const returnCode = 20;
const messages = ['Something went really wrong....'];
mockServer.forAnyRequest().thenJson(
500,
{
returnCode,
reasonCode: 34,
reports: null,
messages,
data: [],
},
{
'content-type': 'application/json',
version: '2.5',
}
);
const service = toService(mockServer.url);
// act
const createPackageResult = await createPackage(logger)(progress)(
service
)(configuration)(packageInfo)(packageOptions)(sclContent);
// assert
expect(createPackageResult).toEqual({
status: ResponseStatus.ERROR,
type: ErrorResponseType.GENERIC_ERROR,
details: {
messages: messages.map((message) => message.trim()),
returnCode: 20,
},
});
});
});
describe('printing members', () => {
const configuration = 'TEST-INST';
const member: Member = {
Expand Down
15 changes: 15 additions & 0 deletions packages/endevor/_doc/Endevor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ export type ChangeControlValue = Readonly<{
export type ActionChangeControlValue = ChangeControlValue;
export type ProcessorGroupValue = Value | undefined;

export type PackageInformation = Readonly<{
name: Value;
description: Value;
}>;

export type EnvironmentStageMapPath = Readonly<{
environment: Value;
stageNumber: StageNumber;
Expand Down Expand Up @@ -199,6 +204,8 @@ export type ElementDataWithFingerprint = ElementData &
fingerprint: Value;
}>;

export type PackageSclContent = string;

export type AuthorizationToken = Readonly<{
token: Value;
tokenCreatedOn: Value;
Expand Down Expand Up @@ -240,6 +247,13 @@ export type SignOutParams = Readonly<{
overrideSignOut?: OverrideSignOut;
}>;

export type CreatePackageParams = {
sharable: boolean;
backoutEnabled: boolean;
doNotValidateSCL: boolean;
isEmergency: boolean;
};

export const enum SearchStrategies {
IN_PLACE = 'IN_PLACE',
FIRST_FOUND = 'FIRST_FOUND',
Expand Down Expand Up @@ -511,3 +525,4 @@ export class EndevorResponseError extends Error {
Object.setPrototypeOf(this, EndevorResponseError.prototype);
}
}
export type PackageCreateResponse = AuthorizedEndevorResponse<undefined>;
8 changes: 6 additions & 2 deletions packages/endevor/_ext/Endevor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export type BaseResponseWithNoData = t.TypeOf<typeof BaseResponseWithNoData>;
export type SystemsResponse = t.TypeOf<typeof SystemsResponse>;
export type SubSystemsResponse = t.TypeOf<typeof SubSystemsResponse>;
export type ElementTypesResponse = t.TypeOf<typeof ElementTypesResponse>;
export type ProcessorGroupsRepsonse = t.TypeOf<typeof ProcessorGroupsRepsonse>;
export type ProcessorGroupsResponse = t.TypeOf<typeof ProcessorGroupsResponse>;
export type ElementsResponse = t.TypeOf<typeof ElementsResponse>;

export type ComponentsResponse = t.TypeOf<typeof ComponentsResponse>;
Expand All @@ -72,6 +72,8 @@ export type GenerateResponse = t.TypeOf<typeof GenerateResponse>;

export type SignInElementResponse = t.TypeOf<typeof SignInElementResponse>;

export type PackageCreateResponse = t.TypeOf<typeof PackageCreateResponse>;

export type AuthenticationTokenResponse = t.TypeOf<
typeof AuthenticationTokenResponse
>;
Expand Down Expand Up @@ -314,7 +316,7 @@ export const SystemsResponse = BaseResponseWithUnknownDataOrNull;
export const SubSystemsResponse = BaseResponseWithUnknownDataOrNull;
export const ElementTypesResponse = BaseResponseWithUnknownDataOrNull;
export const ElementsResponse = BaseResponseWithUnknownDataOrNull;
export const ProcessorGroupsRepsonse = BaseResponseWithUnknownDataOrNull;
export const ProcessorGroupsResponse = BaseResponseWithUnknownDataOrNull;

export const PrintResponse = BaseResponseWithContentOrNull;

Expand Down Expand Up @@ -360,3 +362,5 @@ export const GenerateResponse = BaseResponseWithNoData;
export const UpdateResponse = BaseResponseWithNoData;
export const AddResponse = BaseResponseWithNoData;
export const SignInElementResponse = BaseResponseWithNoData;

export const PackageCreateResponse = BaseResponseWithNoData;
Loading

0 comments on commit f05589c

Please sign in to comment.