From c5290c73000e51d068f183e787b022dcaf3f3c88 Mon Sep 17 00:00:00 2001 From: Olivier Date: Fri, 3 May 2024 19:27:46 +0200 Subject: [PATCH 01/13] types: updating types to match with different schoolinfo --- src/models/School/Attachment.ts | 10 +++++----- src/models/School/School.ts | 23 ++++++++++++----------- src/models/School/SchoolInfo.ts | 18 ++++++++++++------ 3 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/models/School/Attachment.ts b/src/models/School/Attachment.ts index ebe4864..06e813f 100644 --- a/src/models/School/Attachment.ts +++ b/src/models/School/Attachment.ts @@ -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 } diff --git a/src/models/School/School.ts b/src/models/School/School.ts index 6200f74..0393c5e 100644 --- a/src/models/School/School.ts +++ b/src/models/School/School.ts @@ -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 } diff --git a/src/models/School/SchoolInfo.ts b/src/models/School/SchoolInfo.ts index b75b0e0..4d55597 100644 --- a/src/models/School/SchoolInfo.ts +++ b/src/models/School/SchoolInfo.ts @@ -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 + url: string | null + linkedInfoUrl: string | null + linkedWebSiteUrl: string | null + school: Partial attachments?: Attachment[] - author: { + author?: { id: string additionalInfo: any - person: User + person?: User + technicalUser?: { + id: string + label: string + logoUrl: string + } } illustration?: Attachment } From 0dee2cd917171b88f813208954f82aa6cbb023f3 Mon Sep 17 00:00:00 2001 From: Olivier Date: Fri, 3 May 2024 19:28:25 +0200 Subject: [PATCH 02/13] fix(types): null check for emsOIDCWellKnownUrl --- src/index.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/index.ts b/src/index.ts index a8e2214..2867377 100644 --- a/src/index.ts +++ b/src/index.ts @@ -217,13 +217,17 @@ export class Skolengo { public static async getOIDClient (school: School, redirectUri = 'skoapp-prod://sign-in-callback'): Promise { 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'] + }) + } } /** From 424a04e975de6f1adeb01699355256cb8b780235 Mon Sep 17 00:00:00 2001 From: Olivier Date: Fri, 3 May 2024 19:28:54 +0200 Subject: [PATCH 03/13] tests: adding getSchoolInfos type test --- test/user.test.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/user.test.ts b/test/user.test.ts index 4fde3c8..21c15d7 100644 --- a/test/user.test.ts +++ b/test/user.test.ts @@ -63,4 +63,15 @@ describeIfLoggedIn('Test Skolengo API types - User logged in', () => { expect(result).toBe(true) }) + + it('should getSchoolInfos return an array of SchoolInfo type', async () => { + const type = 'SchoolInfo' + const response = await user.getSchoolInfos() + const ajv = new Ajv() + const schema = createGenerator({ ...ajvConfig, type }).createSchema(type) + for (const info of response.slice(0, Math.min(3, response.length))) { + const result = ajv.validate(schema, info) + expect(result).toBe(true) + } + }) }) From 36e396f79cf91aac3b0865f6ab26143df9640591 Mon Sep 17 00:00:00 2001 From: Olivier Date: Fri, 3 May 2024 19:54:54 +0200 Subject: [PATCH 04/13] fix(typo): unsafe arg --- test/user.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/user.test.ts b/test/user.test.ts index 21c15d7..636823b 100644 --- a/test/user.test.ts +++ b/test/user.test.ts @@ -1,6 +1,7 @@ import { describe, expect } from '@jest/globals' import type { Config } from 'ts-json-schema-generator' import { createGenerator } from 'ts-json-schema-generator' +import { AuthConfig } from '../src/models/Common/Auth' import { Skolengo } from '../src/index' import Ajv from 'ajv' @@ -22,7 +23,7 @@ describeIfLoggedIn('Test Skolengo API types - User logged in', () => { 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() From 324ddedf0036542446f66d4348cbbf3c7298330a Mon Sep 17 00:00:00 2001 From: Olivier Date: Fri, 3 May 2024 20:03:38 +0200 Subject: [PATCH 05/13] chore: update due PR #43 --- test/user.test.ts | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/test/user.test.ts b/test/user.test.ts index 4cbd515..fded7de 100644 --- a/test/user.test.ts +++ b/test/user.test.ts @@ -1,5 +1,4 @@ import { describe, expect } from '@jest/globals' -import type { Config } from 'ts-json-schema-generator' import { createGenerator } from 'ts-json-schema-generator' import { AuthConfig } from '../src/models/Common/Auth' import { Skolengo } from '../src/index' @@ -31,7 +30,6 @@ 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') } @@ -39,18 +37,13 @@ describeAuthenticated('Test Skolengo API types - Authenticated user', () => { 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 type = 'SchoolInfo' - const response = await user.getSchoolInfos() - const ajv = new Ajv() - const schema = createGenerator({ ...ajvConfig, type }).createSchema(type) - for (const info of response.slice(0, Math.min(3, response.length))) { - const result = ajv.validate(schema, info) - expect(result).toBe(true) + const response = await Skolengo.searchSchool({ text: 'Lycée' }, 10) + for (const school of response) { + expect(school).toMatchSchema('School') } }) }) From ed2bab7e8bb574a0ed48e34d83166f06cecc173f Mon Sep 17 00:00:00 2001 From: Olivier Date: Fri, 3 May 2024 20:06:55 +0200 Subject: [PATCH 06/13] style: import type --- test/user.test.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/user.test.ts b/test/user.test.ts index fded7de..7921329 100644 --- a/test/user.test.ts +++ b/test/user.test.ts @@ -1,6 +1,5 @@ import { describe, expect } from '@jest/globals' -import { createGenerator } from 'ts-json-schema-generator' -import { AuthConfig } from '../src/models/Common/Auth' +import type { AuthConfig } from '../src/models/Common/Auth' import { Skolengo } from '../src/index' import './common' From ba226a3065be9a7f923b45e0db9d0a8a7b50da10 Mon Sep 17 00:00:00 2001 From: Olivier Date: Fri, 3 May 2024 20:08:26 +0200 Subject: [PATCH 07/13] style: handle empty case explicitly --- test/user.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/user.test.ts b/test/user.test.ts index 7921329..26eb1f4 100644 --- a/test/user.test.ts +++ b/test/user.test.ts @@ -4,7 +4,7 @@ import { Skolengo } from '../src/index' import './common' const SKOLENGO_TOKENSET = process.env.SKOLENGO_TOKENSET -const describeAuthenticated = !!SKOLENGO_TOKENSET ? describe : describe.skip +const describeAuthenticated = (SKOLENGO_TOKENSET !== null && SKOLENGO_TOKENSET !== '') ? describe : describe.skip /** * Tests unitaires des endpoints qui nécessitent une authentification From b1b398d956d62f01c1b835b466f8ac514ef6819a Mon Sep 17 00:00:00 2001 From: Olivier Date: Fri, 3 May 2024 20:24:59 +0200 Subject: [PATCH 08/13] tests(fix): wrong function call --- test/user.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/user.test.ts b/test/user.test.ts index 26eb1f4..1597d06 100644 --- a/test/user.test.ts +++ b/test/user.test.ts @@ -40,9 +40,9 @@ describeAuthenticated('Test Skolengo API types - Authenticated user', () => { }) 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') + const response = await user.getSchoolInfos() + for (const info of response) { + expect(info).toMatchSchema('SchoolInfo') } }) }) From 2478d85590d47df62229f1d3ce1377260dd88585 Mon Sep 17 00:00:00 2001 From: Vilerio <69359417+Vilerio@users.noreply.github.com> Date: Fri, 3 May 2024 21:25:38 +0200 Subject: [PATCH 09/13] fix(typo): handle empty case explicitly correction MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Maël Gangloff --- src/index.ts | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/index.ts b/src/index.ts index 2867377..c15e6dd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -217,17 +217,15 @@ export class Skolengo { public static async getOIDClient (school: School, redirectUri = 'skoapp-prod://sign-in-callback'): Promise { const { Issuer } = await import('openid-client') - 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'] - }) - } + if (!school.emsOIDCWellKnownUrl) throw new TypeError('emsOIDCWellKnownUrl invalid') + 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'] + }) + } } /** From ad7fe83807960c2f3e5214e8e6f4656a0087ff51 Mon Sep 17 00:00:00 2001 From: Vilerio <69359417+Vilerio@users.noreply.github.com> Date: Fri, 3 May 2024 21:26:11 +0200 Subject: [PATCH 10/13] fix(typo): handle undefined value MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Maël Gangloff --- test/user.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/user.test.ts b/test/user.test.ts index 1597d06..33aa290 100644 --- a/test/user.test.ts +++ b/test/user.test.ts @@ -4,7 +4,7 @@ import { Skolengo } from '../src/index' import './common' const SKOLENGO_TOKENSET = process.env.SKOLENGO_TOKENSET -const describeAuthenticated = (SKOLENGO_TOKENSET !== null && SKOLENGO_TOKENSET !== '') ? describe : describe.skip +const describeAuthenticated = SKOLENGO_TOKENSET !== undefined ? describe : describe.skip /** * Tests unitaires des endpoints qui nécessitent une authentification From 72e86a13772c79c707239d4ebdb20407e5b4aeeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Gangloff?= Date: Fri, 3 May 2024 21:58:52 +0200 Subject: [PATCH 11/13] fix: remove extra bracket --- src/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index c15e6dd..8d38787 100644 --- a/src/index.ts +++ b/src/index.ts @@ -226,7 +226,6 @@ export class Skolengo { response_types: ['code'] }) } - } /** * Créer un client Scolengo à partir d'un objet contenant les informations d'authentification. From e5820913bbf6835019d3d331da29752bcc231a91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Gangloff?= Date: Fri, 3 May 2024 22:01:12 +0200 Subject: [PATCH 12/13] fix: nullable string value in conditional --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 8d38787..bd6eed3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -217,7 +217,7 @@ export class Skolengo { public static async getOIDClient (school: School, redirectUri = 'skoapp-prod://sign-in-callback'): Promise { const { Issuer } = await import('openid-client') - if (!school.emsOIDCWellKnownUrl) throw new TypeError('emsOIDCWellKnownUrl invalid') + if (school.emsOIDCWellKnownUrl == undefined || school.emsOIDCWellKnownUrl == null) throw new TypeError('emsOIDCWellKnownUrl invalid') const skolengoIssuer = await Issuer.discover(school.emsOIDCWellKnownUrl) return new skolengoIssuer.Client({ client_id: OID_CLIENT_ID, From 0dc370eb01f011d69fe365c82aa07e3e1271c921 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Gangloff?= Date: Fri, 3 May 2024 22:02:29 +0200 Subject: [PATCH 13/13] fix: === instead of == --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index bd6eed3..80921b8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -217,7 +217,7 @@ export class Skolengo { public static async getOIDClient (school: School, redirectUri = 'skoapp-prod://sign-in-callback'): Promise { const { Issuer } = await import('openid-client') - if (school.emsOIDCWellKnownUrl == undefined || school.emsOIDCWellKnownUrl == null) throw new TypeError('emsOIDCWellKnownUrl invalid') + if (school.emsOIDCWellKnownUrl === undefined || school.emsOIDCWellKnownUrl === null) throw new TypeError('emsOIDCWellKnownUrl invalid') const skolengoIssuer = await Issuer.discover(school.emsOIDCWellKnownUrl) return new skolengoIssuer.Client({ client_id: OID_CLIENT_ID,