Skip to content

Commit

Permalink
tests: add spy method to check if extractAuthorEmail was called
Browse files Browse the repository at this point in the history
  • Loading branch information
dcshzj committed Nov 10, 2022
1 parent cd951d3 commit c333d8c
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/services/identity/__tests__/SitesService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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 () => {
Expand All @@ -607,6 +612,7 @@ describe("SitesService", () => {
// Assert
expect(actual).toBe(expected)
expect(MockUsersService.findById).not.toHaveBeenCalled()
expect(SpySitesService.extractAuthorEmail).toHaveBeenCalled()
})
})

Expand Down Expand Up @@ -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 () => {
Expand All @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -757,6 +767,7 @@ describe("SitesService", () => {
expect(
MockReviewRequestService.getLatestMergedReviewRequest
).toHaveBeenCalledWith(mockSite)
expect(SpySitesService.extractAuthorEmail).toHaveBeenCalled()
})
})

Expand Down

0 comments on commit c333d8c

Please sign in to comment.