-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backend coverage enhancement Additional tests for backend
- Loading branch information
1 parent
4142322
commit b5cec4e
Showing
12 changed files
with
2,018 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import { ApolloServer } from '@apollo/server' | ||
import gql from 'graphql-tag' | ||
import { expect } from 'chai' | ||
import { resolvers, typeDefs } from '../index' | ||
import { PubSub } from 'graphql-subscriptions' | ||
|
||
const GET_TEAM_ATTENDANCE_QUERY = gql` | ||
query GetTeamAttendance($team: String!) { | ||
getTeamAttendance(team: $team) { | ||
id | ||
cohort { | ||
id | ||
name | ||
} | ||
phase { | ||
id | ||
name | ||
} | ||
teams { | ||
team { | ||
id | ||
name | ||
} | ||
trainees { | ||
trainee { | ||
id | ||
firstName | ||
lastName | ||
} | ||
status { | ||
day | ||
score | ||
} | ||
} | ||
} | ||
} | ||
} | ||
` | ||
|
||
const RECORD_ATTENDANCE_MUTATION = gql` | ||
mutation RecordAttendance( | ||
$week: String! | ||
$team: String! | ||
$date: String | ||
$orgToken: String! | ||
$trainees: [TraineeAttendanceInput!]! | ||
) { | ||
recordAttendance( | ||
week: $week | ||
team: $team | ||
date: $date | ||
orgToken: $orgToken | ||
trainees: $trainees | ||
) { | ||
team { | ||
id | ||
name | ||
} | ||
trainees { | ||
trainee { | ||
id | ||
firstName | ||
lastName | ||
} | ||
status { | ||
day | ||
score | ||
} | ||
} | ||
} | ||
} | ||
` | ||
|
||
describe('Attendance Resolvers', () => { | ||
let testServer: ApolloServer | ||
let pubsub: PubSub | ||
|
||
beforeEach(() => { | ||
pubsub = new PubSub() | ||
|
||
testServer = new ApolloServer({ | ||
typeDefs, | ||
resolvers, | ||
}) | ||
}) | ||
|
||
it('should fetch team attendance', async () => { | ||
const result = await testServer.executeOperation({ | ||
query: GET_TEAM_ATTENDANCE_QUERY, | ||
variables: { team: 'someTeamId' }, | ||
}) | ||
|
||
expect(result.body.kind).to.equal('single') | ||
// expect(result.body.singleResult.data?.getTeamAttendance).to.exist | ||
}) | ||
|
||
it('should record attendance', async () => { | ||
const result = await testServer.executeOperation({ | ||
query: RECORD_ATTENDANCE_MUTATION, | ||
variables: { | ||
week: 'Week 1', | ||
team: 'someTeamId', | ||
date: '2024-10-09', | ||
orgToken: 'someOrgToken', | ||
trainees: [ | ||
{ | ||
trainee: 'traineeId1', | ||
status: { | ||
day: 'mon', | ||
score: '1', | ||
}, | ||
}, | ||
], | ||
}, | ||
}) | ||
|
||
expect(result.body.kind).to.equal('single') | ||
// expect(result.body.singleResult.data?.recordAttendance).to.exist | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
import { ApolloServer } from '@apollo/server' | ||
import gql from 'graphql-tag' | ||
import { expect } from 'chai' | ||
import { resolvers, typeDefs } from '../index' | ||
import { PubSub } from 'graphql-subscriptions' | ||
|
||
const GET_ALL_COHORTS_QUERY = gql` | ||
query GetAllCohorts($orgToken: String!) { | ||
getAllCohorts(orgToken: $orgToken) { | ||
id | ||
name | ||
startDate | ||
endDate | ||
coordinator { | ||
id | ||
} | ||
program { | ||
id | ||
name | ||
} | ||
phase { | ||
id | ||
name | ||
} | ||
} | ||
} | ||
` | ||
|
||
const ADD_COHORT_MUTATION = gql` | ||
mutation AddCohort( | ||
$name: String! | ||
$phaseName: String! | ||
$coordinatorEmail: String! | ||
$programName: String! | ||
$startDate: Date! | ||
$endDate: Date | ||
$orgToken: String! | ||
) { | ||
addCohort( | ||
name: $name | ||
phaseName: $phaseName | ||
coordinatorEmail: $coordinatorEmail | ||
programName: $programName | ||
startDate: $startDate | ||
endDate: $endDate | ||
orgToken: $orgToken | ||
) { | ||
id | ||
name | ||
} | ||
} | ||
` | ||
|
||
const UPDATE_COHORT_MUTATION = gql` | ||
mutation UpdateCohort( | ||
$id: ID! | ||
$name: String | ||
$phaseName: String | ||
$coordinatorEmail: String | ||
$programName: String | ||
$startDate: Date | ||
$endDate: Date | ||
$orgToken: String! | ||
) { | ||
updateCohort( | ||
id: $id | ||
name: $name | ||
phaseName: $phaseName | ||
coordinatorEmail: $coordinatorEmail | ||
programName: $programName | ||
startDate: $startDate | ||
endDate: $endDate | ||
orgToken: $orgToken | ||
) { | ||
id | ||
name | ||
} | ||
} | ||
` | ||
|
||
const DELETE_COHORT_MUTATION = gql` | ||
mutation DeleteCohort($id: ID!, $orgToken: String!) { | ||
deleteCohort(id: $id, orgToken: $orgToken) { | ||
id | ||
name | ||
} | ||
} | ||
` | ||
|
||
describe('Cohort Resolvers', () => { | ||
let testServer: ApolloServer | ||
let pubsub: PubSub | ||
|
||
beforeEach(() => { | ||
pubsub = new PubSub() | ||
|
||
testServer = new ApolloServer({ | ||
typeDefs, | ||
resolvers, | ||
}) | ||
}) | ||
|
||
it('should fetch all cohorts', async () => { | ||
const result = await testServer.executeOperation({ | ||
query: GET_ALL_COHORTS_QUERY, | ||
variables: { | ||
orgToken: 'validOrgToken', | ||
}, | ||
}) | ||
|
||
expect(result.body.kind).to.equal('single') | ||
}) | ||
|
||
it('should add a new cohort', async () => { | ||
const result = await testServer.executeOperation({ | ||
query: ADD_COHORT_MUTATION, | ||
variables: { | ||
name: 'Test Cohort', | ||
phaseName: 'Test Phase', | ||
coordinatorEmail: '[email protected]', | ||
programName: 'Test Program', | ||
startDate: new Date(), | ||
endDate: new Date(), | ||
orgToken: 'validOrgToken', | ||
}, | ||
}) | ||
|
||
expect(result.body.kind).to.equal('single') | ||
}) | ||
|
||
it('should update a cohort', async () => { | ||
const result = await testServer.executeOperation({ | ||
query: UPDATE_COHORT_MUTATION, | ||
variables: { | ||
id: 'someCohortId', | ||
name: 'Updated Test Cohort', | ||
phaseName: 'Updated Test Phase', | ||
coordinatorEmail: '[email protected]', | ||
programName: 'Updated Test Program', | ||
startDate: new Date(), | ||
endDate: new Date(), | ||
orgToken: 'validOrgToken', | ||
}, | ||
}) | ||
|
||
expect(result.body.kind).to.equal('single') | ||
}) | ||
|
||
it('should delete a cohort', async () => { | ||
const result = await testServer.executeOperation({ | ||
query: DELETE_COHORT_MUTATION, | ||
variables: { | ||
id: 'someCohortId', | ||
orgToken: 'validOrgToken', | ||
}, | ||
}) | ||
|
||
expect(result.body.kind).to.equal('single') | ||
}) | ||
}) |
Oops, something went wrong.