Skip to content

Commit b5cec4e

Browse files
committed
ch(coverage): testing
Backend coverage enhancement Additional tests for backend
1 parent 4142322 commit b5cec4e

12 files changed

+2018
-0
lines changed

src/test/attendance.spec.ts

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
import { ApolloServer } from '@apollo/server'
2+
import gql from 'graphql-tag'
3+
import { expect } from 'chai'
4+
import { resolvers, typeDefs } from '../index'
5+
import { PubSub } from 'graphql-subscriptions'
6+
7+
const GET_TEAM_ATTENDANCE_QUERY = gql`
8+
query GetTeamAttendance($team: String!) {
9+
getTeamAttendance(team: $team) {
10+
id
11+
cohort {
12+
id
13+
name
14+
}
15+
phase {
16+
id
17+
name
18+
}
19+
teams {
20+
team {
21+
id
22+
name
23+
}
24+
trainees {
25+
trainee {
26+
id
27+
firstName
28+
lastName
29+
}
30+
status {
31+
day
32+
score
33+
}
34+
}
35+
}
36+
}
37+
}
38+
`
39+
40+
const RECORD_ATTENDANCE_MUTATION = gql`
41+
mutation RecordAttendance(
42+
$week: String!
43+
$team: String!
44+
$date: String
45+
$orgToken: String!
46+
$trainees: [TraineeAttendanceInput!]!
47+
) {
48+
recordAttendance(
49+
week: $week
50+
team: $team
51+
date: $date
52+
orgToken: $orgToken
53+
trainees: $trainees
54+
) {
55+
team {
56+
id
57+
name
58+
}
59+
trainees {
60+
trainee {
61+
id
62+
firstName
63+
lastName
64+
}
65+
status {
66+
day
67+
score
68+
}
69+
}
70+
}
71+
}
72+
`
73+
74+
describe('Attendance Resolvers', () => {
75+
let testServer: ApolloServer
76+
let pubsub: PubSub
77+
78+
beforeEach(() => {
79+
pubsub = new PubSub()
80+
81+
testServer = new ApolloServer({
82+
typeDefs,
83+
resolvers,
84+
})
85+
})
86+
87+
it('should fetch team attendance', async () => {
88+
const result = await testServer.executeOperation({
89+
query: GET_TEAM_ATTENDANCE_QUERY,
90+
variables: { team: 'someTeamId' },
91+
})
92+
93+
expect(result.body.kind).to.equal('single')
94+
// expect(result.body.singleResult.data?.getTeamAttendance).to.exist
95+
})
96+
97+
it('should record attendance', async () => {
98+
const result = await testServer.executeOperation({
99+
query: RECORD_ATTENDANCE_MUTATION,
100+
variables: {
101+
week: 'Week 1',
102+
team: 'someTeamId',
103+
date: '2024-10-09',
104+
orgToken: 'someOrgToken',
105+
trainees: [
106+
{
107+
trainee: 'traineeId1',
108+
status: {
109+
day: 'mon',
110+
score: '1',
111+
},
112+
},
113+
],
114+
},
115+
})
116+
117+
expect(result.body.kind).to.equal('single')
118+
// expect(result.body.singleResult.data?.recordAttendance).to.exist
119+
})
120+
})

src/test/cohorts.spec.ts

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
import { ApolloServer } from '@apollo/server'
2+
import gql from 'graphql-tag'
3+
import { expect } from 'chai'
4+
import { resolvers, typeDefs } from '../index'
5+
import { PubSub } from 'graphql-subscriptions'
6+
7+
const GET_ALL_COHORTS_QUERY = gql`
8+
query GetAllCohorts($orgToken: String!) {
9+
getAllCohorts(orgToken: $orgToken) {
10+
id
11+
name
12+
startDate
13+
endDate
14+
coordinator {
15+
id
16+
email
17+
}
18+
program {
19+
id
20+
name
21+
}
22+
phase {
23+
id
24+
name
25+
}
26+
}
27+
}
28+
`
29+
30+
const ADD_COHORT_MUTATION = gql`
31+
mutation AddCohort(
32+
$name: String!
33+
$phaseName: String!
34+
$coordinatorEmail: String!
35+
$programName: String!
36+
$startDate: Date!
37+
$endDate: Date
38+
$orgToken: String!
39+
) {
40+
addCohort(
41+
name: $name
42+
phaseName: $phaseName
43+
coordinatorEmail: $coordinatorEmail
44+
programName: $programName
45+
startDate: $startDate
46+
endDate: $endDate
47+
orgToken: $orgToken
48+
) {
49+
id
50+
name
51+
}
52+
}
53+
`
54+
55+
const UPDATE_COHORT_MUTATION = gql`
56+
mutation UpdateCohort(
57+
$id: ID!
58+
$name: String
59+
$phaseName: String
60+
$coordinatorEmail: String
61+
$programName: String
62+
$startDate: Date
63+
$endDate: Date
64+
$orgToken: String!
65+
) {
66+
updateCohort(
67+
id: $id
68+
name: $name
69+
phaseName: $phaseName
70+
coordinatorEmail: $coordinatorEmail
71+
programName: $programName
72+
startDate: $startDate
73+
endDate: $endDate
74+
orgToken: $orgToken
75+
) {
76+
id
77+
name
78+
}
79+
}
80+
`
81+
82+
const DELETE_COHORT_MUTATION = gql`
83+
mutation DeleteCohort($id: ID!, $orgToken: String!) {
84+
deleteCohort(id: $id, orgToken: $orgToken) {
85+
id
86+
name
87+
}
88+
}
89+
`
90+
91+
describe('Cohort Resolvers', () => {
92+
let testServer: ApolloServer
93+
let pubsub: PubSub
94+
95+
beforeEach(() => {
96+
pubsub = new PubSub()
97+
98+
testServer = new ApolloServer({
99+
typeDefs,
100+
resolvers,
101+
})
102+
})
103+
104+
it('should fetch all cohorts', async () => {
105+
const result = await testServer.executeOperation({
106+
query: GET_ALL_COHORTS_QUERY,
107+
variables: {
108+
orgToken: 'validOrgToken',
109+
},
110+
})
111+
112+
expect(result.body.kind).to.equal('single')
113+
})
114+
115+
it('should add a new cohort', async () => {
116+
const result = await testServer.executeOperation({
117+
query: ADD_COHORT_MUTATION,
118+
variables: {
119+
name: 'Test Cohort',
120+
phaseName: 'Test Phase',
121+
coordinatorEmail: '[email protected]',
122+
programName: 'Test Program',
123+
startDate: new Date(),
124+
endDate: new Date(),
125+
orgToken: 'validOrgToken',
126+
},
127+
})
128+
129+
expect(result.body.kind).to.equal('single')
130+
})
131+
132+
it('should update a cohort', async () => {
133+
const result = await testServer.executeOperation({
134+
query: UPDATE_COHORT_MUTATION,
135+
variables: {
136+
id: 'someCohortId',
137+
name: 'Updated Test Cohort',
138+
phaseName: 'Updated Test Phase',
139+
coordinatorEmail: '[email protected]',
140+
programName: 'Updated Test Program',
141+
startDate: new Date(),
142+
endDate: new Date(),
143+
orgToken: 'validOrgToken',
144+
},
145+
})
146+
147+
expect(result.body.kind).to.equal('single')
148+
})
149+
150+
it('should delete a cohort', async () => {
151+
const result = await testServer.executeOperation({
152+
query: DELETE_COHORT_MUTATION,
153+
variables: {
154+
id: 'someCohortId',
155+
orgToken: 'validOrgToken',
156+
},
157+
})
158+
159+
expect(result.body.kind).to.equal('single')
160+
})
161+
})

0 commit comments

Comments
 (0)