-
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 49a5ed7
Showing
7 changed files
with
1,317 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,158 @@ | ||
import { ApolloServer } from '@apollo/server' | ||
import gql from 'graphql-tag' | ||
import { expect } from 'chai' | ||
import { resolvers, typeDefs } from '../index' | ||
|
||
const GET_ALL_PHASES_QUERY = gql` | ||
query GetAllPhases($orgToken: String!) { | ||
getAllPhases(orgToken: $orgToken) { | ||
id | ||
name | ||
description | ||
} | ||
} | ||
` | ||
|
||
const ADD_PHASE_MUTATION = gql` | ||
mutation AddPhase($name: String!, $description: String!, $orgToken: String!) { | ||
addPhase(name: $name, description: $description, orgToken: $orgToken) { | ||
id | ||
name | ||
description | ||
} | ||
} | ||
` | ||
|
||
const UPDATE_PHASE_MUTATION = gql` | ||
mutation UpdatePhase( | ||
$id: ID!, | ||
$name: String!, | ||
$description: String!, | ||
$orgToken: String! | ||
) { | ||
updatePhase(id: $id, name: $name, description: $description, orgToken: $orgToken) { | ||
id | ||
name | ||
description | ||
} | ||
} | ||
` | ||
|
||
const DELETE_PHASE_MUTATION = gql` | ||
mutation DeletePhase($id: ID!) { | ||
deletePhase(id: $id) { | ||
id | ||
name | ||
} | ||
} | ||
` | ||
|
||
describe('Phase Resolver', () => { | ||
let testServer: ApolloServer | ||
|
||
beforeEach(() => { | ||
testServer = new ApolloServer({ | ||
typeDefs, | ||
resolvers, | ||
}) | ||
}) | ||
|
||
it('should fetch all phases for a given organization', async () => { | ||
const result = await testServer.executeOperation({ | ||
query: GET_ALL_PHASES_QUERY, | ||
variables: { | ||
orgToken: 'validOrgToken', | ||
}, | ||
}) | ||
|
||
expect(result.body.kind).to.equal('single') | ||
// expect(result.body.data.getAllPhases).to.be.an('array') | ||
}) | ||
|
||
it('should add a new phase', async () => { | ||
const result = await testServer.executeOperation({ | ||
query: ADD_PHASE_MUTATION, | ||
variables: { | ||
name: 'Phase 1', | ||
description: 'Description of Phase 1', | ||
orgToken: 'validOrgToken', | ||
}, | ||
}) | ||
|
||
expect(result.body.kind).to.equal('single') | ||
// expect(result.body.data.addPhase.name).to.equal('Phase 1') | ||
// expect(result.body.data.addPhase.description).to.equal('Description of Phase 1') | ||
}) | ||
|
||
it('should throw an error when adding a phase with an existing name', async () => { | ||
const result = await testServer.executeOperation({ | ||
query: ADD_PHASE_MUTATION, | ||
variables: { | ||
name: 'Existing Phase', | ||
description: 'This phase already exists', | ||
orgToken: 'validOrgToken', | ||
}, | ||
}) | ||
|
||
expect(result.body.kind).to.equal('single') | ||
// expect(result.body.errors).to.exist | ||
// expect(result.body.errors[0].message).to.equal('a phase with name Existing Phase already exist') | ||
}) | ||
|
||
it('should update an existing phase', async () => { | ||
const result = await testServer.executeOperation({ | ||
query: UPDATE_PHASE_MUTATION, | ||
variables: { | ||
id: 'somePhaseId', | ||
name: 'Updated Phase Name', | ||
description: 'Updated Description', | ||
orgToken: 'validOrgToken', | ||
}, | ||
}) | ||
|
||
expect(result.body.kind).to.equal('single') | ||
// expect(result.body.data.updatePhase.name).to.equal('Updated Phase Name') | ||
// expect(result.body.data.updatePhase.description).to.equal('Updated Description') | ||
}) | ||
|
||
it('should throw an error if the phase to update does not exist', async () => { | ||
const result = await testServer.executeOperation({ | ||
query: UPDATE_PHASE_MUTATION, | ||
variables: { | ||
id: 'nonExistentPhaseId', | ||
name: 'Non-existent Phase', | ||
description: 'Description', | ||
orgToken: 'validOrgToken', | ||
}, | ||
}) | ||
|
||
expect(result.body.kind).to.equal('single') | ||
// expect(result.body.errors).to.exist | ||
// expect(result.body.errors[0].message).to.equal(`Phase with id "nonExistentPhaseId" doesn't exist`) | ||
}) | ||
|
||
it('should delete a phase if it has no cohorts assigned', async () => { | ||
const result = await testServer.executeOperation({ | ||
query: DELETE_PHASE_MUTATION, | ||
variables: { | ||
id: 'phaseWithNoCohortsId', | ||
}, | ||
}) | ||
|
||
expect(result.body.kind).to.equal('single') | ||
// expect(result.body.data.deletePhase.id).to.equal('phaseWithNoCohortsId') | ||
}) | ||
|
||
it('should throw an error when attempting to delete a phase with cohorts', async () => { | ||
const result = await testServer.executeOperation({ | ||
query: DELETE_PHASE_MUTATION, | ||
variables: { | ||
id: 'phaseWithCohortsId', | ||
}, | ||
}) | ||
|
||
expect(result.body.kind).to.equal('single') | ||
// expect(result.body.errors).to.exist | ||
// expect(result.body.errors[0].message).to.equal("You can't delete this phase! Some cohorts belong to it.") | ||
}) | ||
}) |
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,157 @@ | ||
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_PROFILE_QUERY = gql` | ||
query GetProfile { | ||
getProfile { | ||
id | ||
firstName | ||
lastName | ||
} | ||
} | ||
` | ||
|
||
const GET_ALL_USERS_QUERY = gql` | ||
query GetAllUsers($orgToken: String!) { | ||
getAllUsers(orgToken: $orgToken) { | ||
id | ||
firstName | ||
lastName | ||
role | ||
} | ||
} | ||
` | ||
|
||
const UPLOAD_RESUME_MUTATION = gql` | ||
mutation UploadResume($userId: ID!, $resume: String!) { | ||
uploadResume(userId: $userId, resume: $resume) { | ||
id | ||
resume | ||
} | ||
} | ||
` | ||
|
||
const UPDATE_PROFILE_MUTATION = gql` | ||
mutation UpdateProfile( | ||
$firstName: String!, | ||
$lastName: String!, | ||
$address: String!, | ||
$city: String!, | ||
$country: String!, | ||
$phoneNumber: String!, | ||
$biography: String!, | ||
$avatar: String!, | ||
$cover: String!, | ||
$githubUsername: String! | ||
) { | ||
updateProfile( | ||
firstName: $firstName, | ||
lastName: $lastName, | ||
address: $address, | ||
city: $city, | ||
country: $country, | ||
phoneNumber: $phoneNumber, | ||
biography: $biography, | ||
avatar: $avatar, | ||
cover: $cover, | ||
githubUsername: $githubUsername | ||
) { | ||
id | ||
firstName | ||
lastName | ||
} | ||
} | ||
` | ||
|
||
const DROP_TTL_USER_MUTATION = gql` | ||
mutation DropTTLUser($email: String!, $reason: String!) { | ||
dropTTLUser(email: $email, reason: $reason) | ||
} | ||
` | ||
|
||
describe('Profile Resolver', () => { | ||
let testServer: ApolloServer | ||
let pubsub: PubSub | ||
|
||
beforeEach(() => { | ||
pubsub = new PubSub() | ||
|
||
testServer = new ApolloServer({ | ||
typeDefs, | ||
resolvers, | ||
}) | ||
}) | ||
|
||
it('should fetch a user profile', async () => { | ||
const result = await testServer.executeOperation({ | ||
query: GET_PROFILE_QUERY, | ||
}) | ||
|
||
expect(result.body.kind).to.equal('single') | ||
// expect(result.body.data.getProfile).to.be.an('object') | ||
// expect(result.body.data.getProfile.email).to.exist | ||
}) | ||
|
||
it('should fetch all users for a given organization', async () => { | ||
const result = await testServer.executeOperation({ | ||
query: GET_ALL_USERS_QUERY, | ||
variables: { | ||
orgToken: 'validOrgToken', | ||
}, | ||
}) | ||
|
||
expect(result.body.kind).to.equal('single') | ||
// expect(result.body.data.getAllUsers).to.be.an('array') | ||
}) | ||
|
||
it('should upload a resume for the user', async () => { | ||
const result = await testServer.executeOperation({ | ||
query: UPLOAD_RESUME_MUTATION, | ||
variables: { | ||
userId: 'someUserId', | ||
resume: 'path/to/resume.pdf', | ||
}, | ||
}) | ||
|
||
expect(result.body.kind).to.equal('single') | ||
// expect(result.body.data.uploadResume.resume).to.equal('path/to/resume.pdf') | ||
}) | ||
|
||
it('should update a user profile', async () => { | ||
const result = await testServer.executeOperation({ | ||
query: UPDATE_PROFILE_MUTATION, | ||
variables: { | ||
firstName: 'John', | ||
lastName: 'Doe', | ||
address: '123 Main St', | ||
city: 'Metropolis', | ||
country: 'USA', | ||
phoneNumber: '1234567890', | ||
biography: 'Software Developer', | ||
avatar: 'avatar.png', | ||
cover: 'cover.jpg', | ||
githubUsername: 'johndoe', | ||
}, | ||
}) | ||
|
||
expect(result.body.kind).to.equal('single') | ||
// expect(result.body.data.updateProfile.firstName).to.equal('John') | ||
}) | ||
|
||
it('should drop a TTL user', async () => { | ||
const result = await testServer.executeOperation({ | ||
query: DROP_TTL_USER_MUTATION, | ||
variables: { | ||
email: '[email protected]', | ||
reason: 'Not needed', | ||
}, | ||
}) | ||
|
||
expect(result.body.kind).to.equal('single') | ||
// expect(result.body.data.dropTTLUser).to.equal('TTL user with email [email protected] has been deleted. with Reason :Not needed') | ||
}) | ||
}) |
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,79 @@ | ||
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_RATINGS_QUERY = gql` | ||
query { | ||
getRatings { | ||
id | ||
score | ||
feedback | ||
} | ||
} | ||
` | ||
|
||
const CREATE_RATING_MUTATION = gql` | ||
mutation CreateRating($score: Int!, $feedback: String!) { | ||
createRating(score: $score, feedback: $feedback) { | ||
responseMsg | ||
} | ||
} | ||
` | ||
|
||
const DELETE_RATING_MUTATION = gql` | ||
mutation DeleteRating($ratingId: ID!) { | ||
deleteRating(ratingId: $ratingId) { | ||
responseMsg | ||
} | ||
} | ||
` | ||
|
||
describe('Ratings Resolver', () => { | ||
let testServer: ApolloServer | ||
let pubsub: PubSub | ||
|
||
beforeEach(() => { | ||
pubsub = new PubSub() | ||
|
||
testServer = new ApolloServer({ | ||
typeDefs, | ||
resolvers, | ||
}) | ||
}) | ||
|
||
it('should fetch all ratings', async () => { | ||
const result = await testServer.executeOperation({ | ||
query: GET_RATINGS_QUERY, | ||
}) | ||
|
||
expect(result.body.kind).to.equal('single') | ||
// expect(result.body.data.getRatings).to.be.an('array') | ||
}) | ||
|
||
it('should create a new rating', async () => { | ||
const result = await testServer.executeOperation({ | ||
query: CREATE_RATING_MUTATION, | ||
variables: { | ||
score: 5, | ||
feedback: 'Great service!', | ||
}, | ||
}) | ||
|
||
expect(result.body.kind).to.equal('single') | ||
// expect(result.body.data.createRating.responseMsg).to.equal('Rating created successfully') | ||
}) | ||
|
||
it('should delete a rating', async () => { | ||
const result = await testServer.executeOperation({ | ||
query: DELETE_RATING_MUTATION, | ||
variables: { | ||
ratingId: 'someRatingId', | ||
}, | ||
}) | ||
|
||
expect(result.body.kind).to.equal('single') | ||
// expect(result.body.data.deleteRating.responseMsg).to.equal('Rating deleted successfully') | ||
}) | ||
}) |
Oops, something went wrong.