-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: add unit tests for ReviewRequestService (#569)
* chore: remove TODO comment as it is already done * fix: should get the count of unread comments instead * tests: add ReviewRequestService unit tests * chore: move tests back to identity services * chore: remove unused variable * chore: adjust naming of test to be clearer on the situation
- Loading branch information
1 parent
b0076b0
commit 77d780d
Showing
7 changed files
with
1,285 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import { Attributes } from "sequelize/types" | ||
|
||
import { User, SiteMember } from "@database/models" | ||
import { Author } from "@root/types/github" | ||
|
||
import { mockIsomerUserId } from "./sessionData" | ||
|
||
|
@@ -18,18 +19,24 @@ export const mockHeaders = { | |
} | ||
export const mockSiteName = "hello world" | ||
export const mockUserId = "some user id" | ||
export const mockSiteId = "16" | ||
|
||
export const mockBearerTokenHeaders = { | ||
headers: { | ||
Authorization: `Bearer ${process.env.POSTMAN_API_KEY}`, | ||
}, | ||
} | ||
|
||
const mockCollaboratorContributor1: Attributes<User> & { | ||
export const MOCK_IDENTITY_EMAIL_ONE = "[email protected]" | ||
export const MOCK_IDENTITY_EMAIL_TWO = "[email protected]" | ||
export const MOCK_IDENTITY_EMAIL_THREE = "[email protected]" | ||
export const MOCK_IDENTITY_EMAIL_FOUR = "[email protected]" | ||
|
||
export const mockCollaboratorContributor1: Attributes<User> & { | ||
SiteMember: Attributes<SiteMember> | ||
} = { | ||
id: 1, | ||
email: "[email protected]", | ||
email: MOCK_IDENTITY_EMAIL_ONE, | ||
githubId: "test1", | ||
contactNumber: "12331231", | ||
lastLoggedIn: new Date("2022-07-30T07:41:09.661Z"), | ||
|
@@ -38,19 +45,19 @@ const mockCollaboratorContributor1: Attributes<User> & { | |
deletedAt: undefined, | ||
SiteMember: { | ||
userId: 1, | ||
siteId: "16", | ||
siteId: mockSiteId, | ||
role: "CONTRIBUTOR", | ||
createdAt: new Date("2022-07-29T03:50:49.145Z"), | ||
updatedAt: new Date("2022-07-29T03:50:49.145Z"), | ||
}, | ||
sites: [], | ||
} | ||
|
||
const mockCollaboratorAdmin1: Attributes<User> & { | ||
export const mockCollaboratorAdmin1: Attributes<User> & { | ||
SiteMember: Attributes<SiteMember> | ||
} = { | ||
id: 2, | ||
email: "[email protected]", | ||
email: MOCK_IDENTITY_EMAIL_TWO, | ||
githubId: "test2", | ||
contactNumber: "12331232", | ||
lastLoggedIn: new Date("2022-07-30T07:41:09.661Z"), | ||
|
@@ -59,18 +66,18 @@ const mockCollaboratorAdmin1: Attributes<User> & { | |
deletedAt: undefined, | ||
SiteMember: { | ||
userId: 2, | ||
siteId: "16", | ||
siteId: mockSiteId, | ||
role: "ADMIN", | ||
createdAt: new Date("2022-07-29T03:50:49.145Z"), | ||
updatedAt: new Date("2022-07-29T03:50:49.145Z"), | ||
}, | ||
sites: [], | ||
} | ||
const mockCollaboratorAdmin2: Attributes<User> & { | ||
export const mockCollaboratorAdmin2: Attributes<User> & { | ||
SiteMember: Attributes<SiteMember> | ||
} = { | ||
id: 3, | ||
email: "[email protected]", | ||
email: MOCK_IDENTITY_EMAIL_THREE, | ||
githubId: "test3", | ||
contactNumber: "12331233", | ||
lastLoggedIn: new Date("2022-06-30T07:41:09.661Z"), | ||
|
@@ -79,18 +86,18 @@ const mockCollaboratorAdmin2: Attributes<User> & { | |
deletedAt: undefined, | ||
SiteMember: { | ||
userId: 3, | ||
siteId: "16", | ||
siteId: mockSiteId, | ||
role: "ADMIN", | ||
createdAt: new Date("2022-07-29T03:50:49.145Z"), | ||
updatedAt: new Date("2022-07-29T03:50:49.145Z"), | ||
}, | ||
sites: [], | ||
} | ||
const mockCollaboratorContributor2: Attributes<User> & { | ||
export const mockCollaboratorContributor2: Attributes<User> & { | ||
SiteMember: Attributes<SiteMember> | ||
} = { | ||
id: 4, | ||
email: "[email protected]", | ||
email: MOCK_IDENTITY_EMAIL_FOUR, | ||
githubId: "test4", | ||
contactNumber: "12331234", | ||
lastLoggedIn: new Date("2022-07-30T07:41:09.661Z"), | ||
|
@@ -99,7 +106,7 @@ const mockCollaboratorContributor2: Attributes<User> & { | |
deletedAt: undefined, | ||
SiteMember: { | ||
userId: 4, | ||
siteId: "16", | ||
siteId: mockSiteId, | ||
role: "CONTRIBUTOR", | ||
createdAt: new Date("2022-07-29T03:50:49.145Z"), | ||
updatedAt: new Date("2022-07-29T03:50:49.145Z"), | ||
|
@@ -143,6 +150,7 @@ export const mockSiteOrmResponseWithNoCollaborators = { | |
|
||
export const MOCK_COMMIT_MESSAGE_ONE = "Update file: Example.md" | ||
export const MOCK_COMMIT_FILENAME_ONE = "Example.md" | ||
export const MOCK_COMMIT_FILEPATH_ONE = "test/path/one/" | ||
export const MOCK_GITHUB_NAME_ONE = "testuser" | ||
export const MOCK_GITHUB_EMAIL_ADDRESS_ONE = "[email protected]" | ||
export const MOCK_GITHUB_DATE_ONE = "2022-09-22T04:07:53Z" | ||
|
@@ -154,6 +162,7 @@ export const MOCK_COMMIT_MESSAGE_OBJECT_ONE = { | |
|
||
export const MOCK_COMMIT_MESSAGE_TWO = "Update file: Test.md" | ||
export const MOCK_COMMIT_FILENAME_TWO = "Test.md" | ||
export const MOCK_COMMIT_FILEPATH_TWO = "test/path/two/" | ||
export const MOCK_GITHUB_NAME_TWO = "testuser2" | ||
export const MOCK_GITHUB_EMAIL_ADDRESS_TWO = "[email protected]" | ||
export const MOCK_GITHUB_DATE_TWO = "2022-09-28T06:25:14Z" | ||
|
@@ -163,4 +172,30 @@ export const MOCK_COMMIT_MESSAGE_OBJECT_TWO = { | |
userId: mockIsomerUserId, | ||
} | ||
|
||
export const MOCK_GITHUB_COMMIT_AUTHOR_ONE: Author = { | ||
name: MOCK_GITHUB_NAME_ONE, | ||
email: MOCK_GITHUB_EMAIL_ADDRESS_ONE, | ||
date: MOCK_GITHUB_DATE_ONE, | ||
} | ||
|
||
export const MOCK_GITHUB_COMMIT_AUTHOR_TWO: Author = { | ||
name: MOCK_GITHUB_NAME_TWO, | ||
email: MOCK_GITHUB_EMAIL_ADDRESS_TWO, | ||
date: MOCK_GITHUB_DATE_TWO, | ||
} | ||
|
||
export const MOCK_GITHUB_COMMENT_ONE = "test comment 1" | ||
export const MOCK_GITHUB_COMMENT_DATA_ONE = { | ||
userId: mockIsomerUserId, | ||
message: MOCK_GITHUB_COMMENT_ONE, | ||
createdAt: MOCK_GITHUB_DATE_ONE, | ||
} | ||
|
||
export const MOCK_GITHUB_COMMENT_TWO = "test comment 2" | ||
export const MOCK_GITHUB_COMMENT_DATA_TWO = { | ||
userId: mockIsomerUserId, | ||
message: MOCK_GITHUB_COMMENT_TWO, | ||
createdAt: MOCK_GITHUB_DATE_TWO, | ||
} | ||
|
||
export const MOCK_COMMON_ACCESS_TOKEN_GITHUB_NAME = "isomergithub1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { Attributes } from "sequelize/types" | ||
|
||
import { ReviewRequestStatus } from "@root/constants" | ||
import { ReviewRequest, ReviewRequestView } from "@root/database/models" | ||
import { Commit } from "@root/types/github" | ||
|
||
import { | ||
mockCollaboratorAdmin1, | ||
mockCollaboratorAdmin2, | ||
mockCollaboratorContributor1, | ||
MOCK_COMMIT_FILEPATH_TWO, | ||
MOCK_COMMIT_MESSAGE_OBJECT_ONE, | ||
MOCK_COMMIT_MESSAGE_OBJECT_TWO, | ||
MOCK_GITHUB_COMMIT_AUTHOR_ONE, | ||
MOCK_GITHUB_COMMIT_AUTHOR_TWO, | ||
MOCK_GITHUB_DATE_ONE, | ||
} from "./identity" | ||
|
||
export const MOCK_PULL_REQUEST_FILE_FILENAME_ONE = "file1.txt" | ||
export const MOCK_PULL_REQUEST_FILE_CONTENTSURL_ONE = | ||
"https://api.github.com/repos/octocat/Hello-World/contents/file1.txt?ref=6dcb09b5b57875f334f61aebed695e2e4193db5e" | ||
export const MOCK_PULL_REQUEST_FILE_FILENAME_TWO = "file2.txt" | ||
export const MOCK_PULL_REQUEST_FILE_CONTENTSURL_TWO = | ||
"https://api.github.com/repos/octocat/Hello-World/contents/file2.txt?ref=bbcd538c8e72b8c175046e27cc8f907076331401" | ||
|
||
export const MOCK_PULL_REQUEST_FILECHANGEINFO_ONE = { | ||
filename: MOCK_PULL_REQUEST_FILE_FILENAME_ONE, | ||
contents_url: MOCK_PULL_REQUEST_FILE_CONTENTSURL_ONE, | ||
} | ||
export const MOCK_PULL_REQUEST_FILECHANGEINFO_TWO = { | ||
filename: `${MOCK_COMMIT_FILEPATH_TWO}/${MOCK_PULL_REQUEST_FILE_FILENAME_TWO}`, | ||
contents_url: MOCK_PULL_REQUEST_FILE_CONTENTSURL_TWO, | ||
} | ||
|
||
export const MOCK_PULL_REQUEST_COMMIT_SHA_ONE = | ||
"6dcb09b5b57875f334f61aebed695e2e4193db5e" | ||
export const MOCK_PULL_REQUEST_COMMIT_SHA_TWO = | ||
"bbcd538c8e72b8c175046e27cc8f907076331401" | ||
|
||
export const MOCK_PULL_REQUEST_COMMIT_ONE: Commit = { | ||
sha: MOCK_PULL_REQUEST_COMMIT_SHA_ONE, | ||
url: "fakeUrl", | ||
commit: { | ||
url: "fakeUrl", | ||
author: MOCK_GITHUB_COMMIT_AUTHOR_ONE, | ||
message: JSON.stringify(MOCK_COMMIT_MESSAGE_OBJECT_ONE), | ||
}, | ||
} | ||
export const MOCK_PULL_REQUEST_COMMIT_TWO: Commit = { | ||
sha: MOCK_PULL_REQUEST_COMMIT_SHA_TWO, | ||
url: "fakeUrl", | ||
commit: { | ||
url: "fakeUrl", | ||
author: MOCK_GITHUB_COMMIT_AUTHOR_TWO, | ||
message: JSON.stringify(MOCK_COMMIT_MESSAGE_OBJECT_TWO), | ||
}, | ||
} | ||
|
||
export const MOCK_PULL_REQUEST_ONE = { | ||
title: "Pull Request 1", | ||
body: "Pull Request 1 Description", | ||
changed_files: 3, | ||
created_at: MOCK_GITHUB_DATE_ONE, | ||
} | ||
|
||
export const MOCK_REVIEW_REQUEST_ONE: Attributes<ReviewRequest> = { | ||
id: 1, | ||
site: { | ||
name: "Test Site 1", | ||
}, | ||
requestor: mockCollaboratorContributor1, | ||
reviewMeta: { | ||
id: 1, | ||
pullRequestNumber: 1, | ||
reviewLink: "fakeUrl", | ||
}, | ||
reviewStatus: ReviewRequestStatus.Open, | ||
reviewers: [mockCollaboratorAdmin1, mockCollaboratorAdmin2], | ||
} | ||
|
||
export const MOCK_REVIEW_REQUEST_VIEW_ONE: Attributes<ReviewRequestView> = { | ||
id: 1, | ||
reviewRequestId: 1, | ||
lastViewedAt: new Date("2022-09-23T00:00:00Z"), | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.