Skip to content

Commit

Permalink
Merge branch 'master' into ID-1462-add-OAuth-support
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelefros authored Jun 27, 2024
2 parents edbcae3 + 1fcb9fe commit b27d44f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/api/diff-api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {PackageDiffTransport} from "../interfaces/diff-package.transport";
import { PackageDiffMetadata, PackageDiffTransport } from "../interfaces/diff-package.transport";
import {httpClientV2} from "../services/http-client-service.v2";
import * as FormData from "form-data";

Expand All @@ -12,7 +12,7 @@ class DiffApi {
);
}

public async hasChanges(data: FormData): Promise<PackageDiffTransport[]> {
public async hasChanges(data: FormData): Promise<PackageDiffMetadata[]> {
return httpClientV2.postFile(
"/package-manager/api/core/packages/diff/configuration/has-changes",
data
Expand Down
6 changes: 5 additions & 1 deletion src/interfaces/diff-package.transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ export interface NodeDiffTransport {

export interface PackageDiffTransport {
packageKey: string;
hasChanges: boolean
packageChanges: ConfigurationChangeTransport[];
nodesWithChanges: NodeDiffTransport[];
}

export interface PackageDiffMetadata {
packageKey: string;
hasChanges: boolean;
}
20 changes: 15 additions & 5 deletions src/services/package-manager/diff-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as FormData from "form-data";
import {diffApi} from "../../api/diff-api";
import {FileService, fileService} from "../file-service";
import {logger} from "../../util/logger";
import {PackageDiffTransport} from "../../interfaces/diff-package.transport";
import { PackageDiffMetadata, PackageDiffTransport } from "../../interfaces/diff-package.transport";
import {v4 as uuidv4} from "uuid";

class DiffService {
Expand All @@ -23,9 +23,9 @@ class DiffService {
const returnedHasChangesData = await diffApi.hasChanges(formData);

if (jsonResponse) {
this.exportListOfPackageDiffs(returnedHasChangesData);
this.exportListOfPackageDiffMetadata(returnedHasChangesData);
} else {
logger.info(this.buildStringResponse(returnedHasChangesData));
logger.info(this.buildStringResponseForPackageDiffMetadataList(returnedHasChangesData));
}
}

Expand All @@ -37,7 +37,7 @@ class DiffService {
if (jsonResponse) {
this.exportListOfPackageDiffs(returnedHasChangesData);
} else {
logger.info(this.buildStringResponse(returnedHasChangesData));
logger.info(this.buildStringResponseForPackageDiffs(returnedHasChangesData));
}
}

Expand Down Expand Up @@ -65,9 +65,19 @@ class DiffService {
logger.info(FileService.fileDownloadedMessage + filename);
}

private buildStringResponse(packageDiffs: PackageDiffTransport[]): string {
private exportListOfPackageDiffMetadata(packageDiffMetadata: PackageDiffMetadata[]): void {
const filename = uuidv4() + ".json";
fileService.writeToFileWithGivenName(JSON.stringify(packageDiffMetadata), filename);
logger.info(FileService.fileDownloadedMessage + filename);
}

private buildStringResponseForPackageDiffs(packageDiffs: PackageDiffTransport[]): string {
return "\n" + JSON.stringify(packageDiffs, null, 2);
}

private buildStringResponseForPackageDiffMetadataList(packageDiffMetadata: PackageDiffMetadata[]): string {
return "\n" + JSON.stringify(packageDiffMetadata, null, 2);
}
}

export const diffService = new DiffService();
17 changes: 6 additions & 11 deletions tests/config/config-diff.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import * as path from "path";
import {stringify} from "../../src/util/yaml";
import {mockCreateReadStream, mockExistsSync, mockReadFileSync} from "../utls/fs-mock-utils";
import {
PackageDiffTransport
PackageDiffMetadata,
PackageDiffTransport,
} from "../../src/interfaces/diff-package.transport";
import {mockAxiosPost} from "../utls/http-requests-mock";
import {ConfigCommand} from "../../src/commands/config.command";
Expand All @@ -29,11 +30,9 @@ describe("Config diff", () => {
mockReadFileSync(exportedPackagesZip.toBuffer());
mockCreateReadStream(exportedPackagesZip.toBuffer());

const diffResponse: PackageDiffTransport[] = [{
const diffResponse: PackageDiffMetadata[] = [{
packageKey: "package-key",
hasChanges: true,
packageChanges: [],
nodesWithChanges: []
hasChanges: true
}];

mockAxiosPost("https://myTeam.celonis.cloud/package-manager/api/core/packages/diff/configuration/has-changes", diffResponse);
Expand All @@ -60,7 +59,6 @@ describe("Config diff", () => {

const diffResponse: PackageDiffTransport[] = [{
packageKey: "package-key",
hasChanges: true,
packageChanges: [
{
op: "add",
Expand Down Expand Up @@ -103,7 +101,6 @@ describe("Config diff", () => {

const diffResponse: PackageDiffTransport[] = [{
packageKey: "package-key",
hasChanges: true,
packageChanges: [
{
op: "add",
Expand Down Expand Up @@ -148,11 +145,9 @@ describe("Config diff", () => {
mockReadFileSync(exportedPackagesZip.toBuffer());
mockCreateReadStream(exportedPackagesZip.toBuffer());

const diffResponse: PackageDiffTransport[] = [{
const diffResponse: PackageDiffMetadata[] = [{
packageKey: "package-key",
hasChanges: true,
packageChanges: [],
nodesWithChanges: []
hasChanges: true
}];

mockAxiosPost("https://myTeam.celonis.cloud/package-manager/api/core/packages/diff/configuration/has-changes", diffResponse);
Expand Down

0 comments on commit b27d44f

Please sign in to comment.