Skip to content

Commit

Permalink
test: add getEvaluation unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
maelgangloff committed May 3, 2024
1 parent e91e4e7 commit a0e3b91
Showing 1 changed file with 35 additions and 16 deletions.
51 changes: 35 additions & 16 deletions test/user.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { describe, expect } from '@jest/globals'
import type { AuthConfig } from '../src/models/Common/Auth'
import type { EvaluationSettings } from '../src/models/Results'
import { Skolengo } from '../src/index'
import './common'

Expand All @@ -9,7 +10,7 @@ const describeAuthenticated = SKOLENGO_TOKENSET !== undefined ? describe : descr
/**
* Tests unitaires des endpoints qui nécessitent une authentification
*/
describeAuthenticated('Test Skolengo API types - Authenticated user', () => {
describeAuthenticated('Test of the Skolengo API types - Authenticated user', () => {
let user: Skolengo
let userPermissions: string[] = []

Expand All @@ -22,28 +23,46 @@ describeAuthenticated('Test Skolengo API types - Authenticated user', () => {

it('should getUserInfo return User type', async () => {
const response = await user.getUserInfo()

expect(response).toMatchSchema('User')
})

it('should getEvaluationSettings return EvaluationSettings type', async () => {
it('should getSchoolInfos return an array of SchoolInfo type', async () => {
const response = await user.getSchoolInfos()
for (const info of response) expect(info).toMatchSchema('SchoolInfo')
})

/**
* Tests unitaires du module d'évaluation
*/
describe('Test of the Evaluation module', () => {
if (!userPermissions.includes('READ_EVALUATIONS')) return
const response = await user.getEvaluationSettings()
for (const evaluationSettings of response) {
expect(evaluationSettings).toMatchSchema('EvaluationSettings')
}

let evaluationSettingsList: EvaluationSettings[]

beforeAll(async () => {
evaluationSettingsList = await user.getEvaluationSettings()
})

it('should getEvaluationSettings return EvaluationSettings type', async () => {
for (const evaluationSettings of evaluationSettingsList) expect(evaluationSettings).toMatchSchema('EvaluationSettings')
})

it('should getEvaluation return an array of Evaluation', async () => {
if (evaluationSettingsList.length === 0 || evaluationSettingsList[0].periods.length === 0) return
const response = await user.getEvaluation(undefined, evaluationSettingsList[0].periods[0].id)
for (const evaluation of response) expect(evaluation).toMatchSchema('Evaluation')
})
})

it('should getUsersMailSettings return UsersMailSettings type', async () => {
/**
* Tests du module de messagerie
*/
describe('Test of the Messagerie module', () => {
if (!userPermissions.includes('READ_MESSAGES')) return
const response = await user.getUsersMailSettings()
expect(response).toMatchSchema('UsersMailSettings')
})

it('should getSchoolInfos return an array of SchoolInfo type', async () => {
const response = await user.getSchoolInfos()
for (const info of response) {
expect(info).toMatchSchema('SchoolInfo')
}
it('should getUsersMailSettings return UsersMailSettings type', async () => {
const response = await user.getUsersMailSettings()
expect(response).toMatchSchema('UsersMailSettings')
})
})
})

0 comments on commit a0e3b91

Please sign in to comment.