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

N21-939 api generation #2854

Merged
merged 11 commits into from
Oct 16, 2023
4 changes: 2 additions & 2 deletions src/pages/administration/ClassOverview.page.unit.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import GroupModule from "@/store/group";
import { createModuleMocks } from "@/utils/mock-store-module";
import { classInfoResponseFactory, i18nMock } from "@@/tests/test-utils";
import { classInfoFactory, i18nMock } from "@@/tests/test-utils";
import { MountOptions, Wrapper, mount } from "@vue/test-utils";
import ClassOverview from "./ClassOverview.page.vue";
import { GROUP_MODULE_KEY, I18N_KEY } from "@/utils/inject";
Expand All @@ -14,7 +14,7 @@ describe("ClassOverview", () => {
document.body.setAttribute("data-app", "true");

const groupModule = createModuleMocks(GroupModule, {
getClasses: [classInfoResponseFactory.build()],
getClasses: [classInfoFactory.build()],
getPagination: {
limit: 10,
skip: 0,
Expand Down
28 changes: 28 additions & 0 deletions src/serverApi/v3/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,18 @@ export enum ChangeLanguageParamsLanguageEnum {
* @interface ClassInfoResponse
*/
export interface ClassInfoResponse {
/**
*
* @type {string}
* @memberof ClassInfoResponse
*/
id: string;
/**
*
* @type {string}
* @memberof ClassInfoResponse
*/
type: ClassInfoResponseTypeEnum;
/**
*
* @type {string}
Expand All @@ -383,7 +395,23 @@ export interface ClassInfoResponse {
* @memberof ClassInfoResponse
*/
teachers: Array<string>;
/**
*
* @type {string}
* @memberof ClassInfoResponse
*/
schoolYear?: string;
}

/**
* @export
* @enum {string}
*/
export enum ClassInfoResponseTypeEnum {
Class = 'class',
Group = 'group'
}

/**
*
* @export
Expand Down
12 changes: 9 additions & 3 deletions src/store/group.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import {
classInfoResponseFactory,
classInfoSearchListResponseFactory,
} from "@@/tests/test-utils";
import { ClassInfo } from "./types/class-info";
import { ClassInfo, ClassRootType } from "./types/class-info";
import { BusinessError, Pagination } from "./types/commons";
import { SortOrder } from "./types/sort-order.enum";
import GroupModule from "./group";
import { DeepMocked, createMock } from "@golevelup/ts-jest";
import { createMock, DeepMocked } from "@golevelup/ts-jest";
import { mockApiResponse } from "@@/tests/test-utils/mockApiResponse";
import { mapAxiosErrorToResponseError } from "@/utils/api";

Expand Down Expand Up @@ -86,7 +86,13 @@ describe("GroupModule", () => {

it("should return the changed state", () => {
const classes: ClassInfo[] = [
{ name: "3a", externalSourceName: "Klasse", teachers: ["Carlie"] },
{
name: "3a",
externalSourceName: "Klasse",
teachers: ["Carlie"],
type: ClassRootType.Class,
id: "id",
},
];

module.setClasses(classes);
Expand Down
14 changes: 12 additions & 2 deletions src/store/group/group.mapper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { ClassInfoResponse } from "@/serverApi/v3";
import { ClassInfo } from "../types/class-info";
import { ClassInfoResponse, ClassInfoResponseTypeEnum } from "@/serverApi/v3";
import { ClassInfo, ClassRootType } from "../types/class-info";

export const ClassRootTypeMapping: Record<
ClassInfoResponseTypeEnum,
ClassRootType
> = {
[ClassInfoResponseTypeEnum.Class]: ClassRootType.Class,
[ClassInfoResponseTypeEnum.Group]: ClassRootType.Group,
};

export class GroupMapper {
static mapToClassInfo(response: ClassInfoResponse[]): ClassInfo[] {
Expand All @@ -8,6 +16,8 @@ export class GroupMapper {
name: classInfoResponse.name,
externalSourceName: classInfoResponse.externalSourceName,
teachers: classInfoResponse.teachers,
type: ClassRootTypeMapping[classInfoResponse.type],
id: classInfoResponse.id,
})
);

Expand Down
7 changes: 7 additions & 0 deletions src/store/types/class-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,11 @@ export type ClassInfo = {
name: string;
externalSourceName?: string;
teachers: string[];
type: ClassRootType;
id: string;
};

export enum ClassRootType {
Class = "class",
Group = "group",
}
10 changes: 10 additions & 0 deletions tests/test-utils/factory/classInfoFactory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Factory } from "fishery";
import { ClassInfo, ClassRootType } from "@/store/types/class-info";

export const classInfoFactory = Factory.define<ClassInfo>(({ sequence }) => ({
name: `className${sequence}`,
externalSourceName: "Source",
teachers: ["TestTeacher"],
type: ClassRootType.Class,
id: `id-${sequence}`,
}));
8 changes: 5 additions & 3 deletions tests/test-utils/factory/classInfoResponseFactory.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { ClassInfoResponse } from "@/serverApi/v3";
import { ClassInfoResponse, ClassInfoResponseTypeEnum } from "@/serverApi/v3";
import { Factory } from "fishery";

export const classInfoResponseFactory = Factory.define<ClassInfoResponse>(
() => ({
name: "className",
({ sequence }) => ({
name: `className${sequence}`,
externalSourceName: "Source",
teachers: ["TestTeacher"],
type: ClassInfoResponseTypeEnum.Class,
id: `id-${sequence}`,
MBergCap marked this conversation as resolved.
Show resolved Hide resolved
})
);
1 change: 1 addition & 0 deletions tests/test-utils/factory/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export * from "./businessErrorFactory";
export * from "./cardSkeletonResponseFactory";
export * from "./classInfoSearchListResponseFactory";
export * from "./classInfoResponseFactory";
export * from "./classInfoFactory";
export * from "./columnResponseFactory";
export * from "./contextExternalToolConfigurationTemplate.factory";
export * from "./contextExternalToolConfigurationTemplateResponseFactory";
Expand Down
Loading