Skip to content

Commit f600b8b

Browse files
committed
Add Cypress coverage
1 parent 35bfb66 commit f600b8b

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

cypress.config.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
const { defineConfig } = require('cypress')
22
const db = require('./src/lib/db')
33
const Team = require('./src/models/team')
4+
const Organization = require('./src/models/organization')
45
const TeamInvitation = require('./src/models/team-invitation')
6+
const { pick } = require('ramda')
57

68
const user1 = {
79
id: 1,
@@ -15,6 +17,7 @@ module.exports = defineConfig({
1517
on('task', {
1618
'db:reset': async () => {
1719
await db.raw('TRUNCATE TABLE team RESTART IDENTITY CASCADE')
20+
await db.raw('TRUNCATE TABLE organization RESTART IDENTITY CASCADE')
1821
return null
1922
},
2023
'db:seed': async () => {
@@ -42,6 +45,20 @@ module.exports = defineConfig({
4245
'db:seed:team-invitations': async (teamInvitations) => {
4346
return Promise.all(teamInvitations.map(TeamInvitation.create))
4447
},
48+
'db:seed:organizations': async (orgs) => {
49+
return Promise.all(
50+
orgs.map((org) =>
51+
Organization.create(pick(['name'], org), org.ownerId)
52+
)
53+
)
54+
},
55+
'db:seed:organization-teams': async ({ orgId, teams, managerId }) => {
56+
return Promise.all(
57+
teams.map((team) =>
58+
Organization.createOrgTeam(orgId, pick(['name'], team), managerId)
59+
)
60+
)
61+
},
4562
})
4663
},
4764
},

cypress/e2e/organizations.cy.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const user1 = {
2+
id: 1,
3+
display_name: 'User 1',
4+
}
5+
6+
const org1 = {
7+
id: 1,
8+
name: 'My org',
9+
ownerId: user1.id,
10+
}
11+
12+
const team1 = {
13+
name: 'Team 1',
14+
}
15+
16+
describe('Organization page', () => {
17+
before(() => {
18+
cy.task('db:reset')
19+
cy.task('db:seed:organizations', [org1])
20+
})
21+
22+
it('List organization teams', () => {
23+
cy.login(user1)
24+
25+
// Check state when no teams are available
26+
cy.visit('/organizations/1')
27+
cy.get('body').should('contain', 'This organization has no teams.')
28+
29+
// Seed org teams
30+
cy.task('db:seed:organization-teams', {
31+
orgId: org1.id,
32+
teams: [team1],
33+
managerId: user1.id,
34+
})
35+
36+
// Check state when teams are available
37+
cy.visit('/organizations/1')
38+
cy.get('body').should('contain', team1.name)
39+
})
40+
})

src/lib/org-api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export async function getOrg(id) {
6464
* @returns {response}
6565
*/
6666
export async function getOrgTeams(id) {
67-
let res = await fetch(join(URL, `${id}`, 'teams'))
67+
let res = await fetch(join(ORG_URL, `${id}`, 'teams'))
6868

6969
if (res.status === 200) {
7070
return res.json()

0 commit comments

Comments
 (0)