Skip to content

Commit

Permalink
N21-2062 renaming lizenz-info and skip on error (#5132)
Browse files Browse the repository at this point in the history
  • Loading branch information
arnegns authored Jul 25, 2024
1 parent 517d724 commit 56607ad
Show file tree
Hide file tree
Showing 29 changed files with 227 additions and 110 deletions.
2 changes: 1 addition & 1 deletion apps/server/src/infra/schulconnex-client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ export { SchulconnexRestClientOptions } from './schulconnex-rest-client-options'
export { SchulconnexClientModule } from './schulconnex-client.module';
export { SchulconnexRestClient } from './schulconnex-rest-client';
export * from './response';
export { schulconnexResponseFactory, schulconnexLizenzInfoResponseFactory } from './testing';
export { schulconnexResponseFactory, schulconnexPoliciesInfoResponseFactory } from './testing';
export { SchulconnexClientConfig } from './schulconnex-client-config';
2 changes: 1 addition & 1 deletion apps/server/src/infra/schulconnex-client/response/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ export { SchulconnexResponseValidationGroups } from './schulconnex-response-vali
export { SchulconnexErreichbarkeitenResponse } from './schulconnex-erreichbarkeiten-response';
export { SchulconnexCommunicationType } from './schulconnex-communication-type';
export { SchulconnexLaufzeitResponse, lernperiodeFormat } from './schulconnex-laufzeit-response';
export * from './lizenz-info';
export * from './policies-info';

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export { SchulconnexPoliciesInfoTargetResponse } from './schulconnex-policies-info-target-response';
export { SchulconnexPoliciesInfoResponse } from './schulconnex-policies-info-response';
export { SchulconnexPoliciesInfoActionType } from './schulconnex-policies-info-action-type';
export { SchulconnexPoliciesInfoPermissionResponse } from './schulconnex-policies-info-permission-response';
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export enum SchulconnexPoliciesInfoActionType {
EXECUTE = 'execute',
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { IsArray } from 'class-validator';
import { SchulconnexPoliciesInfoActionType } from './schulconnex-policies-info-action-type';

export class SchulconnexPoliciesInfoPermissionResponse {
@IsArray()
action!: SchulconnexPoliciesInfoActionType[];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Type } from 'class-transformer';
import { IsArray, IsObject, ValidateNested } from 'class-validator';
import { SchulconnexPoliciesInfoPermissionResponse } from './schulconnex-policies-info-permission-response';
import { SchulconnexPoliciesInfoTargetResponse } from './schulconnex-policies-info-target-response';

export class SchulconnexPoliciesInfoResponse {
@IsObject()
@ValidateNested()
@Type(() => SchulconnexPoliciesInfoTargetResponse)
target!: SchulconnexPoliciesInfoTargetResponse;

@IsArray()
@ValidateNested({ each: true })
@Type(() => SchulconnexPoliciesInfoPermissionResponse)
permission!: SchulconnexPoliciesInfoPermissionResponse[];
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IsOptional, IsString } from 'class-validator';

export class SchulconnexLizenzInfoTargetResponse {
export class SchulconnexPoliciesInfoTargetResponse {
@IsString()
uid!: string;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { SchulconnexPersonenInfoParams } from './request';
import { SchulconnexLizenzInfoResponse, SchulconnexResponse } from './response';
import { SchulconnexPoliciesInfoResponse, SchulconnexResponse } from './response';

export interface SchulconnexApiInterface {
getPersonInfo(accessToken: string, options?: { overrideUrl: string }): Promise<SchulconnexResponse>;

getPersonenInfo(params: SchulconnexPersonenInfoParams): Promise<SchulconnexResponse[]>;

getLizenzInfo(accessToken: string, options?: { overrideUrl: string }): Promise<SchulconnexLizenzInfoResponse[]>;
getPoliciesInfo(accessToken: string, options?: { overrideUrl: string }): Promise<SchulconnexPoliciesInfoResponse[]>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import { axiosResponseFactory } from '@shared/testing';
import { Logger } from '@src/core/logger';
import { of } from 'rxjs';
import { SchulconnexConfigurationMissingLoggable } from './loggable';
import { SchulconnexLizenzInfoResponse, SchulconnexResponse } from './response';
import { SchulconnexPoliciesInfoResponse, SchulconnexResponse } from './response';
import { SchulconnexRestClient } from './schulconnex-rest-client';
import { SchulconnexRestClientOptions } from './schulconnex-rest-client-options';
import { schulconnexResponseFactory } from './testing';
import { schulconnexLizenzInfoResponseFactory } from './testing/schulconnex-lizenz-info-response-factory';
import { schulconnexPoliciesInfoResponseFactory, schulconnexResponseFactory } from './testing';

describe(SchulconnexRestClient.name, () => {
let client: SchulconnexRestClient;
Expand Down Expand Up @@ -196,11 +195,11 @@ describe(SchulconnexRestClient.name, () => {
});
});

describe('getLizenzInfo', () => {
describe('when requesting lizenz-info', () => {
describe('getPoliciesInfo', () => {
describe('when requesting policies-info', () => {
const setup = () => {
const accessToken = 'accessToken';
const response: SchulconnexLizenzInfoResponse[] = schulconnexLizenzInfoResponseFactory.buildList(1);
const response: SchulconnexPoliciesInfoResponse[] = schulconnexPoliciesInfoResponseFactory.buildList(1);

httpService.get.mockReturnValueOnce(of(axiosResponseFactory.build({ data: response })));

Expand All @@ -212,9 +211,9 @@ describe(SchulconnexRestClient.name, () => {
it('should make a request to a SchulConneX-API', async () => {
const { accessToken } = setup();

await client.getLizenzInfo(accessToken);
await client.getPoliciesInfo(accessToken);

expect(httpService.get).toHaveBeenCalledWith(`${options.apiUrl ?? ''}/lizenz-info`, {
expect(httpService.get).toHaveBeenCalledWith(`${options.apiUrl ?? ''}/policies-info`, {
headers: {
Authorization: `Bearer ${accessToken}`,
'Accept-Encoding': 'gzip',
Expand All @@ -225,7 +224,7 @@ describe(SchulconnexRestClient.name, () => {
it('should return the response', async () => {
const { accessToken } = setup();

const result: SchulconnexLizenzInfoResponse[] = await client.getLizenzInfo(accessToken);
const result: SchulconnexPoliciesInfoResponse[] = await client.getPoliciesInfo(accessToken);

expect(result).toBeDefined();
});
Expand All @@ -234,8 +233,8 @@ describe(SchulconnexRestClient.name, () => {
describe('when overriding the url', () => {
const setup = () => {
const accessToken = 'accessToken';
const customUrl = 'https://override.url/lizenz-info';
const response: SchulconnexLizenzInfoResponse[] = schulconnexLizenzInfoResponseFactory.buildList(1);
const customUrl = 'https://override.url/policies-info';
const response: SchulconnexPoliciesInfoResponse[] = schulconnexPoliciesInfoResponseFactory.buildList(1);

httpService.get.mockReturnValueOnce(of(axiosResponseFactory.build({ data: response })));

Expand All @@ -248,7 +247,7 @@ describe(SchulconnexRestClient.name, () => {
it('should make a request to a SchulConneX-API', async () => {
const { accessToken, customUrl } = setup();

await client.getLizenzInfo(accessToken, { overrideUrl: customUrl });
await client.getPoliciesInfo(accessToken, { overrideUrl: customUrl });

expect(httpService.get).toHaveBeenCalledWith(customUrl, expect.anything());
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import QueryString from 'qs';
import { lastValueFrom, Observable } from 'rxjs';
import { SchulconnexConfigurationMissingLoggable } from './loggable';
import { SchulconnexPersonenInfoParams } from './request';
import { SchulconnexLizenzInfoResponse, SchulconnexResponse } from './response';
import { SchulconnexPoliciesInfoResponse, SchulconnexResponse } from './response';
import { SchulconnexApiInterface } from './schulconnex-api.interface';
import { SchulconnexRestClientOptions } from './schulconnex-rest-client-options';

Expand Down Expand Up @@ -48,13 +48,13 @@ export class SchulconnexRestClient implements SchulconnexApiInterface {
return response;
}

public async getLizenzInfo(
public async getPoliciesInfo(
accessToken: string,
options?: { overrideUrl: string }
): Promise<SchulconnexLizenzInfoResponse[]> {
const url: URL = new URL(options?.overrideUrl ?? `${this.SCHULCONNEX_API_BASE_URL}/lizenz-info`);
): Promise<SchulconnexPoliciesInfoResponse[]> {
const url: URL = new URL(options?.overrideUrl ?? `${this.SCHULCONNEX_API_BASE_URL}/policies-info`);

const response: Promise<SchulconnexLizenzInfoResponse[]> = this.getRequest<SchulconnexLizenzInfoResponse[]>(
const response: Promise<SchulconnexPoliciesInfoResponse[]> = this.getRequest<SchulconnexPoliciesInfoResponse[]>(
url,
accessToken
);
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/infra/schulconnex-client/testing/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { schulconnexResponseFactory } from './schulconnex-response-factory';
export { schulconnexLizenzInfoResponseFactory } from './schulconnex-lizenz-info-response-factory';
export { schulconnexPoliciesInfoResponseFactory } from './schulconnex-policies-info-response-factory';

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Factory } from 'fishery';
import { SchulconnexPoliciesInfoActionType, SchulconnexPoliciesInfoResponse } from '../response';

export const schulconnexPoliciesInfoResponseFactory = Factory.define<SchulconnexPoliciesInfoResponse>(() => {
return {
target: {
uid: 'bildungscloud',
partOf: '',
},
permission: [
{
action: [SchulconnexPoliciesInfoActionType.EXECUTE],
},
],
};
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { ExternalUserDto } from '../dto';
import { FetchingPoliciesInfoFailedLoggable } from './fetching-policies-info-failed.loggable';

describe(FetchingPoliciesInfoFailedLoggable.name, () => {
describe('getLogMessage', () => {
const setup = () => {
const externalUserDto: ExternalUserDto = {
externalId: 'someId',
};
const policiesInfoEndpoint = 'someEndpoint';

const loggable = new FetchingPoliciesInfoFailedLoggable(externalUserDto, policiesInfoEndpoint);

return { loggable, externalUserDto, policiesInfoEndpoint };
};

it('should return a loggable message', () => {
const { loggable, externalUserDto, policiesInfoEndpoint } = setup();

const message = loggable.getLogMessage();

expect(message).toEqual({
message: 'Could not fetch policies info for user. The provisioning of licenses will be skipped.',
data: {
externalUserId: externalUserDto.externalId,
policiesInfoEndpoint,
},
});
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { ErrorLogMessage, Loggable, LogMessage, ValidationErrorLogMessage } from '@src/core/logger';
import { ExternalUserDto } from '../dto';

export class FetchingPoliciesInfoFailedLoggable implements Loggable {
constructor(private readonly user: ExternalUserDto, private readonly policiesInfoEndpoint: string) {}

getLogMessage(): LogMessage | ErrorLogMessage | ValidationErrorLogMessage {
return {
message: 'Could not fetch policies info for user. The provisioning of licenses will be skipped.',
data: {
externalUserId: this.user.externalId,
policiesInfoEndpoint: this.policiesInfoEndpoint,
},
};
}
}
1 change: 1 addition & 0 deletions apps/server/src/modules/provisioning/loggable/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './user-for-group-not-found.loggable';
export * from './school-for-group-not-found.loggable';
export * from './group-role-unknown.loggable';
export { SchoolExternalToolCreatedLoggable } from './school-external-tool-created.loggable';
export { FetchingPoliciesInfoFailedLoggable } from './fetching-policies-info-failed.loggable';
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export interface ProvisioningConfig {
FEATURE_SCHULCONNEX_COURSE_SYNC_ENABLED: boolean;
FEATURE_SCHULCONNEX_MEDIA_LICENSE_ENABLED: boolean;
PROVISIONING_SCHULCONNEX_LIZENZ_INFO_URL: string;
PROVISIONING_SCHULCONNEX_POLICIES_INFO_URL: string;
FEATURE_SANIS_GROUP_PROVISIONING_ENABLED: boolean;
FEATURE_OTHER_GROUPUSERS_PROVISIONING_ENABLED: boolean;
}
Loading

0 comments on commit 56607ad

Please sign in to comment.