Skip to content

Commit

Permalink
chore: add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Keyrxng committed Jul 27, 2024
1 parent 69ed987 commit 5c01247
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/handlers/experience-gate/xp-gate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export async function handleExperienceChecks(context: Context) {
} = context;

if (!experience) {
logger.error("Experience checks are disabled");
return;
logger.info("Experience checks are disabled");
return true;
}

if (!(await accountAgeHandler(context))) {
Expand Down
70 changes: 49 additions & 21 deletions tests/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,20 @@ describe("User start/stop", () => {
}
}
});


test("User can't start an issue if they don't pass the experience checks", async () => {
const issue = db.issue.findFirst({ where: { id: { equals: 1 } } }) as unknown as Issue;
const sender = db.users.findFirst({ where: { id: { equals: 1 } } }) as unknown as Sender;


const context = createContext(issue, sender, "/start", true, true, true, false);
const warnSpy = jest.spyOn(context.logger, "error");
await userStartStop(context);

expect(warnSpy).toHaveBeenNthCalledWith(1, "ubiquity has less than required 50% experience with solidity");
expect(warnSpy).toHaveBeenNthCalledWith(2, "You do not meet the requirements to start this issue.");
});
});

async function setupTests() {
Expand Down Expand Up @@ -384,7 +398,7 @@ async function setupTests() {
});
}

function createContext(issue: Record<string, unknown>, sender: Record<string, unknown>, body = "/start", isEnabled = true, withData = true) {
function createContext(issue: Record<string, unknown>, sender: Record<string, unknown>, body = "/start", isEnabled = true, withData = true, experience = false, passXp = true) {
const ctx: Context = {
adapters: {} as ReturnType<typeof createAdapters>,
payload: {
Expand All @@ -407,17 +421,31 @@ function createContext(issue: Record<string, unknown>, sender: Record<string, un
maxConcurrentTasks: 3,
startRequiresWallet: true,
},
experience: {
minAccountAgeInDays: 0,
mostImportantLanguage: { Typescript: 0 },
languages: { Solidity: 0 },
statThresholds: {
stars: 0,
minCommitsThisYear: 0,
prs: 0,
issues: 0,
},
},
experience: experience ?
passXp ?
{
minAccountAgeInDays: 365,
mostImportantLanguage: { Typescript: 30 },
languages: { Solidity: 15 },
statThresholds: {
stars: 15,
minCommitsThisYear: 150,
prs: 50,
issues: 2,
},
} : {
minAccountAgeInDays: 365,
mostImportantLanguage: { Solidity: 50 },
languages: { Typescript: 30 },
statThresholds: {
stars: 15,
minCommitsThisYear: 150,
prs: 50,
issues: 2,
},
}

: undefined,
},
octokit: new octokit.Octokit(),
eventName: "issue_comment.created" as SupportedEventsU,
Expand All @@ -443,17 +471,17 @@ function getSupabase(withData = true) {
single: jest.fn().mockResolvedValue({
data: withData
? {
id: 1,
wallets: {
address: "0x123",
},
}
id: 1,
wallets: {
address: "0x123",
},
}
: {
id: 1,
wallets: {
address: undefined,
},
id: 1,
wallets: {
address: undefined,
},
},
}),
}),
}),
Expand Down

0 comments on commit 5c01247

Please sign in to comment.