Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding modified files to use getCurrentPewPewLatestVersion #206

Merged
merged 9 commits into from
Mar 21, 2024
16 changes: 8 additions & 8 deletions controller/integration/testmanager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1882,7 +1882,7 @@ describe("TestManager Integration", () => {
});
});

it("postTest with version latest should respond 200 OK", (done: Mocha.Done) => {
it("postTest with version latest should respond 400 Bad Request, because latest is Legacy", (done: Mocha.Done) => {
const parsedForm: ParsedForm = {
files: scriptingFiles,
fields: {
Expand All @@ -1893,14 +1893,14 @@ describe("TestManager Integration", () => {
log("postTest parsedForm latest", LogLevel.DEBUG, { parsedForm });
TestManager.postTest(parsedForm, authAdmin, UNIT_TEST_FOLDER).then((res: ErrorResponse | TestDataResponse) => {
log("postTest res", LogLevel.DEBUG, res);
expect(res.status, JSON.stringify(res.json)).to.equal(200);
const body: TestData = res.json as TestData;
log("body: " + JSON.stringify(res.json), LogLevel.DEBUG, body);
expect(res.status, JSON.stringify(res.json)).to.equal(400);
log("body: " + JSON.stringify(res.json), LogLevel.DEBUG, res.json);
const body: TestManagerError = res.json as TestManagerError;
expect(body).to.not.equal(undefined);
expect(body.testId).to.not.equal(undefined);
expect(body.s3Folder).to.not.equal(undefined);
expect(body.status).to.equal(TestStatus.Created);
expect(body.userId).to.equal(authAdmin.userId);
expect(body.message).to.not.equal(undefined);
expect(body.message).to.include("failed to parse");
expect(body.error).to.not.equal(undefined);
expect(body.error).to.include("UnrecognizedKey");
done();
}).catch((error) => {
log("postTest error", LogLevel.ERROR, error);
Expand Down
10 changes: 7 additions & 3 deletions controller/pages/api/util/testmanager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import { formatError, isYamlFile, latestPewPewVersion } from "./clientutil";
import { createS3Filename as createS3MessageFilename } from "@fs/ppaas-common/dist/src/ppaass3message";
import { createS3Filename as createS3StatusFilename } from "@fs/ppaas-common/dist/src/ppaasteststatus";
import fs from "fs/promises";
import { getCurrentPewPewLatestVersion } from "./pewpew";
import semver from "semver";

logger.config.LogFileName = "ppaas-controller";
Expand Down Expand Up @@ -431,10 +432,13 @@ export async function downloadPriorTestId (
}

// Export for testing
export function getValidateLegacyOnly (version: string | undefined): boolean | undefined {
export async function getValidateLegacyOnly (version: string | undefined): Promise<boolean | undefined> {
// undefined or "latest" parse as anything (reutrn undefined)
if (!version || version === latestPewPewVersion) {
return undefined;
version = await getCurrentPewPewLatestVersion();
if (!version) { // If it's still undefined, we don't know what version latest is, parse as either
return undefined;
}
}
// This needs to create the validateLegacyOnly, so anything less than 0.6.0
return semver.satisfies(version, LEGACY_PEWPEW_VERSION, { includePrerelease: true });
Expand Down Expand Up @@ -1217,7 +1221,7 @@ export abstract class TestManager {
log("environmentVariables", LogLevel.TRACE, environmentVariablesFile);

// Pass pewpew version legacy/scripting
const validateLegacyOnly = getValidateLegacyOnly(version);
const validateLegacyOnly = await getValidateLegacyOnly(version);
const validateResult: ErrorResponse | ValidateYamlfileResult = await validateYamlfile(yamlFile, PpaasEncryptEnvironmentFile.getEnvironmentVariables(environmentVariablesFile), additionalFileNames, bypassParser, authPermissions, validateLegacyOnly);
// eslint-disable-next-line no-prototype-builtins
if (validateResult.hasOwnProperty("json")) {
Expand Down
61 changes: 45 additions & 16 deletions controller/test/testmanager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ import {
logger
} from "@fs/ppaas-common";
import type { File, FileJSON } from "formidable";
import { mockGetObjectTagging, mockS3, resetMockS3 } from "./mock";
import { Test as MochaTest } from "mocha";
import { PpaasEncryptS3File } from "../pages/api/util/ppaasencrypts3file";
import { TestSchedulerIntegration } from "./testscheduler.spec";
import { VERSION_TAG_NAME } from "../pages/api/util/pewpew";
import { expect } from "chai";
import { latestPewPewVersion } from "../pages/api/util/clientutil";
import path from "path";
Expand Down Expand Up @@ -318,6 +320,8 @@ describe("TestManager", () => {

const validateLegacyOnlySuite: Mocha.Suite = describe("getValidateLegacyOnly", () => {
before (() => {
mockS3();
mockGetObjectTagging(new Map([["pewpew", "true"]]));
const validateLegacyOnlyArray: [string, boolean][] = [
["0.4.0", true],
["0.5.0", true],
Expand All @@ -335,41 +339,66 @@ describe("TestManager", () => {
["1.0.0", false]
];
for (const [version, expected] of validateLegacyOnlyArray) {
validateLegacyOnlySuite.addTest(new MochaTest(version + " should return " + expected, (done: Mocha.Done) => {
validateLegacyOnlySuite.addTest(new MochaTest(version + " should return " + expected, async () => {
try {
expect(getValidateLegacyOnly(version)).to.equal(expected);
done();
expect(await getValidateLegacyOnly(version)).to.equal(expected);
} catch (error) {
done(error);
throw error;
}
}));
validateLegacyOnlySuite.addTest(new MochaTest(`latest should return ${expected} for pewpew tagged with version ${version}` , async () => {
try {
mockGetObjectTagging(new Map([[VERSION_TAG_NAME, version]]));
await getValidateLegacyOnly(latestPewPewVersion).then((result: boolean | undefined) => {
log("getValidateLegacyOnly()", LogLevel.INFO, result);
expect(result).to.equal(expected);
});
} catch (error) {
throw error;
}
}));
}
});

it("should return undefined for undefined", (done: Mocha.Done) => {
beforeEach(() => {
mockGetObjectTagging(new Map([["pewpew", "true"]]));
global.currentLatestVersion = undefined;
});

after(() => {
resetMockS3();
global.currentLatestVersion = undefined;
});
it("should return undefined for undefined", async () => {
try {
expect(getValidateLegacyOnly(undefined)).to.equal(undefined);
done();
await getValidateLegacyOnly(undefined).then((result: boolean | undefined) => {
log("getValidateLegacyOnly()", LogLevel.INFO, result);
expect(result).to.equal(undefined);
});
} catch (error) {
done(error);
throw error;
}
});

it("should return undefined for empty string", (done: Mocha.Done) => {
it("should return undefined for empty string", async () => {
try {
expect(getValidateLegacyOnly("")).to.equal(undefined);
done();
await getValidateLegacyOnly("").then((result: boolean | undefined) => {
log("getValidateLegacyOnly()", LogLevel.INFO, result);
expect(result).to.equal(undefined);
});
} catch (error) {
done(error);
throw error;
}
});

it("should return undefined for latest", (done: Mocha.Done) => {
it("should return undefined for latest when no version tagged", async () => {
try {
expect(getValidateLegacyOnly(latestPewPewVersion)).to.equal(undefined);
done();
await getValidateLegacyOnly(latestPewPewVersion).then((result: boolean | undefined) => {
log("getValidateLegacyOnly()", LogLevel.INFO, result);
expect(result).to.equal(undefined);
});
} catch (error) {
done(error);
throw error;
}
});
});
Expand Down