Skip to content

Commit 39d5274

Browse files
committed
change that introduces fix to issue 107
1 parent 4da25dd commit 39d5274

2 files changed

Lines changed: 34 additions & 8 deletions

File tree

src/__tests__/unit/main.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,30 @@ describe("runWithDeps", () => {
152152
expect(deps.setOutput).toHaveBeenCalledWith("method_used", "pull_request");
153153
});
154154

155+
it("includes enum keys in the generated blank code.json", async () => {
156+
process.env.GITHUB_EVENT_NAME = "schedule";
157+
158+
const deps = createMockDeps({
159+
readFile: jest.fn<any>().mockRejectedValue(new Error("no file")),
160+
skipPR: false,
161+
});
162+
163+
await runWithDeps(deps);
164+
165+
const createPullRequestMock = deps.octokit.createPullRequest as jest.Mock;
166+
const pullRequestArgs = createPullRequestMock.mock.calls[0][0] as any;
167+
const codeJSONContent = pullRequestArgs.changes[0].files["code.json"];
168+
const generatedCodeJSON = JSON.parse(codeJSONContent);
169+
170+
expect(generatedCodeJSON).toHaveProperty("status");
171+
expect(generatedCodeJSON).toHaveProperty("repositoryHost");
172+
expect(generatedCodeJSON).toHaveProperty("repositoryVisibility");
173+
expect(generatedCodeJSON).toHaveProperty("softwareType");
174+
expect(generatedCodeJSON).toHaveProperty("maintenance");
175+
expect(generatedCodeJSON).toHaveProperty("repositoryType");
176+
expect(generatedCodeJSON).toHaveProperty("fismaLevel");
177+
});
178+
155179
it("attempts direct push when skipPR is true with admin token", async () => {
156180
process.env.GITHUB_EVENT_NAME = "workflow_dispatch";
157181

src/main.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ import { Dependencies } from "./types/Dependencies.js";
33
import { createHelpers, Helpers } from "./helper.js";
44
import { createProductionDeps } from "./create-deps.js";
55

6+
const blankEnumValue = "" as never;
7+
68
const baselineCodeJSON: Partial<CodeJSON> = {
79
name: "",
810
version: "",
911
description: "",
1012
longDescription: "",
11-
status: undefined,
13+
status: blankEnumValue,
1214
permissions: {
1315
licenses: [
1416
{
@@ -21,8 +23,8 @@ const baselineCodeJSON: Partial<CodeJSON> = {
2123
},
2224
organization: "Centers for Medicare & Medicaid Services",
2325
repositoryURL: "",
24-
repositoryHost: undefined,
25-
repositoryVisibility: undefined,
26+
repositoryHost: blankEnumValue,
27+
repositoryVisibility: blankEnumValue,
2628
homepageURL: "",
2729
downloadURL: "",
2830
disclaimerURL: "",
@@ -35,9 +37,9 @@ const baselineCodeJSON: Partial<CodeJSON> = {
3537
},
3638
platforms: [],
3739
categories: [],
38-
softwareType: undefined,
40+
softwareType: blankEnumValue,
3941
languages: [],
40-
maintenance: undefined,
42+
maintenance: blankEnumValue,
4143
contractNumber: [],
4244
SBOM: "",
4345
relatedCode: [],
@@ -56,9 +58,9 @@ const baselineCodeJSON: Partial<CodeJSON> = {
5658
feedbackMechanism: "",
5759
AIUseCaseID: "0",
5860
localisation: false,
59-
repositoryType: undefined,
61+
repositoryType: blankEnumValue,
6062
userInput: false,
61-
fismaLevel: undefined,
63+
fismaLevel: blankEnumValue,
6264
group: "",
6365
projects: [],
6466
systems: [],
@@ -151,7 +153,7 @@ async function getMetaData(
151153
return {
152154
name: partialCodeJSON.name,
153155
description: description,
154-
status: status,
156+
status: status ?? blankEnumValue,
155157
repositoryURL: partialCodeJSON.repositoryURL,
156158
repositoryVisibility: partialCodeJSON.repositoryVisibility,
157159
laborHours: partialCodeJSON.laborHours,

0 commit comments

Comments
 (0)