From b9ebee350ad71aaa52ea15abad5a556a0313b8ac Mon Sep 17 00:00:00 2001 From: SOOS-JAlvarez <92373106+SOOS-JAlvarez@users.noreply.github.com> Date: Wed, 6 Dec 2023 13:03:33 -0300 Subject: [PATCH] added verifyScanStatus util (#10) added verifyScanStatus util --------- Co-authored-by: SOOS-GSteen --- package-lock.json | 4 ++-- package.json | 2 +- src/utilities.test.ts | 27 ++++++++++++++++++++++++++- src/utilities.ts | 24 ++++++++++++++++++++++++ tsconfig.json | 2 +- 5 files changed, 54 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index afca1d4..a79e0db 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@soos-io/api-client", - "version": "0.2.1", + "version": "0.2.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@soos-io/api-client", - "version": "0.2.1", + "version": "0.2.2", "license": "MIT", "dependencies": { "axios": "^1.6.2", diff --git a/package.json b/package.json index 18ac90e..bb31465 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/utilities.test.ts b/src/utilities.test.ts index e3471df..5e5a6d6 100644 --- a/src/utilities.test.ts +++ b/src/utilities.test.ts @@ -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", () => { @@ -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); + }); +}); diff --git a/src/utilities.ts b/src/utilities.ts index 4421780..496d5b4 100644 --- a/src/utilities.ts +++ b/src/utilities.ts @@ -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; @@ -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, @@ -124,4 +147,5 @@ export { convertStringToBase64, getEnvVariable, formatBytes, + verifyScanStatus, }; diff --git a/tsconfig.json b/tsconfig.json index 2dbde95..263d93c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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. */