Skip to content

Commit

Permalink
Merge pull request #165 from paritytech/rzadp/test
Browse files Browse the repository at this point in the history
Allow for more permissive user input
  • Loading branch information
mutantcornholio authored Aug 13, 2024
2 parents c5e4bc9 + d36b2d3 commit 3b85019
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/bot-handle-comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export const handleTipRequest = async (
return { success: false, errorMessage: `@${contributorLogin} ${contributorAccount.error}` };
}

const tipSize = getTipSize(tipSizeInput);
const tipSize = getTipSize(tipSizeInput?.trim());
if (typeof tipSize == "object" && "error" in tipSize) {
return { success: false, errorMessage: `@${tipRequester} ${tipSize.error}` };
}
Expand Down
31 changes: 31 additions & 0 deletions src/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,37 @@ describe("Utility functions", () => {
expect(result.address).toEqual(address);
});

test("allows uppercase", () => {
const address = randomAddress();
const result = parseContributorAccount([`Kusama Address: ${address}`]);
if ("error" in result) {
throw new Error(result.error);
}
expect(result.network).toEqual("kusama");
expect(result.address).toEqual(address);
});

test("allows whitespace", () => {
const address = randomAddress();
const result = parseContributorAccount([`\nkusama Address: ${address}\n\n`]);
if ("error" in result) {
throw new Error(result.error);
}
expect(result.network).toEqual("kusama");
expect(result.address).toEqual(address);
});

// Some people naturally put backticks aronud the address.
test("allows backticks around the address", () => {
const address = randomAddress();
const result = parseContributorAccount([`Kusama Address: \`${address}\``]);
if ("error" in result) {
throw new Error(result.error);
}
expect(result.network).toEqual("kusama");
expect(result.address).toEqual(address);
});

test("Returns error message when cannot parse", () => {
const address = randomAddress();
const result = parseContributorAccount([`kusama: ${address}`]);
Expand Down
2 changes: 1 addition & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export function parseContributorAccount(bodys: (string | null)[]): ContributorAc
typeof body === "string" &&
body.match(
// match "polkadot address: <ADDRESS>"
/(\S+)\s*address:\s*([a-z0-9]+)/i,
/(\S+)\s*address:\s*`?([a-z0-9]+)`?/i,
);

if (matches === false || matches === null || matches.length != 3) {
Expand Down

0 comments on commit 3b85019

Please sign in to comment.