Skip to content

Commit

Permalink
chore: merge changes
Browse files Browse the repository at this point in the history
  • Loading branch information
gentlementlegen committed Sep 1, 2024
1 parent 615d16a commit 68890ac
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 45 deletions.
41 changes: 12 additions & 29 deletions tests/__mocks__/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@ export const handlers = [
}
return HttpResponse.json(item);
}),
//get member
http.get("https://api.github.com/orgs/:org/memberships/:username", ({ params: { username } }) => {
const user = db.users.findFirst({ where: { login: { equals: username as string } } });
if (user) {
return HttpResponse.json({ role: user.role });
} else {
return HttpResponse.json({ role: "collaborator" });
}
}),
// get issue
http.get("https://api.github.com/repos/:owner/:repo/issues", ({ params: { owner, repo } }: { params: { owner: string; repo: string } }) =>
HttpResponse.json(db.issue.findMany({ where: { owner: { equals: owner }, repo: { equals: repo } } }))
Expand All @@ -43,25 +34,21 @@ export const handlers = [
HttpResponse.json({ owner, repo, issueNumber })
),
// get commit
http.get("https://api.github.com/repos/:owner/:repo/commits/:ref", () =>
HttpResponse.json({
http.get("https://api.github.com/repos/:owner/:repo/commits/:ref", () => {
const res = {
data: {
sha: "commitHash",
},
})
),
};

return HttpResponse.json(res);
}),
// list pull requests
http.get("https://api.github.com/repos/:owner/:repo/pulls", ({ params: { owner, repo } }: { params: { owner: string; repo: string } }) =>
HttpResponse.json(db.pull.findMany({ where: { owner: { equals: owner }, repo: { equals: repo } } }))
),
// list events for an issue timeline
http.get("https://api.github.com/repos/:owner/:repo/issues/:issue_number/timeline", ({ params: { owner, repo, issue_number: issueNumber } }) => {
return HttpResponse.json(
db.event.findMany({
where: { owner: { equals: owner as string }, repo: { equals: repo as string }, issue_number: { equals: Number(issueNumber) } },
})
);
}),
http.get("https://api.github.com/repos/:owner/:repo/issues/:issue_number/timeline", () => HttpResponse.json(db.event.getAll())),
// update a pull request
http.patch("https://api.github.com/repos/:owner/:repo/pulls/:pull_number", ({ params: { owner, repo, pull_number: pullNumber } }) =>
HttpResponse.json({ owner, repo, pullNumber })
Expand Down Expand Up @@ -106,16 +93,12 @@ export const handlers = [
http.delete("https://api.github.com/repos/:owner/:repo/issues/:issue_number/assignees", ({ params: { owner, repo, issue_number: issueNumber } }) =>
HttpResponse.json({ owner, repo, issueNumber })
),
http.get("https://api.github.com/search/issues", ({ request }) => {
const params = new URL(request.url).searchParams;
const query = params.get("q");
const hasAssignee = query?.includes("assignee");
if (hasAssignee) {
return HttpResponse.json(db.issue.getAll());
} else {
return HttpResponse.json(db.pull.getAll());
}
// search issues
http.get("https://api.github.com/search/issues", () => {
const issues = [db.issue.findFirst({ where: { number: { equals: 1 } } })];
return HttpResponse.json({ items: issues });
}),
// get issue by number
http.get("https://api.github.com/repos/:owner/:repo/issues/:issue_number", ({ params: { owner, repo, issue_number: issueNumber } }) =>
HttpResponse.json(
db.issue.findFirst({
Expand Down
19 changes: 3 additions & 16 deletions tests/__mocks__/users-get.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,14 @@
[
{
"id": 1,
"login": "ubiquity",
"role": "admin"
"login": "ubiquity"
},
{
"id": 2,
"login": "user2",
"role": "contributor"
"login": "user2"
},
{
"id": 3,
"login": "user3",
"role": "collaborator"
},
{
"id": 4,
"login": "user4",
"role": "new-start"
},
{
"id": 5,
"login": "user5",
"role": "member"
"login": "user3"
}
]

0 comments on commit 68890ac

Please sign in to comment.