Skip to content

Commit

Permalink
chore: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Keyrxng committed Sep 28, 2024
1 parent 9f3d388 commit 20ec24c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 33 deletions.
1 change: 0 additions & 1 deletion src/handlers/pricing-label.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
52 changes: 21 additions & 31 deletions tests/global-update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
});

Expand Down Expand Up @@ -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);

Expand All @@ -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 ^
});
Expand Down Expand Up @@ -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);

Expand All @@ -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 () => {
Expand All @@ -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,
Expand All @@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 20ec24c

Please sign in to comment.