Skip to content

Commit

Permalink
N21-2268 Add timeout to policies-info (#5331)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvinOehlerkingCap authored Nov 11, 2024
1 parent d1547f4 commit c886edd
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export interface SchulconnexClientConfig {
SCHULCONNEX_CLIENT__PERSONEN_INFO_TIMEOUT_IN_MS: number;
SCHULCONNEX_CLIENT__POLICIES_INFO_TIMEOUT_IN_MS: number;
SCHULCONNEX_CLIENT__API_URL?: string;
SCHULCONNEX_CLIENT__TOKEN_ENDPOINT?: string;
SCHULCONNEX_CLIENT__CLIENT_ID?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class SchulconnexClientModule {
clientId: configService.get<string>('SCHULCONNEX_CLIENT__CLIENT_ID'),
clientSecret: configService.get<string>('SCHULCONNEX_CLIENT__CLIENT_SECRET'),
personenInfoTimeoutInMs: configService.get<number>('SCHULCONNEX_CLIENT__PERSONEN_INFO_TIMEOUT_IN_MS'),
policiesInfoTimeoutInMs: configService.get<number>('SCHULCONNEX_CLIENT__POLICIES_INFO_TIMEOUT_IN_MS'),
};
return new SchulconnexRestClient(options, httpService, oauthAdapterService, logger);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ export interface SchulconnexRestClientOptions {
clientSecret?: string;

personenInfoTimeoutInMs?: number;

policiesInfoTimeoutInMs?: number;
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ describe(SchulconnexRestClient.name, () => {
clientId: 'clientId',
clientSecret: 'clientSecret',
tokenEndpoint: 'https://schulconnex.url/token',
personenInfoTimeoutInMs: 30000,
policiesInfoTimeoutInMs: 30000,
};

beforeAll(() => {
Expand Down Expand Up @@ -144,47 +146,31 @@ describe(SchulconnexRestClient.name, () => {
});
const response: SchulconnexResponse[] = schulconnexResponseFactory.buildList(2);

const optionsWithTimeout: SchulconnexRestClientOptions = {
...options,
personenInfoTimeoutInMs: 30000,
};

const optionsClient: SchulconnexRestClient = new SchulconnexRestClient(
optionsWithTimeout,
httpService,
oauthAdapterService,
logger
);

oauthAdapterService.sendTokenRequest.mockResolvedValueOnce(tokens);
httpService.get.mockReturnValueOnce(of(axiosResponseFactory.build({ data: response })));

return {
tokens,
response,
optionsClient,
optionsWithTimeout,
};
};

it('should make a request to a SchulConneX-API', async () => {
const { tokens, optionsClient, optionsWithTimeout } = setup();
const { tokens } = setup();

await optionsClient.getPersonenInfo({
await client.getPersonenInfo({
'organisation.id': '1234',
vollstaendig: ['personen', 'organisationen'],
});

expect(httpService.get).toHaveBeenCalledWith(
`${
optionsWithTimeout.apiUrl ?? ''
}/personen-info?organisation.id=1234&vollstaendig=personen%2Corganisationen`,
`${options.apiUrl ?? ''}/personen-info?organisation.id=1234&vollstaendig=personen%2Corganisationen`,
{
headers: {
Authorization: `Bearer ${tokens.accessToken}`,
'Accept-Encoding': 'gzip',
},
timeout: optionsWithTimeout.personenInfoTimeoutInMs,
timeout: options.personenInfoTimeoutInMs,
}
);
});
Expand Down Expand Up @@ -223,6 +209,7 @@ describe(SchulconnexRestClient.name, () => {
Authorization: `Bearer ${accessToken}`,
'Accept-Encoding': 'gzip',
},
timeout: options.policiesInfoTimeoutInMs,
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ export class SchulconnexRestClient implements SchulconnexApiInterface {
const response: (SchulconnexPoliciesInfoLicenseResponse | SchulconnexPoliciesInfoErrorResponse)[] =
await this.getRequest<(SchulconnexPoliciesInfoLicenseResponse | SchulconnexPoliciesInfoErrorResponse)[]>(
url,
accessToken
accessToken,
this.options.policiesInfoTimeoutInMs
);

const responseObject: SchulconnexPoliciesInfoResponse = { data: response };
Expand Down
3 changes: 3 additions & 0 deletions apps/server/src/modules/server/server.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ const config: ServerConfig = {
SCHULCONNEX_CLIENT__PERSONEN_INFO_TIMEOUT_IN_MS: Configuration.get(
'SCHULCONNEX_CLIENT__PERSONEN_INFO_TIMEOUT_IN_MS'
) as number,
SCHULCONNEX_CLIENT__POLICIES_INFO_TIMEOUT_IN_MS: Configuration.get(
'SCHULCONNEX_CLIENT__POLICIES_INFO_TIMEOUT_IN_MS'
) as number,
FEATURE_SCHULCONNEX_COURSE_SYNC_ENABLED: Configuration.get('FEATURE_SCHULCONNEX_COURSE_SYNC_ENABLED') as boolean,
...getTldrawClientConfig(),
FEATURE_MEDIA_SHELF_ENABLED: Configuration.get('FEATURE_MEDIA_SHELF_ENABLED') as boolean,
Expand Down
5 changes: 5 additions & 0 deletions config/default.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1669,6 +1669,11 @@
"type": "integer",
"description": "Timeout in milliseconds for fetching personen info from schulconnex",
"default": 120000
},
"POLICIES_INFO_TIMEOUT_IN_MS": {
"type": "integer",
"description": "Timeout in milliseconds for fetching policies info from schulconnex",
"default": 4000
}
},
"default": {
Expand Down

0 comments on commit c886edd

Please sign in to comment.