diff --git a/src/handlers/pricing-label.ts b/src/handlers/pricing-label.ts index a75efa5..8bfffdf 100644 --- a/src/handlers/pricing-label.ts +++ b/src/handlers/pricing-label.ts @@ -141,7 +141,6 @@ async function handleExistingPriceLabel(context: Context, targetPriceLabel: stri if (labeledEvents[labeledEvents.length - 1].actor?.type == UserType.User) { logger.info(`Skipping... already exists`); } else { - await addPriceLabelToIssue(context, targetPriceLabel); } } diff --git a/tests/global-update.test.ts b/tests/global-update.test.ts index 7d537cd..40e21ef 100644 --- a/tests/global-update.test.ts +++ b/tests/global-update.test.ts @@ -63,7 +63,7 @@ describe("Label Base Rate Changes", () => { const updatedIssue = db.issue.findFirst({ where: { id: { equals: 1 } } }); const updatedIssue2 = db.issue.findFirst({ where: { id: { equals: 3 } } }); - expect(updatedRepo?.labels).toHaveLength(40); + expect(updatedRepo?.labels).toHaveLength(27); expect(updatedIssue?.labels).toHaveLength(3); expect(updatedIssue2?.labels).toHaveLength(3); @@ -82,9 +82,9 @@ describe("Label Base Rate Changes", () => { expect(infoSpy).toHaveBeenNthCalledWith(1, STRINGS.CONFIG_CHANGED_IN_COMMIT); expect(infoSpy).toHaveBeenNthCalledWith(2, STRINGS.UPDATING_FROM_1_TO_5); expect(infoSpy).toHaveBeenNthCalledWith(4, STRINGS.CREATING_MISSING_LABELS); - expect(infoSpy).toHaveBeenNthCalledWith(5, STRINGS.UPDATING_ISSUE_1_IN_TEST_REPO); - expect(infoSpy).toHaveBeenNthCalledWith(7, STRINGS.UPDATING_ISSUE_3_IN_TEST_REPO); - expect(infoSpy).toHaveBeenNthCalledWith(6, STRINGS.UPDATING_ISSUE_2_IN_TEST_REPO); + expect(infoSpy).toHaveBeenNthCalledWith(8, STRINGS.UPDATING_ISSUE_1_IN_TEST_REPO); + expect(infoSpy).toHaveBeenNthCalledWith(9, STRINGS.UPDATING_ISSUE_2_IN_TEST_REPO); + expect(infoSpy).toHaveBeenNthCalledWith(10, STRINGS.UPDATING_ISSUE_3_IN_TEST_REPO); expect(errorSpy).toHaveBeenNthCalledWith(1, STRINGS.NO_RECOGNIZED_LABELS); }); @@ -180,7 +180,7 @@ describe("Label Base Rate Changes", () => { expect(infoSpy).toHaveBeenNthCalledWith(1, STRINGS.CONFIG_CHANGED_IN_COMMIT); - expect(updatedRepo?.labels).toHaveLength(46); + expect(updatedRepo?.labels).toHaveLength(27); expect(updatedIssue?.labels).toHaveLength(3); expect(updatedIssue2?.labels).toHaveLength(3); @@ -202,9 +202,9 @@ describe("Label Base Rate Changes", () => { expect(infoSpy).toHaveBeenNthCalledWith(2, "Updating base rate from 1 to 27"); expect(infoSpy).toHaveBeenNthCalledWith(4, STRINGS.CREATING_MISSING_LABELS); - expect(infoSpy).toHaveBeenNthCalledWith(5, STRINGS.UPDATING_ISSUE_1_IN_TEST_REPO); - expect(infoSpy).toHaveBeenNthCalledWith(7, STRINGS.UPDATING_ISSUE_3_IN_TEST_REPO); - expect(infoSpy).toHaveBeenNthCalledWith(6, STRINGS.UPDATING_ISSUE_2_IN_TEST_REPO); + expect(infoSpy).toHaveBeenNthCalledWith(8, STRINGS.UPDATING_ISSUE_1_IN_TEST_REPO); + expect(infoSpy).toHaveBeenNthCalledWith(9, STRINGS.UPDATING_ISSUE_2_IN_TEST_REPO); + expect(infoSpy).toHaveBeenNthCalledWith(10, STRINGS.UPDATING_ISSUE_3_IN_TEST_REPO); expect(errorSpy).toHaveBeenCalledWith(STRINGS.NO_RECOGNIZED_LABELS); // these two are connected ^ }); @@ -236,7 +236,7 @@ describe("Label Base Rate Changes", () => { const updatedIssue = db.issue.findFirst({ where: { id: { equals: 1 } } }); const updatedIssue2 = db.issue.findFirst({ where: { id: { equals: 3 } } }); - expect(updatedRepo?.labels).toHaveLength(46); + expect(updatedRepo?.labels).toHaveLength(27); expect(updatedIssue?.labels).toHaveLength(3); expect(updatedIssue2?.labels).toHaveLength(3); @@ -252,11 +252,11 @@ describe("Label Base Rate Changes", () => { expect(infoSpy).toHaveBeenNthCalledWith(1, STRINGS.CONFIG_CHANGED_IN_COMMIT); expect(infoSpy).toHaveBeenNthCalledWith(2, "Updating base rate from 1 to 8.5"); expect(infoSpy).toHaveBeenNthCalledWith(4, STRINGS.CREATING_MISSING_LABELS); - expect(infoSpy).toHaveBeenNthCalledWith(5, STRINGS.UPDATING_ISSUE_1_IN_TEST_REPO); - expect(infoSpy).toHaveBeenNthCalledWith(7, STRINGS.UPDATING_ISSUE_3_IN_TEST_REPO); + expect(infoSpy).toHaveBeenNthCalledWith(8, STRINGS.UPDATING_ISSUE_1_IN_TEST_REPO); + expect(infoSpy).toHaveBeenNthCalledWith(9, STRINGS.UPDATING_ISSUE_2_IN_TEST_REPO); + expect(infoSpy).toHaveBeenNthCalledWith(10, STRINGS.UPDATING_ISSUE_3_IN_TEST_REPO); - expect(infoSpy).toHaveBeenNthCalledWith(6, STRINGS.UPDATING_ISSUE_2_IN_TEST_REPO); - expect(errorSpy).toHaveBeenCalledWith(STRINGS.NO_RECOGNIZED_LABELS); // these two are connected ^ + expect(errorSpy).toHaveBeenCalledWith(STRINGS.NO_RECOGNIZED_LABELS); }); it("Should not globally update excluded repos", async () => { @@ -277,28 +277,24 @@ describe("Label Base Rate Changes", () => { withPlugin: false, amount: 5, }, - pusher + pusher, + { + excludeRepos: [STRINGS.TEST_REPO], + } ); - if (!context.config.globalConfigUpdate) { - context.config.globalConfigUpdate = { - excludeRepos: [], - }; - } - context.config.globalConfigUpdate.excludeRepos = [STRINGS.TEST_REPO]; await globalLabelUpdate(context); expect(infoSpy).toHaveBeenNthCalledWith(1, STRINGS.CONFIG_CHANGED_IN_COMMIT); expect(infoSpy).toHaveBeenNthCalledWith(2, STRINGS.UPDATING_FROM_1_TO_5); - expect(infoSpy).toHaveBeenNthCalledWith(4, STRINGS.CREATING_MISSING_LABELS); - expect(infoSpy).toHaveBeenNthCalledWith(5, `Skipping excluded repository ${STRINGS.TEST_REPO}`); + expect(infoSpy).toHaveBeenCalledTimes(2); expect(errorSpy).not.toHaveBeenCalled(); }); it("Should not globally update if it's disabled", async () => { const pusher = db.users.findFirst({ where: { id: { equals: 1 } } }) as unknown as Context["payload"]["sender"]; const commits = inMemoryCommits(STRINGS.SHA_1); - const { context, infoSpy, errorSpy } = innerSetup( + const { context, infoSpy } = innerSetup( 1, commits, STRINGS.SHA_1, @@ -316,19 +312,13 @@ describe("Label Base Rate Changes", () => { pusher ); - if (!context.config.globalConfigUpdate) { - context.config.globalConfigUpdate = { - excludeRepos: [], - }; - } - context.config.globalConfigUpdate.excludeRepos = [STRINGS.TEST_REPO]; + context.config.globalConfigUpdate = undefined; await globalLabelUpdate(context); expect(infoSpy).toHaveBeenNthCalledWith(1, STRINGS.CONFIG_CHANGED_IN_COMMIT); expect(infoSpy).toHaveBeenNthCalledWith(2, STRINGS.UPDATING_FROM_1_TO_5); expect(infoSpy).toHaveBeenNthCalledWith(4, STRINGS.CREATING_MISSING_LABELS); - expect(infoSpy).toHaveBeenNthCalledWith(5, `Skipping excluded repository ${STRINGS.TEST_REPO}`); - expect(errorSpy).not.toHaveBeenCalled(); + expect(infoSpy).toHaveBeenNthCalledWith(6, "Removing incorrect price labels done"); }); it("Should not update base rate if the user is not authenticated", async () => { diff --git a/tests/main.test.ts b/tests/main.test.ts index 9732911..19b3b0e 100644 --- a/tests/main.test.ts +++ b/tests/main.test.ts @@ -41,7 +41,7 @@ describe("User tests", () => { } }); - it.only("Should not include globalConfigUpdate in defaults if omitted", () => { + it("Should not include globalConfigUpdate in defaults if omitted", () => { const settings = Value.Default(assistivePricingSettingsSchema, {}) as AssistivePricingSettings; const decodedSettings = Value.Decode(assistivePricingSettingsSchema, settings); expect(decodedSettings.globalConfigUpdate).toBeUndefined();