Skip to content

Commit

Permalink
added verifyScanStatus util (#10)
Browse files Browse the repository at this point in the history
added verifyScanStatus util

---------

Co-authored-by: SOOS-GSteen <[email protected]>
  • Loading branch information
SOOS-JAlvarez and SOOS-GSteen authored Dec 6, 2023
1 parent 3468822 commit b9ebee3
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@soos-io/api-client",
"version": "0.2.1",
"version": "0.2.2",
"description": "This is the SOOS API Client for registered clients leveraging the various integrations to the SOOS platform.",
"main": "dist/index.js",
"scripts": {
Expand Down
27 changes: 26 additions & 1 deletion src/utilities.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { isNil, ensureValue, ensureEnumValue, ensureNonEmptyValue } from "./utilities";
import { ScanStatus } from "./enums";
import {
isNil,
ensureValue,
ensureEnumValue,
ensureNonEmptyValue,
verifyScanStatus,
} from "./utilities";

describe("isNil", () => {
test("should return true for null", () => {
Expand Down Expand Up @@ -73,3 +80,21 @@ describe("ensureEnumValue", () => {
expect(ensureEnumValue({ value: "value" }, "VALUE")).toBe("value");
});
});

describe("verifyScanStatus", () => {
test("should return false for Finished", () => {
expect(verifyScanStatus(ScanStatus.Finished)).toBe(false);
});

test("should return true for an Incomplete status", () => {
expect(verifyScanStatus(ScanStatus.Incomplete)).toBe(true);
});

test("should return true for an Error status", () => {
expect(verifyScanStatus(ScanStatus.Error)).toBe(true);
});

test("should return true for a FailedWithIssues status", () => {
expect(verifyScanStatus(ScanStatus.FailedWithIssues)).toBe(true);
});
});
24 changes: 24 additions & 0 deletions src/utilities.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import axios, { AxiosError } from "axios";
import { soosLogger } from "./logging/SOOSLogger";
import StringUtilities from "./StringUtilities";
import { ScanStatus } from "./enums";

const isNil = (value: unknown): value is null | undefined => value === null || value === undefined;

Expand Down Expand Up @@ -113,6 +114,28 @@ const formatBytes = (bytes: number, decimals = 2) => {
return `${count} ${unit}`;
};

const verifyScanStatus = (scanStatus: ScanStatus): boolean => {
let fail = false;
if (scanStatus === ScanStatus.FailedWithIssues) {
soosLogger.warn("Analysis complete - Failures reported");
fail = true;
} else if (scanStatus === ScanStatus.Incomplete) {
soosLogger.warn(
"Analysis Incomplete. It may have been cancelled or superseded by another scan.",
);
fail = true;
} else if (scanStatus === ScanStatus.Error) {
soosLogger.warn("Analysis Error.");
fail = true;
}

if (fail) {
soosLogger.warn("Failing the build.");
}

return fail;
};

export {
isNil,
ensureValue,
Expand All @@ -124,4 +147,5 @@ export {
convertStringToBase64,
getEnvVariable,
formatBytes,
verifyScanStatus,
};
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* Visit https://aka.ms/tsconfig.json to read more about this file */
{
"compilerOptions": {
"target": "ES2015", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"target": "ES2021", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
"outDir": "./dist", /* Redirect output structure to the directory. */
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
Expand Down

0 comments on commit b9ebee3

Please sign in to comment.