-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tests: add integration tests for review requests and comments #576
Merged
Merged
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
ac37728
fix: force tests to run sequentially
dcshzj b07a745
fix: reset the state of the tables before running the tests
dcshzj 2b8baa4
feat: add fixtures used for review requests
dcshzj c3ed0e7
fix: await results from IdentityService
dcshzj 971ffb0
tests: add partial integration tests for review requests
dcshzj d043f83
chore: switch site name to use repo name instead
dcshzj a027adf
chore: switch to using variable for file name
dcshzj cbad9c7
chore: standardise the response codes for non-happy paths
dcshzj 1bec74e
fix: add additional sanity checks for comments-related features
dcshzj 4d05e80
tests: add remaining integration tests for review requests
dcshzj 7354e91
fix: add methods to generate router for default values
dcshzj ed6af06
chore: rename test to be more reflective of its purpose
dcshzj f3b8eea
fix: add missing return and await when updating database
dcshzj f83091b
chore: add comment on the need for Table.sync
dcshzj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 = | ||
"[email protected]" | ||
export const MOCK_GITHUB_USER_EMAIL_TWO = | ||
"[email protected]" | ||
|
||
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, | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this causes our tests to run sequentially; is there an issue w/ concurrency in our tests? also, could i check what's the runtime of our tests now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have some issues with the concurrency when running integration tests, as they require that the database is in a clean state before the tests are run. I think it should theoretically be possible to make the integration tests be run independently, but we will need to adjust some of the test data especially for some of our older tests.
I feel that we should rationalise the integration tests in a separate PR once all the integration tests are ready and complete (or using some method of generating fake data).
The runtime is slightly slower when the tests run sequentially, but overall it takes around 44 seconds now.