From c333d8c9ed9174d2404da364d4dc12e206edecda Mon Sep 17 00:00:00 2001 From: Hsu Zhong Jun <27919917+dcshzj@users.noreply.github.com> Date: Thu, 10 Nov 2022 15:21:11 +0800 Subject: [PATCH] tests: add spy method to check if extractAuthorEmail was called --- src/services/identity/__tests__/SitesService.spec.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/services/identity/__tests__/SitesService.spec.ts b/src/services/identity/__tests__/SitesService.spec.ts index 7b6f8809c..c9d0037dc 100644 --- a/src/services/identity/__tests__/SitesService.spec.ts +++ b/src/services/identity/__tests__/SitesService.spec.ts @@ -84,6 +84,10 @@ const SitesService = new _SitesService({ reviewRequestService: (MockReviewRequestService as unknown) as ReviewRequestService, }) +const SpySitesService = { + extractAuthorEmail: jest.spyOn(SitesService, "extractAuthorEmail"), +} + const mockSiteName = "some site name" const mockSite = ({ name: "i m a site", @@ -587,6 +591,7 @@ describe("SitesService", () => { // Assert expect(actual).toBe(expected) expect(MockUsersService.findById).toHaveBeenCalledWith(mockIsomerUserId) + expect(SpySitesService.extractAuthorEmail).not.toHaveBeenCalled() }) it("should return the email of the commit author who is a GitHub login user", async () => { @@ -607,6 +612,7 @@ describe("SitesService", () => { // Assert expect(actual).toBe(expected) expect(MockUsersService.findById).not.toHaveBeenCalled() + expect(SpySitesService.extractAuthorEmail).toHaveBeenCalled() }) }) @@ -634,6 +640,7 @@ describe("SitesService", () => { expect( MockReviewRequestService.getLatestMergedReviewRequest ).not.toHaveBeenCalled() + expect(SpySitesService.extractAuthorEmail).toHaveBeenCalled() }) it("should return the email of the merge commit author if the site cannot be found", async () => { @@ -660,6 +667,7 @@ describe("SitesService", () => { expect( MockReviewRequestService.getLatestMergedReviewRequest ).not.toHaveBeenCalled() + expect(SpySitesService.extractAuthorEmail).toHaveBeenCalled() }) it("should return the email of the merge commit author if there are no merged review requests", async () => { @@ -689,6 +697,7 @@ describe("SitesService", () => { expect( MockReviewRequestService.getLatestMergedReviewRequest ).toHaveBeenCalledWith(mockSite) + expect(SpySitesService.extractAuthorEmail).toHaveBeenCalled() }) it("should return the email of the requestor for the latest merged review request", async () => { @@ -723,6 +732,7 @@ describe("SitesService", () => { expect( MockReviewRequestService.getLatestMergedReviewRequest ).toHaveBeenCalledWith(mockSite) + expect(SpySitesService.extractAuthorEmail).not.toHaveBeenCalled() }) it("should return the email of the merge commit author if the requestor for the latest merged review request does not have an email", async () => { @@ -757,6 +767,7 @@ describe("SitesService", () => { expect( MockReviewRequestService.getLatestMergedReviewRequest ).toHaveBeenCalledWith(mockSite) + expect(SpySitesService.extractAuthorEmail).toHaveBeenCalled() }) })