Skip to content
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 14 commits into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"start": "node -r ts-node/register/transpile-only -r tsconfig-paths/register build/server.js",
"dev:services": "docker compose up -d",
"dev": "source .env && ts-node-dev --respawn src/server.js",
"test": "source .env.test && jest",
"test": "source .env.test && jest --runInBand",
Copy link
Contributor

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

Copy link
Contributor Author

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.

"release": "npm version $npm_config_isomer_update && git push --tags",
"lint": "npx eslint .",
"lint-fix": "eslint --ignore-path .gitignore . --fix",
Expand Down
4 changes: 2 additions & 2 deletions src/fixtures/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
mockGithubSessionData,
MOCK_USER_SESSION_DATA_ONE,
} from "./sessionData"
import { MOCK_SITE_NAME_ONE } from "./sites"
import { MOCK_REPO_NAME_ONE } from "./sites"

/**
* @deprecated
Expand Down Expand Up @@ -93,7 +93,7 @@ const attachDefaultUserSessionDataWithSite: RequestHandler<
}
> = attachUserSessionDataWithSite(
MOCK_USER_SESSION_DATA_ONE,
MOCK_SITE_NAME_ONE
MOCK_REPO_NAME_ONE
)

/**
Expand Down
139 changes: 139 additions & 0 deletions src/fixtures/github.ts
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,
}
14 changes: 9 additions & 5 deletions src/fixtures/review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Attributes } from "sequelize/types"

import { ReviewRequestStatus } from "@root/constants"
import { ReviewRequest, ReviewRequestView } from "@root/database/models"
import { Commit } from "@root/types/github"
import { Commit, RawPullRequest } from "@root/types/github"

import {
mockCollaboratorAdmin1,
Expand Down Expand Up @@ -56,10 +56,14 @@ export const MOCK_PULL_REQUEST_COMMIT_TWO: Commit = {
},
}

export const MOCK_PULL_REQUEST_ONE = {
title: "Pull Request 1",
body: "Pull Request 1 Description",
changed_files: 3,
export const MOCK_PULL_REQUEST_TITLE_ONE = "Pull Request 1"
export const MOCK_PULL_REQUEST_BODY_ONE = "Pull Request 1 Description"
export const MOCK_PULL_REQUEST_CHANGED_FILES_ONE = 3

export const MOCK_PULL_REQUEST_ONE: RawPullRequest = {
title: MOCK_PULL_REQUEST_TITLE_ONE,
body: MOCK_PULL_REQUEST_BODY_ONE,
changed_files: MOCK_PULL_REQUEST_CHANGED_FILES_ONE,
created_at: MOCK_GITHUB_DATE_ONE,
}

Expand Down
134 changes: 132 additions & 2 deletions src/fixtures/sites.ts
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,
}
46 changes: 46 additions & 0 deletions src/fixtures/users.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { Attributes } from "sequelize/types"

import { User } from "@database/models"

export const MOCK_USER_ID_ONE = 1
export const MOCK_USER_ID_TWO = 2
export const MOCK_USER_ID_THREE = 3
Expand All @@ -7,3 +11,45 @@ export const MOCK_USER_EMAIL_ONE = "[email protected]"
export const MOCK_USER_EMAIL_TWO = "[email protected]"
export const MOCK_USER_EMAIL_THREE = "[email protected]"
export const MOCK_USER_EMAIL_FOUR = "[email protected]"

export const MOCK_USER_DATE_ONE = new Date("2022-08-23T00:00:00Z")
export const MOCK_USER_DATE_TWO = new Date("2022-08-25T00:00:00Z")
export const MOCK_USER_DATE_THREE = new Date("2022-08-27T00:00:00Z")
export const MOCK_USER_DATE_FOUR = new Date("2022-08-29T00:00:00Z")

export const MOCK_USER_LAST_LOGIN_ONE = new Date("2022-09-12T00:00:00Z")
export const MOCK_USER_LAST_LOGIN_TWO = new Date("2022-09-14T00:00:00Z")
export const MOCK_USER_LAST_LOGIN_THREE = new Date("2022-09-16T00:00:00Z")
export const MOCK_USER_LAST_LOGIN_FOUR = new Date("2022-09-18T00:00:00Z")

export const MOCK_USER_DBENTRY_ONE: Attributes<User> = {
id: MOCK_USER_ID_ONE,
email: MOCK_USER_EMAIL_ONE,
lastLoggedIn: MOCK_USER_LAST_LOGIN_ONE,
createdAt: MOCK_USER_DATE_ONE,
updatedAt: MOCK_USER_DATE_ONE,
}

export const MOCK_USER_DBENTRY_TWO: Attributes<User> = {
id: MOCK_USER_ID_TWO,
email: MOCK_USER_EMAIL_TWO,
lastLoggedIn: MOCK_USER_LAST_LOGIN_TWO,
createdAt: MOCK_USER_DATE_TWO,
updatedAt: MOCK_USER_DATE_TWO,
}

export const MOCK_USER_DBENTRY_THREE: Attributes<User> = {
id: MOCK_USER_ID_THREE,
email: MOCK_USER_EMAIL_THREE,
lastLoggedIn: MOCK_USER_LAST_LOGIN_THREE,
createdAt: MOCK_USER_DATE_THREE,
updatedAt: MOCK_USER_DATE_THREE,
}

export const MOCK_USER_DBENTRY_FOUR: Attributes<User> = {
id: MOCK_USER_ID_FOUR,
email: MOCK_USER_EMAIL_FOUR,
lastLoggedIn: MOCK_USER_LAST_LOGIN_FOUR,
createdAt: MOCK_USER_DATE_FOUR,
updatedAt: MOCK_USER_DATE_FOUR,
}
Loading