Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ajout du test pour getSchoolInfos (+update des types pour faire le test) #45

Merged
merged 15 commits into from
May 3, 2024
Merged
18 changes: 11 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,17 @@ export class Skolengo {
public static async getOIDClient (school: School, redirectUri = 'skoapp-prod://sign-in-callback'): Promise<Client> {
const { Issuer } = await import('openid-client')

const skolengoIssuer = await Issuer.discover(school.emsOIDCWellKnownUrl)
return new skolengoIssuer.Client({
client_id: OID_CLIENT_ID,
client_secret: OID_CLIENT_SECRET,
redirect_uris: [redirectUri],
response_types: ['code']
})
if (school.emsOIDCWellKnownUrl === null || school.emsOIDCWellKnownUrl === '' || school.emsOIDCWellKnownUrl === undefined) {
throw new TypeError('emsOIDCWellKnownUrl invalid')
} else {
const skolengoIssuer = await Issuer.discover(school.emsOIDCWellKnownUrl)
return new skolengoIssuer.Client({
client_id: OID_CLIENT_ID,
client_secret: OID_CLIENT_SECRET,
redirect_uris: [redirectUri],
response_types: ['code']
})
}
Vilerio marked this conversation as resolved.
Show resolved Hide resolved
}
maelgangloff marked this conversation as resolved.
Show resolved Hide resolved

/**
Expand Down
10 changes: 5 additions & 5 deletions src/models/School/Attachment.ts
Vilerio marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export interface Attachment {
id: string
name?: string
mimeType?: string
mimeTypeLabel?: string
size?: number
name: string | null
mimeType: string | null
mimeTypeLabel: string | null
size: number | null
url: string
alternativeText?: string | null
alternativeText: string
}
23 changes: 12 additions & 11 deletions src/models/School/School.ts
Vilerio marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ export type SchoolFilter = { text: string } | { lat: number, lon: number }

export interface School {
id: string
name: string
addressLine1: string
addressLine2: null | string
addressLine3: null | string
zipCode: string
city: string
country: string
homePageUrl: string
emsCode: string
emsOIDCWellKnownUrl: string
distance?: number
name?: string
addressLine1: string | null
addressLine2: string | null
addressLine3: string | null
zipCode: string | null
city: string | null
country: string | null
homePageUrl: string | null
timeZone?: string | null
emsCode?: string | null
emsOIDCWellKnownUrl?: string | null
distance?: number | null
}
18 changes: 12 additions & 6 deletions src/models/School/SchoolInfo.ts
Vilerio marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,25 @@ import type { School } from './School'

export interface SchoolInfo {
id: string
level?: string
publicationDateTime: string
title: string
shortContent: string
content?: string
url?: string | null
linkedInfoUrl?: string | null
linkedWebSiteUrl?: string | null
school?: Partial<School>
url: string | null
linkedInfoUrl: string | null
linkedWebSiteUrl: string | null
school: Partial<School>
attachments?: Attachment[]
author: {
author?: {
id: string
additionalInfo: any
person: User
person?: User
technicalUser?: {
id: string
label: string
logoUrl: string
}
}
illustration?: Attachment
}
12 changes: 9 additions & 3 deletions test/user.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { describe, expect } from '@jest/globals'
import type { AuthConfig } from '../src/models/Common/Auth'
import { Skolengo } from '../src/index'
import './common'

Expand All @@ -13,7 +14,7 @@ describeAuthenticated('Test Skolengo API types - Authenticated user', () => {
let userPermissions: string[] = []

beforeAll(async () => {
user = await Skolengo.fromConfigObject(JSON.parse(SKOLENGO_TOKENSET as string), { handlePronoteError: true })
user = await Skolengo.fromConfigObject((JSON.parse(SKOLENGO_TOKENSET as string) as AuthConfig), { handlePronoteError: true })
const userInfo = await user.getUserInfo()
if (userInfo.permissions === undefined) throw new Error("Impossible de lister les habilitations de l'utilisateur.")
userPermissions = userInfo.permissions.map(p => p.permittedOperations).flat()
Expand All @@ -28,15 +29,20 @@ describeAuthenticated('Test Skolengo API types - Authenticated user', () => {
it('should getEvaluationSettings return EvaluationSettings type', async () => {
if (!userPermissions.includes('READ_EVALUATIONS')) return
const response = await user.getEvaluationSettings()

for (const evaluationSettings of response) {
expect(evaluationSettings).toMatchSchema('EvaluationSettings')
}
})

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

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

it('should getSchoolInfos return an array of SchoolInfo type', async () => {
const response = await Skolengo.searchSchool({ text: 'Lycée' }, 10)
for (const school of response) {
expect(school).toMatchSchema('School')
}
})
maelgangloff marked this conversation as resolved.
Show resolved Hide resolved
})
Loading