-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: add integration tests for review requests and comments (#576)
* fix: force tests to run sequentially * fix: reset the state of the tables before running the tests * feat: add fixtures used for review requests * fix: await results from IdentityService * tests: add partial integration tests for review requests * chore: switch site name to use repo name instead * chore: switch to using variable for file name * chore: standardise the response codes for non-happy paths * fix: add additional sanity checks for comments-related features * tests: add remaining integration tests for review requests * fix: add methods to generate router for default values * chore: rename test to be more reflective of its purpose * fix: add missing return and await when updating database * chore: add comment on the need for Table.sync
- Loading branch information
1 parent
84f2460
commit ef629a7
Showing
10 changed files
with
2,354 additions
and
19 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
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,139 @@ | ||
import { Commit, RawComment, RawFileChangeInfo } from "@root/types/github" | ||
|
||
import { MOCK_USER_ID_ONE, MOCK_USER_ID_TWO } from "./users" | ||
|
||
export const MOCK_GITHUB_USER_NAME_ONE = "isomergithub1" | ||
export const MOCK_GITHUB_USER_NAME_TWO = "isomergithub2" | ||
|
||
export const MOCK_GITHUB_USER_EMAIL_ONE = | ||
"111718653+isomergithub1@users.noreply.github.com" | ||
export const MOCK_GITHUB_USER_EMAIL_TWO = | ||
"111725612+isomergithub2@users.noreply.github.com" | ||
|
||
export const MOCK_GITHUB_PULL_REQUEST_NUMBER = 251 | ||
|
||
// This is one set of commits and file changes which should be used together | ||
export const MOCK_GITHUB_COMMIT_SHA_LATEST_ALPHA = | ||
"a15a7c8b23324f680cd7c5011ca763e36d350f41" | ||
export const MOCK_GITHUB_COMMIT_DATE_ONE = "2022-10-12T06:31:05Z" | ||
export const MOCK_GITHUB_COMMIT_DATE_TWO = "2022-10-13T05:39:43Z" | ||
export const MOCK_GITHUB_COMMIT_DATE_THREE = "2022-11-07T16:32:08Z" | ||
export const MOCK_GITHUB_FILENAME_ALPHA_ONE = "index.md" | ||
export const MOCK_GITHUB_FILEPATH_ALPHA_ONE = "" | ||
export const MOCK_GITHUB_FULL_FILEPATH_ALPHA_ONE = encodeURIComponent( | ||
MOCK_GITHUB_FILENAME_ALPHA_ONE | ||
) | ||
export const MOCK_GITHUB_FILENAME_ALPHA_TWO = "Example Title 22.md" | ||
export const MOCK_GITHUB_FILEPATH_ALPHA_TWO = "pages/" | ||
export const MOCK_GITHUB_FULL_FILEPATH_ALPHA_TWO = encodeURIComponent( | ||
MOCK_GITHUB_FILEPATH_ALPHA_TWO + MOCK_GITHUB_FILENAME_ALPHA_TWO | ||
) | ||
export const MOCK_GITHUB_COMMIT_MESSAGE_ALPHA_ONE = `Update file: ${MOCK_GITHUB_FILENAME_ALPHA_ONE}` | ||
export const MOCK_GITHUB_COMMIT_MESSAGE_ALPHA_TWO = `Update file: ${MOCK_GITHUB_FILENAME_ALPHA_TWO}` | ||
export const MOCK_GITHUB_COMMIT_MESSAGE_OBJECT_ALPHA_ONE = { | ||
message: MOCK_GITHUB_COMMIT_MESSAGE_ALPHA_ONE, | ||
fileName: MOCK_GITHUB_FILENAME_ALPHA_ONE, | ||
userId: MOCK_USER_ID_ONE, | ||
} | ||
export const MOCK_GITHUB_COMMIT_MESSAGE_OBJECT_ALPHA_TWO = { | ||
message: MOCK_GITHUB_COMMIT_MESSAGE_ALPHA_TWO, | ||
fileName: MOCK_GITHUB_FILENAME_ALPHA_TWO, | ||
userId: MOCK_USER_ID_ONE, | ||
} | ||
export const MOCK_GITHUB_COMMIT_MESSAGE_OBJECT_ALPHA_THREE = { | ||
message: MOCK_GITHUB_COMMIT_MESSAGE_ALPHA_TWO, | ||
fileName: MOCK_GITHUB_FILENAME_ALPHA_TWO, | ||
userId: MOCK_USER_ID_TWO, | ||
} | ||
|
||
export const MOCK_GITHUB_FILE_CHANGE_INFO_ALPHA_ONE: RawFileChangeInfo = { | ||
sha: "66804d21ba86f1a193c31714bc15e388c2013a57", | ||
filename: MOCK_GITHUB_FILENAME_ALPHA_ONE, | ||
status: "modified", | ||
additions: 1, | ||
deletions: 2, | ||
changes: 3, | ||
blob_url: `https://github.com/isomerpages/a-test-v4/blob/${MOCK_GITHUB_COMMIT_SHA_LATEST_ALPHA}/${MOCK_GITHUB_FULL_FILEPATH_ALPHA_ONE}`, | ||
raw_url: `https://github.com/isomerpages/a-test-v4/raw/${MOCK_GITHUB_COMMIT_SHA_LATEST_ALPHA}/${MOCK_GITHUB_FULL_FILEPATH_ALPHA_ONE}`, | ||
contents_url: `https://api.github.com/repos/isomerpages/a-test-v4/contents/${MOCK_GITHUB_FULL_FILEPATH_ALPHA_ONE}?ref=${MOCK_GITHUB_COMMIT_SHA_LATEST_ALPHA}`, | ||
} | ||
export const MOCK_GITHUB_FILE_CHANGE_INFO_ALPHA_TWO: RawFileChangeInfo = { | ||
sha: "f04f18eaa8d31fffc9f8cf5020b1f6a765ac225f", | ||
filename: `${MOCK_GITHUB_FILEPATH_ALPHA_TWO}${MOCK_GITHUB_FILENAME_ALPHA_TWO}`, | ||
status: "modified", | ||
additions: 13, | ||
deletions: 2, | ||
changes: 15, | ||
blob_url: `https://github.com/isomerpages/a-test-v4/blob/${MOCK_GITHUB_COMMIT_SHA_LATEST_ALPHA}/${MOCK_GITHUB_FULL_FILEPATH_ALPHA_TWO}`, | ||
raw_url: `https://github.com/isomerpages/a-test-v4/raw/${MOCK_GITHUB_COMMIT_SHA_LATEST_ALPHA}/${MOCK_GITHUB_FULL_FILEPATH_ALPHA_TWO}`, | ||
contents_url: `https://api.github.com/repos/isomerpages/a-test-v4/contents/${MOCK_GITHUB_FULL_FILEPATH_ALPHA_TWO}?ref=${MOCK_GITHUB_COMMIT_SHA_LATEST_ALPHA}`, | ||
} | ||
|
||
export const MOCK_GITHUB_COMMIT_ALPHA_ONE: Commit = { | ||
url: | ||
"https://api.github.com/repos/isomerpages/a-test-v4/commits/a79525f0d188880b965053bc0df25a041b476fad", | ||
sha: "a79525f0d188880b965053bc0df25a041b476fad", | ||
commit: { | ||
url: | ||
"https://api.github.com/repos/isomerpages/a-test-v4/git/commits/a79525f0d188880b965053bc0df25a041b476fad", | ||
author: { | ||
name: MOCK_GITHUB_USER_NAME_ONE, | ||
email: MOCK_GITHUB_USER_EMAIL_ONE, | ||
date: MOCK_GITHUB_COMMIT_DATE_ONE, | ||
}, | ||
message: JSON.stringify(MOCK_GITHUB_COMMIT_MESSAGE_OBJECT_ALPHA_ONE), | ||
}, | ||
} | ||
export const MOCK_GITHUB_COMMIT_ALPHA_TWO: Commit = { | ||
url: | ||
"https://api.github.com/repos/isomerpages/a-test-v4/commits/ad2b13184f8ee1030636c304737941146bd67f4d", | ||
sha: "ad2b13184f8ee1030636c304737941146bd67f4d", | ||
commit: { | ||
url: | ||
"https://api.github.com/repos/isomerpages/a-test-v4/git/commits/ad2b13184f8ee1030636c304737941146bd67f4d", | ||
author: { | ||
name: MOCK_GITHUB_USER_NAME_TWO, | ||
email: MOCK_GITHUB_USER_EMAIL_TWO, | ||
date: MOCK_GITHUB_COMMIT_DATE_TWO, | ||
}, | ||
message: JSON.stringify(MOCK_GITHUB_COMMIT_MESSAGE_OBJECT_ALPHA_TWO), | ||
}, | ||
} | ||
export const MOCK_GITHUB_COMMIT_ALPHA_THREE: Commit = { | ||
url: `https://api.github.com/repos/isomerpages/a-test-v4/commits/${MOCK_GITHUB_COMMIT_SHA_LATEST_ALPHA}`, | ||
sha: MOCK_GITHUB_COMMIT_SHA_LATEST_ALPHA, | ||
commit: { | ||
url: `https://api.github.com/repos/isomerpages/a-test-v4/git/commits/${MOCK_GITHUB_COMMIT_SHA_LATEST_ALPHA}`, | ||
author: { | ||
name: MOCK_GITHUB_USER_NAME_ONE, | ||
email: MOCK_GITHUB_USER_EMAIL_ONE, | ||
date: MOCK_GITHUB_COMMIT_DATE_THREE, | ||
}, | ||
message: JSON.stringify(MOCK_GITHUB_COMMIT_MESSAGE_OBJECT_ALPHA_THREE), | ||
}, | ||
} | ||
// end of set | ||
|
||
export const MOCK_GITHUB_COMMENT_BODY_ONE = "Comment 1" | ||
export const MOCK_GITHUB_COMMENT_BODY_TWO = "Comment 2" | ||
|
||
export const MOCK_GITHUB_COMMENT_OBJECT_ONE = { | ||
message: MOCK_GITHUB_COMMENT_BODY_ONE, | ||
fileName: MOCK_GITHUB_FILENAME_ALPHA_ONE, | ||
userId: MOCK_USER_ID_ONE, | ||
} | ||
|
||
export const MOCK_GITHUB_COMMENT_OBJECT_TWO = { | ||
message: MOCK_GITHUB_COMMENT_BODY_TWO, | ||
fileName: MOCK_GITHUB_FILENAME_ALPHA_TWO, | ||
userId: MOCK_USER_ID_TWO, | ||
} | ||
|
||
export const MOCK_GITHUB_RAWCOMMENT_ONE: RawComment = { | ||
body: JSON.stringify(MOCK_GITHUB_COMMENT_OBJECT_ONE), | ||
created_at: MOCK_GITHUB_COMMIT_DATE_ONE, | ||
} | ||
export const MOCK_GITHUB_RAWCOMMENT_TWO: RawComment = { | ||
body: JSON.stringify(MOCK_GITHUB_COMMENT_OBJECT_TWO), | ||
created_at: MOCK_GITHUB_COMMIT_DATE_THREE, | ||
} |
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
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,2 +1,132 @@ | ||
export const MOCK_SITE_NAME_ONE = "test-site-one" | ||
export const MOCK_SITE_NAME_TWO = "test-site-two" | ||
import { Attributes } from "sequelize/types" | ||
|
||
import { Deployment, Repo, Site, SiteMember } from "@database/models" | ||
import { CollaboratorRoles, JobStatus, SiteStatus } from "@root/constants" | ||
|
||
import { | ||
MOCK_USER_ID_FOUR, | ||
MOCK_USER_ID_ONE, | ||
MOCK_USER_ID_THREE, | ||
MOCK_USER_ID_TWO, | ||
} from "./users" | ||
|
||
export const MOCK_SITE_ID_ONE = 1 | ||
export const MOCK_SITE_ID_TWO = 2 | ||
|
||
export const MOCK_SITE_NAME_ONE = "Human readable site name one" | ||
export const MOCK_SITE_NAME_TWO = "Human readable site name two" | ||
|
||
export const MOCK_SITE_DATE_ONE = new Date("2022-09-23T00:00:00Z") | ||
export const MOCK_SITE_DATE_TWO = new Date("2022-09-25T00:00:00Z") | ||
|
||
export const MOCK_REPO_NAME_ONE = "repo-name-test-one" | ||
export const MOCK_REPO_NAME_TWO = "repo-name-test-two" | ||
|
||
export const MOCK_REPO_URL_ONE = "https://github.com/example/repo-one" | ||
export const MOCK_REPO_URL_TWO = "https://github.com/example/repo-two" | ||
|
||
export const MOCK_DEPLOYMENT_PROD_URL_ONE = | ||
"https://master.gibberishone.amplifyapp.com" | ||
export const MOCK_DEPLOYMENT_PROD_URL_TWO = | ||
"https://master.gibberishtwo.amplifyapp.com" | ||
|
||
export const MOCK_DEPLOYMENT_STAGING_URL_ONE = | ||
"https://staging.gibberishone.amplifyapp.com" | ||
export const MOCK_DEPLOYMENT_STAGING_URL_TWO = | ||
"https://staging.gibberishtwo.amplifyapp.com" | ||
|
||
export const MOCK_SITE_DBENTRY_ONE: Attributes<Site> = { | ||
id: MOCK_SITE_ID_ONE, | ||
name: MOCK_REPO_NAME_ONE, | ||
apiTokenName: "unused", | ||
siteStatus: SiteStatus.Launched, | ||
jobStatus: JobStatus.Ready, | ||
creatorId: MOCK_USER_ID_ONE, | ||
createdAt: MOCK_SITE_DATE_ONE, | ||
updatedAt: MOCK_SITE_DATE_ONE, | ||
} | ||
|
||
export const MOCK_SITE_DBENTRY_TWO: Attributes<Site> = { | ||
id: MOCK_SITE_ID_TWO, | ||
name: MOCK_REPO_NAME_TWO, | ||
apiTokenName: "unused", | ||
siteStatus: SiteStatus.Launched, | ||
jobStatus: JobStatus.Ready, | ||
creatorId: MOCK_USER_ID_TWO, | ||
createdAt: MOCK_SITE_DATE_TWO, | ||
updatedAt: MOCK_SITE_DATE_TWO, | ||
} | ||
|
||
export const MOCK_REPO_DBENTRY_ONE: Attributes<Repo> = { | ||
id: 1, | ||
name: MOCK_REPO_NAME_ONE, | ||
url: MOCK_REPO_URL_ONE, | ||
siteId: MOCK_SITE_ID_ONE, | ||
createdAt: MOCK_SITE_DATE_ONE, | ||
updatedAt: MOCK_SITE_DATE_ONE, | ||
} | ||
|
||
export const MOCK_REPO_DBENTRY_TWO: Attributes<Repo> = { | ||
id: 2, | ||
name: MOCK_REPO_NAME_TWO, | ||
url: MOCK_REPO_URL_TWO, | ||
siteId: MOCK_SITE_ID_TWO, | ||
createdAt: MOCK_SITE_DATE_TWO, | ||
updatedAt: MOCK_SITE_DATE_TWO, | ||
} | ||
|
||
export const MOCK_DEPLOYMENT_DBENTRY_ONE: Attributes<Deployment> = { | ||
id: 1, | ||
siteId: MOCK_SITE_ID_ONE, | ||
productionUrl: MOCK_DEPLOYMENT_PROD_URL_ONE, | ||
stagingUrl: MOCK_DEPLOYMENT_STAGING_URL_ONE, | ||
createdAt: MOCK_SITE_DATE_ONE, | ||
updatedAt: MOCK_SITE_DATE_ONE, | ||
hostingId: "1", | ||
} | ||
|
||
export const MOCK_DEPLOYMENT_DBENTRY_TWO: Attributes<Deployment> = { | ||
id: 2, | ||
siteId: MOCK_SITE_ID_TWO, | ||
productionUrl: MOCK_DEPLOYMENT_PROD_URL_TWO, | ||
stagingUrl: MOCK_DEPLOYMENT_STAGING_URL_TWO, | ||
createdAt: MOCK_SITE_DATE_TWO, | ||
updatedAt: MOCK_SITE_DATE_TWO, | ||
hostingId: "1", | ||
} | ||
|
||
export const MOCK_SITEMEMBER_DBENTRY_ONE: Attributes<SiteMember> = { | ||
id: 1, | ||
userId: MOCK_USER_ID_ONE, | ||
siteId: MOCK_SITE_ID_ONE, | ||
role: CollaboratorRoles.Admin, | ||
createdAt: MOCK_SITE_DATE_ONE, | ||
updatedAt: MOCK_SITE_DATE_ONE, | ||
} | ||
|
||
export const MOCK_SITEMEMBER_DBENTRY_TWO: Attributes<SiteMember> = { | ||
id: 2, | ||
userId: MOCK_USER_ID_TWO, | ||
siteId: MOCK_SITE_ID_ONE, | ||
role: CollaboratorRoles.Contributor, | ||
createdAt: MOCK_SITE_DATE_ONE, | ||
updatedAt: MOCK_SITE_DATE_ONE, | ||
} | ||
|
||
export const MOCK_SITEMEMBER_DBENTRY_THREE: Attributes<SiteMember> = { | ||
id: 3, | ||
userId: MOCK_USER_ID_THREE, | ||
siteId: MOCK_SITE_ID_TWO, | ||
role: CollaboratorRoles.Admin, | ||
createdAt: MOCK_SITE_DATE_TWO, | ||
updatedAt: MOCK_SITE_DATE_TWO, | ||
} | ||
|
||
export const MOCK_SITEMEMBER_DBENTRY_FOUR: Attributes<SiteMember> = { | ||
id: 4, | ||
userId: MOCK_USER_ID_FOUR, | ||
siteId: MOCK_SITE_ID_TWO, | ||
role: CollaboratorRoles.Contributor, | ||
createdAt: MOCK_SITE_DATE_TWO, | ||
updatedAt: MOCK_SITE_DATE_TWO, | ||
} |
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.