Skip to content

Commit

Permalink
Merge branch 'main' into EW-1019
Browse files Browse the repository at this point in the history
  • Loading branch information
mkreuzkam-cap authored Dec 18, 2024
2 parents c734169 + 6133a8e commit 91d5632
Show file tree
Hide file tree
Showing 67 changed files with 2,424 additions and 443 deletions.
16 changes: 8 additions & 8 deletions ansible/roles/common-cartridge/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@
- service

# This is a testing route and will not be deployed
# - name: Ingress
# kubernetes.core.k8s:
# kubeconfig: ~/.kube/config
# namespace: "{{ NAMESPACE }}"
# template: ingress.yml.j2
# when: WITH_COMMON_CARTRIDGE is defined and WITH_COMMON_CARTRIDGE|bool
# tags:
# - ingress
- name: Ingress
kubernetes.core.k8s:
kubeconfig: ~/.kube/config
namespace: "{{ NAMESPACE }}"
template: ingress.yml.j2
when: WITH_COMMON_CARTRIDGE is defined and WITH_COMMON_CARTRIDGE|bool
tags:
- ingress
19 changes: 19 additions & 0 deletions apps/server/src/core/error/domain/domain-error-handler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import { Test, TestingModule } from '@nestjs/testing';
import { BusinessError } from '@shared/common';
import { ErrorLogger, ErrorLogMessage, Loggable, LogMessage, ValidationErrorLogMessage } from '@src/core/logger';
import util from 'util';
import { AxiosError } from 'axios';
import { ErrorLoggable } from '../loggable/error.loggable';
import { ErrorUtils } from '../utils';
import { AxiosErrorLoggable } from '../loggable';
import { DomainErrorHandler } from './domain-error-handler';

class SampleLoggableException extends BadRequestException implements Loggable {
Expand Down Expand Up @@ -201,5 +203,22 @@ describe('GlobalErrorFilter', () => {
expect(logger.error).toBeCalledWith(loggable);
});
});

describe('when error is a axios error', () => {
const setup = () => {
const error = new AxiosError('test');
const axiosLoggable = new AxiosErrorLoggable(error, 'AXIOS_REQUEST_ERROR');

return { axiosLoggable };
};

it('should call logger with axios error', () => {
const { axiosLoggable } = setup();

domainErrorHandler.exec(axiosLoggable);

expect(logger.error).toBeCalledWith(axiosLoggable);
});
});
});
});
21 changes: 21 additions & 0 deletions apps/server/src/core/error/filter/global-error.filter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { WsException } from '@nestjs/websockets';
import { BusinessError } from '@shared/common';
import { ErrorLogMessage, Loggable } from '@src/core/logger';
import { Response } from 'express';
import { AxiosError } from 'axios';
import { DomainErrorHandler } from '../domain';
import { ErrorResponse } from '../dto';
import { ErrorUtils } from '../utils';
Expand Down Expand Up @@ -102,6 +103,26 @@ describe('GlobalErrorFilter', () => {
});
});

describe('given context is axios', () => {
const setup = () => {
const argumentsHost = createMock<ArgumentsHost>();
argumentsHost.getType.mockReturnValueOnce(UseableContextType.http);

const error = new AxiosError('test');

return { error, argumentsHost };
};

it('should call exec on domain error handler', () => {
const { error, argumentsHost } = setup();

service.catch(error, argumentsHost);

expect(domainErrorHandler.execHttpContext).toBeCalledWith(error, {});
expect(domainErrorHandler.execHttpContext).toBeCalledTimes(1);
});
});

describe('given context is http', () => {
const mockHttpArgumentsHost = () => {
const argumentsHost = createMock<ArgumentsHost>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CardResponseDto } from './card-response.dto';

export class CardListResponseDto {
data: CardResponseDto[];
public data: CardResponseDto[];

constructor(data: CardResponseDto[]) {
this.data = data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,24 @@ import { TimestampResponseDto } from './timestamp-response.dto';
import { VisibilitySettingsResponseDto } from './visibility-settings-response.dto';

export class CardResponseDto {
id: string;
public id: string;

title?: string;
public title?: string;

height: number;
public height: number;

elements: Array<CardResponseElementsInnerDto>;
public elements: Array<CardResponseElementsInnerDto>;

visibilitySettings: VisibilitySettingsResponseDto;
public visibilitySettings: VisibilitySettingsResponseDto;

timeStamps: TimestampResponseDto;
public timeStamps: TimestampResponseDto;

constructor(
id: string,
title: string,
height: number,
elements: CardResponseElementsInnerDto[],
visibilitySettings: VisibilitySettingsResponseDto,
timestamps: TimestampResponseDto
) {
this.id = id;
this.title = title;
this.height = height;
this.elements = elements;
this.visibilitySettings = visibilitySettings;
this.timeStamps = timestamps;
constructor(props: Readonly<CardResponseDto>) {
this.id = props.id;
this.title = props.title;
this.height = props.height;
this.elements = props.elements;
this.visibilitySettings = props.visibilitySettings;
this.timeStamps = props.timeStamps;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { ContentElementType } from '../cards-api-client';
import { TimestampResponseDto } from './timestamp-response.dto';

export class CollaborativeTextEditorElementResponseDto {
id: string;
public id: string;

type: ContentElementType;
public type: ContentElementType;

timestamps: TimestampResponseDto;
public timestamps: TimestampResponseDto;

content: object;
public content: object;

constructor(id: string, type: ContentElementType, content: object, timestamps: TimestampResponseDto) {
this.id = id;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export { RichTextElementResponseDto } from './rich-text-element-response.dto';
export { RichTextElementContentDto } from './rich-text-element-content.dto';
export { LinkElementContentDto } from './link-element-content.dto';
export { LinkElementResponseDto } from './link-element-response.dto';
export { CardResponseDto } from './card-response.dto';
export { CardListResponseDto } from './card-list-response.dto';
export { TimestampResponseDto } from './timestamp-response.dto';
export { VisibilitySettingsResponseDto } from './visibility-settings-response.dto';
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
export class LinkElementContentDto {
url: string;
public url: string;

title: string;
public title: string;

description?: string;
public description?: string;

imageUrl?: string;
public imageUrl?: string;

constructor(url: string, title: string, description: string, imageUrl: string) {
this.url = url;
this.title = title;
this.description = description;
this.imageUrl = imageUrl;
constructor(props: Readonly<LinkElementContentDto>) {
this.url = props.url;
this.title = props.title;
this.description = props.description;
this.imageUrl = props.imageUrl;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@ import { LinkElementContentDto } from './link-element-content.dto';
import { TimestampResponseDto } from './timestamp-response.dto';

export class LinkElementResponseDto {
id: string;
public id: string;

type: ContentElementType;
public type: ContentElementType;

content: LinkElementContentDto;
public content: LinkElementContentDto;

timestamps: TimestampResponseDto;
public timestamps: TimestampResponseDto;

constructor(id: string, type: ContentElementType, content: LinkElementContentDto, timestamps: TimestampResponseDto) {
this.id = id;
this.type = type;
this.content = content;
this.timestamps = timestamps;
constructor(props: LinkElementResponseDto) {
this.id = props.id;
this.type = props.type;
this.content = props.content;
this.timestamps = props.timestamps;
}

public static isLinkElement(reference: unknown): reference is LinkElementResponseDto {
return reference instanceof LinkElementResponseDto;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export class RichTextElementContentDto {
text: string;
public text: string;

inputFormat: string;
public inputFormat: string;

constructor(text: string, inputFormat: string) {
this.text = text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,22 @@ import { RichTextElementContentDto } from './rich-text-element-content.dto';
import { TimestampResponseDto } from './timestamp-response.dto';

export class RichTextElementResponseDto {
id: string;
public id: string;

type: ContentElementType;
public type: ContentElementType;

content: RichTextElementContentDto;
public content: RichTextElementContentDto;

timestamps: TimestampResponseDto;
public timestamps: TimestampResponseDto;

constructor(
id: string,
type: ContentElementType,
content: RichTextElementContentDto,
timestamps: TimestampResponseDto
) {
this.id = id;
this.type = type;
this.content = content;
this.timestamps = timestamps;
constructor(props: Readonly<RichTextElementResponseDto>) {
this.id = props.id;
this.type = props.type;
this.content = props.content;
this.timestamps = props.timestamps;
}

public static isRichTextElement(reference: unknown): reference is RichTextElementResponseDto {
return reference instanceof RichTextElementResponseDto;
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
export class TimestampResponseDto {
lastUpdatedAt: string;
public lastUpdatedAt: string;

createdAt: string;
public createdAt: string;

deletedAt?: string;
public deletedAt?: string;

constructor(lastUpdatedAt: string, createdAt: string, deletedAt: string) {
this.lastUpdatedAt = lastUpdatedAt;
this.createdAt = createdAt;
this.deletedAt = deletedAt;
constructor(props: Readonly<TimestampResponseDto>) {
this.lastUpdatedAt = props.lastUpdatedAt;
this.createdAt = props.createdAt;
this.deletedAt = props.deletedAt;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,5 @@ describe('CardResponseMapper', () => {
expect(cardResponse.visibilitySettings.publishedAt).toBe('');
});
});

describe('when deletedAt in TimestampsResponse is null', () => {
const mockList: CardListResponse = setup([]);
mockList.data[0].timestamps.deletedAt = undefined;

it('should return an empty string', () => {
const mapperResult = CardResponseMapper.mapToCardListResponseDto(mockList);
const cardResponse: CardResponseDto = mapperResult.data[0];

expect(cardResponse.timeStamps.deletedAt).toBe('');
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ export class CardResponseMapper {
}

private static mapToCardResponseDto(cardResponse: CardResponse): CardResponseDto {
return new CardResponseDto(
cardResponse.id,
cardResponse.title ?? '',
cardResponse.height,
this.mapToCardResponseElementsInnerDto(cardResponse.elements),
this.mapToVisibilitySettingsDto(cardResponse.visibilitySettings),
this.mapToTimestampDto(cardResponse.timestamps)
);
return new CardResponseDto({
id: cardResponse.id,
title: cardResponse.title,
height: cardResponse.height,
elements: this.mapToCardResponseElementsInnerDto(cardResponse.elements),
visibilitySettings: this.mapToVisibilitySettingsDto(cardResponse.visibilitySettings),
timeStamps: this.mapToTimestampDto(cardResponse.timestamps),
});
}

private static mapToCardResponseElementsInnerDto(
Expand Down Expand Up @@ -138,24 +138,28 @@ export class CardResponseMapper {
case ContentElementType.LINK: {
const content: LinkElementContent = element.content as LinkElementContent;
elements.push(
new LinkElementResponseDto(
element.id,
ContentElementType.LINK,
new LinkElementContentDto(content.url, content.title, content.description ?? '', content.imageUrl ?? ''),
this.mapToTimestampDto(element.timestamps)
)
new LinkElementResponseDto({
id: element.id,
type: ContentElementType.LINK,
content: new LinkElementContentDto({
url: content.url,
title: content.title,
description: content.description,
}),
timestamps: this.mapToTimestampDto(element.timestamps),
})
);
break;
}
case ContentElementType.RICH_TEXT: {
const content: RichTextElementContent = element.content as RichTextElementContent;
elements.push(
new RichTextElementResponseDto(
element.id,
ContentElementType.RICH_TEXT,
new RichTextElementContentDto(content.text, content.inputFormat),
this.mapToTimestampDto(element.timestamps)
)
new RichTextElementResponseDto({
id: element.id,
type: ContentElementType.RICH_TEXT,
content: new RichTextElementContentDto(content.text, content.inputFormat),
timestamps: this.mapToTimestampDto(element.timestamps),
})
);
break;
}
Expand Down Expand Up @@ -185,6 +189,10 @@ export class CardResponseMapper {
}

private static mapToTimestampDto(timestamp: TimestampsResponse): TimestampResponseDto {
return new TimestampResponseDto(timestamp.lastUpdatedAt, timestamp.createdAt, timestamp.deletedAt ?? '');
return new TimestampResponseDto({
lastUpdatedAt: timestamp.lastUpdatedAt,
createdAt: timestamp.createdAt,
deletedAt: timestamp.deletedAt,
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe(CoursesClientAdapter.name, () => {

expect(coursesApi.courseControllerGetCourseCcMetadataById).toHaveBeenCalledWith(courseId, expectedOptions);
expect(result.id).toBeDefined();
expect(result.title).toBeDefined();
expect(result.courseName).toBeDefined();
expect(result.creationDate).toBeDefined();
expect(result.copyRightOwners).toBeDefined();
});
Expand Down
Loading

0 comments on commit 91d5632

Please sign in to comment.