Skip to content

Commit 9e6ffdf

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

File tree

10 files changed

+1679
-0
lines changed

10 files changed

+1679
-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/invitation.spec.ts

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
import { ApolloServer } from '@apollo/server';
2+
import gql from 'graphql-tag';
3+
import { expect } from 'chai';
4+
import { resolvers, typeDefs } from '../index'; // adjust if needed
5+
import { PubSub } from 'graphql-subscriptions';
6+
7+
const SEND_INVITATION_MUTATION = gql`
8+
mutation SendInvitation($invitees: [InviteeInput!]!, $orgToken: String!, $orgName: String!) {
9+
sendInvitation(invitees: $invitees, orgToken: $orgToken, orgName: $orgName) {
10+
inviterId
11+
invitees {
12+
email
13+
role
14+
}
15+
orgToken
16+
orgName
17+
}
18+
}
19+
`;
20+
21+
const CANCEL_INVITATION_MUTATION = gql`
22+
mutation CancelInvitation($id: ID!, $orgToken: String!) {
23+
cancelInvitation(id: $id, orgToken: $orgToken) {
24+
id
25+
status
26+
}
27+
}
28+
`;
29+
30+
const UPLOAD_INVITATION_FILE_MUTATION = gql`
31+
mutation UploadInvitationFile($file: Upload!, $orgName: String!, $orgToken: String!) {
32+
uploadInvitationFile(file: $file, orgName: $orgName, orgToken: $orgToken) {
33+
filename
34+
sentEmails
35+
message
36+
}
37+
}
38+
`;
39+
40+
const UPDATE_INVITATION_MUTATION = gql`
41+
mutation UpdateInvitation($orgToken: String!, $invitationId: String!, $newEmail: String, $newRole: String) {
42+
updateInvitation(orgToken: $orgToken, invitationId: $invitationId, newEmail: $newEmail, newRole: $newRole) {
43+
id
44+
invitees {
45+
email
46+
role
47+
}
48+
status
49+
}
50+
}
51+
`;
52+
53+
const DELETE_INVITATION_MUTATION = gql`
54+
mutation DeleteInvitation($invitationId: ID!) {
55+
deleteInvitation(invitationId: $invitationId) {
56+
message
57+
}
58+
}
59+
`;
60+
61+
const RESEND_INVITATION_MUTATION = gql`
62+
mutation ResendInvitation($invitationId: ID!, $orgToken: String!) {
63+
resendInvitation(invitationId: $invitationId, orgToken: $orgToken) {
64+
success
65+
message
66+
}
67+
}
68+
`;
69+
70+
describe('Invitation Resolvers', () => {
71+
let testServer: ApolloServer;
72+
let pubsub: PubSub;
73+
74+
beforeEach(() => {
75+
pubsub = new PubSub();
76+
77+
testServer = new ApolloServer({
78+
typeDefs,
79+
resolvers,
80+
});
81+
});
82+
83+
it('should send an invitation', async () => {
84+
const result = await testServer.executeOperation({
85+
query: SEND_INVITATION_MUTATION,
86+
variables: {
87+
invitees: [{ email: '[email protected]', role: 'ADMIN' }],
88+
orgToken: 'someOrgToken',
89+
orgName: 'TestOrg',
90+
},
91+
});
92+
93+
expect(result.body.kind).to.equal('single');
94+
});
95+
96+
it('should cancel an invitation', async () => {
97+
const result = await testServer.executeOperation({
98+
query: CANCEL_INVITATION_MUTATION,
99+
variables: {
100+
id: 'someInvitationId',
101+
orgToken: 'someOrgToken',
102+
},
103+
});
104+
105+
expect(result.body.kind).to.equal('single');
106+
});
107+
108+
it('should upload an invitation file', async () => {
109+
const result = await testServer.executeOperation({
110+
query: UPLOAD_INVITATION_FILE_MUTATION,
111+
variables: {
112+
file: 'someMockFile',
113+
orgName: 'TestOrg',
114+
orgToken: 'someOrgToken',
115+
},
116+
});
117+
118+
expect(result.body.kind).to.equal('single');
119+
});
120+
121+
it('should update an invitation', async () => {
122+
const result = await testServer.executeOperation({
123+
query: UPDATE_INVITATION_MUTATION,
124+
variables: {
125+
orgToken: 'someOrgToken',
126+
invitationId: 'someInvitationId',
127+
newEmail: '[email protected]',
128+
newRole: 'TTL',
129+
},
130+
});
131+
132+
expect(result.body.kind).to.equal('single');
133+
});
134+
135+
it('should delete an invitation', async () => {
136+
const result = await testServer.executeOperation({
137+
query: DELETE_INVITATION_MUTATION,
138+
variables: {
139+
invitationId: 'someInvitationId',
140+
},
141+
});
142+
143+
expect(result.body.kind).to.equal('single');
144+
});
145+
146+
it('should resend an invitation', async () => {
147+
const result = await testServer.executeOperation({
148+
query: RESEND_INVITATION_MUTATION,
149+
variables: {
150+
invitationId: 'someInvitationId',
151+
orgToken: 'someOrgToken',
152+
},
153+
});
154+
155+
expect(result.body.kind).to.equal('single');
156+
});
157+
});

0 commit comments

Comments
 (0)