Skip to content

Commit

Permalink
fix(test): resolve promises
Browse files Browse the repository at this point in the history
  • Loading branch information
0x4007 committed Feb 27, 2024
1 parent 1d62274 commit 9d57104
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
6 changes: 2 additions & 4 deletions src/get-activity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ process.argv = ["path/to/node", "path/to/script", `--auth=${GITHUB_TOKEN}`];
describe("GetActivity class", () => {
const issue22 = parseGitHubUrl("https://github.com/ubiquibot/comment-incentives/issues/22");
const activity = new GetActivity(issue22);

beforeAll(async () => {
await activity.init();
});
beforeAll(async () => await activity.init());

it("should resolve all promises", async () => {
await activity.init();
Expand All @@ -25,6 +22,7 @@ describe("GetActivity class", () => {
expect(activity.events).toBeTruthy();
expect(activity.comments).toBeTruthy();
expect(Array.isArray(activity.linkedReviews)).toBeTruthy();
console.dir(activity.linkedReviews, { depth: 4, colors: true });
});

it("should create an instance of GetActivity", () => {
Expand Down
9 changes: 6 additions & 3 deletions src/get-activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,18 @@ export class GetActivity {
}

class Review {
self: Promise<GitHubPullRequest> | null = null;
reviews: Promise<GitHubPullRequestReview[]> | null = null;
reviewComments: Promise<GitHubPullRequestReviewComment[]> | null = null;
self: Promise<GitHubPullRequest> | GitHubPullRequest | null = null;
reviews: Promise<GitHubPullRequestReview[]> | GitHubPullRequestReview[] | null = null;
reviewComments: Promise<GitHubPullRequestReviewComment[]> | GitHubPullRequestReviewComment[] | null = null;

constructor(private _pullParams: PullParams) {}

async init() {
this.self = getPullRequest(this._pullParams);
this.reviews = getPullRequestReviews(this._pullParams);
this.reviewComments = getPullRequestReviewComments(this._pullParams);

// Wait for all promises to resolve
[this.self, this.reviews, this.reviewComments] = await Promise.all([this.self, this.reviews, this.reviewComments]);
}
}

0 comments on commit 9d57104

Please sign in to comment.