Skip to content

Commit 64b237e

Browse files
committed
Wrote end-to-end cypress tests
1 parent ad74afb commit 64b237e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+4647
-1164
lines changed

api/package-lock.json

Lines changed: 52 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"license": "MIT",
66
"scripts": {
77
"start": "nodemon --exec ts-node --files src/index.ts",
8-
"db-seed": "nodemon --exec ts-node --files src/database/seeds/development/index.ts",
8+
"test:start": "cross-env NODE_ENV='test' DB_DATABASE='jira_test' nodemon --exec ts-node --files src/index.ts",
99
"pre-commit": "lint-staged"
1010
},
1111
"dependencies": {
@@ -32,6 +32,7 @@
3232
"@types/node": "^12.12.11",
3333
"@typescript-eslint/eslint-plugin": "^2.7.0",
3434
"@typescript-eslint/parser": "^2.7.0",
35+
"cross-env": "^6.0.3",
3536
"eslint": "^6.1.0",
3637
"eslint-config-airbnb-base": "^14.0.0",
3738
"eslint-config-prettier": "^6.7.0",

api/src/controllers/authentication.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import express from 'express';
22

33
import { catchErrors } from 'errors';
44
import { signToken } from 'utils/authToken';
5-
import seedGuestUserEntities from 'database/seeds/guestUser';
5+
import createGuestAccount from 'database/createGuestAccount';
66

77
const router = express.Router();
88

99
router.post(
1010
'/authentication/guest',
1111
catchErrors(async (_req, res) => {
12-
const user = await seedGuestUserEntities();
12+
const user = await createGuestAccount();
1313
res.respond({
1414
authToken: signToken({ sub: user.id }),
1515
});

api/src/controllers/test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import express from 'express';
2+
3+
import { catchErrors } from 'errors';
4+
import { signToken } from 'utils/authToken';
5+
import resetDatabase from 'database/resetDatabase';
6+
import createTestAccount from 'database/createTestAccount';
7+
8+
const router = express.Router();
9+
10+
router.delete(
11+
'/test/reset-database',
12+
catchErrors(async (_req, res) => {
13+
await resetDatabase();
14+
res.respond(true);
15+
}),
16+
);
17+
18+
router.post(
19+
'/test/create-account',
20+
catchErrors(async (_req, res) => {
21+
const user = await createTestAccount();
22+
res.respond({
23+
authToken: signToken({ sub: user.id }),
24+
});
25+
}),
26+
);
27+
28+
export default router;
File renamed without changes.

api/src/database/seeds/guestUser.ts renamed to api/src/database/createGuestAccount.ts

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { sample } from 'lodash';
2-
31
import { Comment, Issue, Project, User } from 'entities';
42
import { ProjectCategory } from 'constants/projects';
53
import { IssueType, IssueStatus, IssuePriority } from 'constants/issues';
@@ -37,7 +35,8 @@ const seedProject = (users: User[]): Promise<Project> =>
3735
});
3836

3937
const seedIssues = (project: Project): Promise<Issue[]> => {
40-
const getRandomUser = (): User => sample(project.users) as User;
38+
const { users } = project;
39+
4140
const issues = [
4241
createEntity(Issue, {
4342
title: 'This is an issue of type: Task.',
@@ -46,9 +45,9 @@ const seedIssues = (project: Project): Promise<Issue[]> => {
4645
priority: IssuePriority.LOWEST,
4746
listPosition: 1,
4847
estimate: 8,
49-
reporterId: getRandomUser().id,
48+
reporterId: users[1].id,
5049
project,
51-
users: [getRandomUser()],
50+
users: [users[0]],
5251
}),
5352
createEntity(Issue, {
5453
title: "Click on an issue to see what's behind it.",
@@ -58,7 +57,7 @@ const seedIssues = (project: Project): Promise<Issue[]> => {
5857
listPosition: 2,
5958
description: 'Nothing in particular.',
6059
estimate: 40,
61-
reporterId: getRandomUser().id,
60+
reporterId: users[2].id,
6261
project,
6362
}),
6463
createEntity(Issue, {
@@ -68,9 +67,9 @@ const seedIssues = (project: Project): Promise<Issue[]> => {
6867
priority: IssuePriority.MEDIUM,
6968
listPosition: 3,
7069
estimate: 15,
71-
reporterId: getRandomUser().id,
70+
reporterId: users[1].id,
7271
project,
73-
users: [getRandomUser()],
72+
users: [users[2]],
7473
}),
7574
createEntity(Issue, {
7675
title: 'You can use markdown for issue descriptions.',
@@ -80,9 +79,9 @@ const seedIssues = (project: Project): Promise<Issue[]> => {
8079
listPosition: 4,
8180
description: '#### Colons can be used to align columns.',
8281
estimate: 4,
83-
reporterId: getRandomUser().id,
82+
reporterId: users[0].id,
8483
project,
85-
users: [getRandomUser()],
84+
users: [users[2]],
8685
}),
8786
createEntity(Issue, {
8887
title: 'You must assign priority from lowest to highest to all issues.',
@@ -91,7 +90,7 @@ const seedIssues = (project: Project): Promise<Issue[]> => {
9190
priority: IssuePriority.HIGHEST,
9291
listPosition: 5,
9392
estimate: 15,
94-
reporterId: getRandomUser().id,
93+
reporterId: users[2].id,
9594
project,
9695
}),
9796
createEntity(Issue, {
@@ -101,9 +100,9 @@ const seedIssues = (project: Project): Promise<Issue[]> => {
101100
priority: IssuePriority.MEDIUM,
102101
listPosition: 6,
103102
estimate: 55,
104-
reporterId: getRandomUser().id,
103+
reporterId: users[1].id,
105104
project,
106-
users: [getRandomUser()],
105+
users: [users[0]],
107106
}),
108107
createEntity(Issue, {
109108
title: 'Try leaving a comment on this issue.',
@@ -112,7 +111,7 @@ const seedIssues = (project: Project): Promise<Issue[]> => {
112111
priority: IssuePriority.MEDIUM,
113112
listPosition: 7,
114113
estimate: 12,
115-
reporterId: getRandomUser().id,
114+
reporterId: users[0].id,
116115
project,
117116
}),
118117
];
@@ -122,16 +121,16 @@ const seedIssues = (project: Project): Promise<Issue[]> => {
122121
const seedComments = (issue: Issue, user: User): Promise<Comment> =>
123122
createEntity(Comment, {
124123
body: "Be nice to each other! Don't be mean to each other!",
125-
issue,
126-
user,
124+
issueId: issue.id,
125+
userId: user.id,
127126
});
128127

129-
const seedGuestUserEntities = async (): Promise<User> => {
128+
const createGuestAccount = async (): Promise<User> => {
130129
const users = await seedUsers();
131130
const project = await seedProject(users);
132131
const issues = await seedIssues(project);
133-
await seedComments(issues[issues.length - 1], project.users[0]);
132+
await seedComments(issues[0], project.users[0]);
134133
return users[0];
135134
};
136135

137-
export default seedGuestUserEntities;
136+
export default createGuestAccount;
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import { Comment, Issue, Project, User } from 'entities';
2+
import { ProjectCategory } from 'constants/projects';
3+
import { IssueType, IssueStatus, IssuePriority } from 'constants/issues';
4+
import { createEntity } from 'utils/typeorm';
5+
6+
const seedUsers = (): Promise<User[]> => {
7+
const users = [
8+
createEntity(User, {
9+
10+
name: 'Gaben',
11+
avatarUrl: 'https://i.ibb.co/6RJ5hq6/gaben.jpg',
12+
}),
13+
createEntity(User, {
14+
15+
name: 'Yoda',
16+
avatarUrl: 'https://i.ibb.co/6n0hLML/baby-yoda.jpg',
17+
}),
18+
];
19+
return Promise.all(users);
20+
};
21+
22+
const seedProject = (users: User[]): Promise<Project> =>
23+
createEntity(Project, {
24+
name: 'Project name',
25+
url: 'https://www.testurl.com',
26+
description: 'Project description',
27+
category: ProjectCategory.SOFTWARE,
28+
users,
29+
});
30+
31+
const seedIssues = (project: Project): Promise<Issue[]> => {
32+
const { users } = project;
33+
34+
const issues = [
35+
createEntity(Issue, {
36+
title: 'Issue title 1',
37+
type: IssueType.TASK,
38+
status: IssueStatus.BACKLOG,
39+
priority: IssuePriority.LOWEST,
40+
listPosition: 1,
41+
reporterId: users[0].id,
42+
project,
43+
}),
44+
createEntity(Issue, {
45+
title: 'Issue title 2',
46+
type: IssueType.TASK,
47+
status: IssueStatus.BACKLOG,
48+
priority: IssuePriority.MEDIUM,
49+
listPosition: 2,
50+
estimate: 5,
51+
description: 'Issue description 2',
52+
reporterId: users[0].id,
53+
users: [users[0]],
54+
project,
55+
}),
56+
createEntity(Issue, {
57+
title: 'Issue title 3',
58+
type: IssueType.STORY,
59+
status: IssueStatus.SELECTED,
60+
priority: IssuePriority.HIGH,
61+
listPosition: 3,
62+
estimate: 10,
63+
description: 'Issue description 3',
64+
reporterId: users[0].id,
65+
users: [users[0], users[1]],
66+
project,
67+
}),
68+
];
69+
return Promise.all(issues);
70+
};
71+
72+
const seedComments = (issue: Issue, user: User): Promise<Comment> =>
73+
createEntity(Comment, {
74+
body: 'Comment body',
75+
issueId: issue.id,
76+
userId: user.id,
77+
});
78+
79+
const createTestAccount = async (): Promise<User> => {
80+
const users = await seedUsers();
81+
const project = await seedProject(users);
82+
const issues = await seedIssues(project);
83+
await seedComments(issues[0], project.users[0]);
84+
return users[0];
85+
};
86+
87+
export default createTestAccount;

api/src/database/resetDatabase.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { getConnection } from 'typeorm';
2+
3+
const resetDatabase = async (): Promise<void> => {
4+
const connection = getConnection();
5+
await connection.dropDatabase();
6+
await connection.synchronize();
7+
};
8+
9+
export default resetDatabase;

api/src/database/seeds/development/comment.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)