Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/__tests__/unit/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,30 @@ describe("runWithDeps", () => {
expect(deps.setOutput).toHaveBeenCalledWith("method_used", "pull_request");
});

it("includes enum keys in the generated blank code.json", async () => {
process.env.GITHUB_EVENT_NAME = "schedule";

const deps = createMockDeps({
readFile: jest.fn<any>().mockRejectedValue(new Error("no file")),
skipPR: false,
});

await runWithDeps(deps);

const createPullRequestMock = deps.octokit.createPullRequest as jest.Mock;
const pullRequestArgs = createPullRequestMock.mock.calls[0][0] as any;
const codeJSONContent = pullRequestArgs.changes[0].files["code.json"];
const generatedCodeJSON = JSON.parse(codeJSONContent);

expect(generatedCodeJSON).toHaveProperty("status");
expect(generatedCodeJSON).toHaveProperty("repositoryHost");
expect(generatedCodeJSON).toHaveProperty("repositoryVisibility");
expect(generatedCodeJSON).toHaveProperty("softwareType");
expect(generatedCodeJSON).toHaveProperty("maintenance");
expect(generatedCodeJSON).toHaveProperty("repositoryType");
expect(generatedCodeJSON).toHaveProperty("fismaLevel");
});

it("attempts direct push when skipPR is true with admin token", async () => {
process.env.GITHUB_EVENT_NAME = "workflow_dispatch";

Expand Down
18 changes: 10 additions & 8 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import { Dependencies } from "./types/Dependencies.js";
import { createHelpers, Helpers } from "./helper.js";
import { createProductionDeps } from "./create-deps.js";

const blankEnumValue = "" as never;

const baselineCodeJSON: Partial<CodeJSON> = {
name: "",
version: "",
description: "",
longDescription: "",
status: undefined,
status: blankEnumValue,
permissions: {
licenses: [
{
Expand All @@ -21,8 +23,8 @@ const baselineCodeJSON: Partial<CodeJSON> = {
},
organization: "Centers for Medicare & Medicaid Services",
repositoryURL: "",
repositoryHost: undefined,
repositoryVisibility: undefined,
repositoryHost: blankEnumValue,
repositoryVisibility: blankEnumValue,
homepageURL: "",
downloadURL: "",
disclaimerURL: "",
Expand All @@ -35,9 +37,9 @@ const baselineCodeJSON: Partial<CodeJSON> = {
},
platforms: [],
categories: [],
softwareType: undefined,
softwareType: blankEnumValue,
languages: [],
maintenance: undefined,
maintenance: blankEnumValue,
contractNumber: [],
SBOM: "",
relatedCode: [],
Expand All @@ -56,9 +58,9 @@ const baselineCodeJSON: Partial<CodeJSON> = {
feedbackMechanism: "",
AIUseCaseID: "0",
localisation: false,
repositoryType: undefined,
repositoryType: blankEnumValue,
userInput: false,
fismaLevel: undefined,
fismaLevel: blankEnumValue,
group: "",
projects: [],
systems: [],
Expand Down Expand Up @@ -150,7 +152,7 @@ async function getMetaData(
return {
name: partialCodeJSON.name,
description: description,
status: status,
status: status ?? blankEnumValue,
repositoryURL: partialCodeJSON.repositoryURL,
repositoryVisibility: partialCodeJSON.repositoryVisibility,
laborHours: partialCodeJSON.laborHours,
Expand Down
Loading