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

Add mocks for code list endpoints #14528

Merged
merged 4 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions frontend/packages/shared/src/api/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ import type { FormLayoutRequest } from 'app-shared/types/api/FormLayoutRequest';
import type { Option } from 'app-shared/types/Option';
import type { MaskinportenScopes } from 'app-shared/types/MaskinportenScope';
import type { DataType } from '../types/DataType';
import type { CodeListData } from 'app-shared/types/CodeListData';
import type { CodeList } from 'app-shared/types/CodeList';

const headers = {
Accept: 'application/json',
Expand Down Expand Up @@ -167,3 +169,10 @@ export const updateProcessDataTypes = (org: string, app: string, dataTypesChange

// Maskinporten
export const updateSelectedMaskinportenScopes = (org: string, app: string, appScopesUpsertRequest: MaskinportenScopes) => put(selectedMaskinportenScopesPath(org, app), appScopesUpsertRequest);

// Organisation library:
// Todo: Replace these with real API calls when endpoints are ready. https://github.com/Altinn/altinn-studio/issues/14505
export const createCodeListForOrg = async (org: string, payload: CodeListData): Promise<void> => Promise.resolve();
export const updateCodeListForOrg = async (org: string, codeListId: string, payload: CodeList): Promise<void> => Promise.resolve();
export const deleteCodeListForOrg = async (org: string, codeListId: string): Promise<void> => Promise.resolve();
export const uploadCodeListForOrg = async (org: string, app: string, payload: FormData): Promise<void> => Promise.resolve();
5 changes: 5 additions & 0 deletions frontend/packages/shared/src/api/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ import type { OptionListReferences } from 'app-shared/types/OptionListReferences
import type { LayoutSetsModel } from '../types/api/dto/LayoutSetsModel';
import type { AccessPackageResource, PolicyAccessPackageAreaGroup } from 'app-shared/types/PolicyAccessPackages';
import type { DataType } from '../types/DataType';
import { codeListsResponse } from '../mocks/codeListsResponse';
import type { CodeListsResponse } from '../types/api/CodeListsResponse';

export const getIsLoggedInWithAnsattporten = () => get<{ isLoggedIn: boolean }>(authStatusAnsattporten());
export const getMaskinportenScopes = (org: string, app: string) => get<MaskinportenScopes>(availableMaskinportenScopesPath(org, app));
Expand Down Expand Up @@ -176,3 +178,6 @@ export const getProcessTaskType = (org: string, app: string, taskId: string) =>

// Contact Page
export const fetchBelongsToGiteaOrg = () => get(belongsToOrg());

// Organisation library
export const getCodeListsForOrg = async (org: string): Promise<CodeListsResponse> => Promise.resolve(codeListsResponse); // Todo: Replace with real API call when endpoint is ready. https://github.com/Altinn/altinn-studio/issues/14505
26 changes: 26 additions & 0 deletions frontend/packages/shared/src/mocks/codeListsResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { CodeListsResponse } from '../types/api/CodeListsResponse';
import type { CodeListData } from '@studio/content-library';

const codeList1: CodeListData = {
title: 'codeList1',
data: [
{ label: 'Item 1', value: 'item1' },
{ label: 'Item 2', value: 'item2' },
],
};

const codeList2: CodeListData = {
title: 'codeList2',
data: [
{ label: 'A', value: 'a' },
{ label: 'B', value: 'b' },
{ label: 'C', value: 'c' },
],
};

const codeListWithError: CodeListData = {
title: 'codeListWithError',
hasError: true,
};

export const codeListsResponse: CodeListsResponse = [codeList1, codeList2, codeListWithError];
6 changes: 6 additions & 0 deletions frontend/packages/shared/src/mocks/queriesMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
import type { LayoutSetsModel } from '../types/api/dto/LayoutSetsModel';
import { layoutSetsExtendedMock } from '@altinn/ux-editor/testing/layoutSetsMock';
import type { OptionListsResponse } from 'app-shared/types/api/OptionListsResponse';
import type { CodeListsResponse } from 'app-shared/types/api/CodeListsResponse';

export const queriesMock: ServicesContextProps = {
// Queries
Expand All @@ -83,6 +84,7 @@
.mockImplementation(() => Promise.resolve<AppReleasesResponse>(appReleasesResponse)),
getAppVersion: jest.fn().mockImplementation(() => Promise.resolve<AppVersion>(appVersion)),
getBranchStatus: jest.fn().mockImplementation(() => Promise.resolve<BranchStatus>(branchStatus)),
getCodeListsForOrg: jest.fn().mockImplementation(() => Promise.resolve<CodeListsResponse>([])),

Check warning on line 87 in frontend/packages/shared/src/mocks/queriesMock.ts

View check run for this annotation

Codecov / codecov/patch

frontend/packages/shared/src/mocks/queriesMock.ts#L87

Added line #L87 was not covered by tests
getDataModel: jest.fn().mockImplementation(() => Promise.resolve<JsonSchema>({})),
getDataModelMetadata: jest
.fn()
Expand Down Expand Up @@ -214,6 +216,7 @@
.fn()
.mockImplementation(() => Promise.resolve<CreateRepoCommitPayload>(createRepoCommitPayload)),
copyApp: jest.fn().mockImplementation(() => Promise.resolve()),
createCodeListForOrg: jest.fn().mockImplementation(() => Promise.resolve()),

Check warning on line 219 in frontend/packages/shared/src/mocks/queriesMock.ts

View check run for this annotation

Codecov / codecov/patch

frontend/packages/shared/src/mocks/queriesMock.ts#L219

Added line #L219 was not covered by tests
createDataModel: jest.fn().mockImplementation(() => Promise.resolve<JsonSchema>({})),
updateDataType: jest.fn().mockImplementation(() => Promise.resolve<JsonSchema>({})),
createDeployment: jest.fn().mockImplementation(() => Promise.resolve()),
Expand All @@ -222,6 +225,7 @@
.fn()
.mockImplementation(() => Promise.resolve<CreateRepoCommitPayload>(createRepoCommitPayload)),
deleteAppAttachmentMetadata: jest.fn().mockImplementation(() => Promise.resolve()),
deleteCodeListForOrg: jest.fn().mockImplementation(() => Promise.resolve()),

Check warning on line 228 in frontend/packages/shared/src/mocks/queriesMock.ts

View check run for this annotation

Codecov / codecov/patch

frontend/packages/shared/src/mocks/queriesMock.ts#L228

Added line #L228 was not covered by tests
deleteDataModel: jest.fn().mockImplementation(() => Promise.resolve()),
deleteDataTypeFromAppMetadata: jest.fn().mockImplementation(() => Promise.resolve()),
deleteFormLayout: jest.fn().mockImplementation(() => Promise.resolve()),
Expand All @@ -248,8 +252,10 @@
updateAppPolicy: jest.fn().mockImplementation(() => Promise.resolve()),
updateAppMetadata: jest.fn().mockImplementation(() => Promise.resolve()),
updateAppConfig: jest.fn().mockImplementation(() => Promise.resolve()),
updateCodeListForOrg: jest.fn().mockImplementation(() => Promise.resolve()),

Check warning on line 255 in frontend/packages/shared/src/mocks/queriesMock.ts

View check run for this annotation

Codecov / codecov/patch

frontend/packages/shared/src/mocks/queriesMock.ts#L255

Added line #L255 was not covered by tests
updateOptionList: jest.fn().mockImplementation(() => Promise.resolve()),
updateOptionListId: jest.fn().mockImplementation(() => Promise.resolve()),
uploadCodeListForOrg: jest.fn().mockImplementation(() => Promise.resolve()),

Check warning on line 258 in frontend/packages/shared/src/mocks/queriesMock.ts

View check run for this annotation

Codecov / codecov/patch

frontend/packages/shared/src/mocks/queriesMock.ts#L258

Added line #L258 was not covered by tests
uploadDataModel: jest.fn().mockImplementation(() => Promise.resolve<JsonSchema>({})),
uploadOptionList: jest.fn().mockImplementation(() => Promise.resolve()),
upsertTextResources: jest
Expand Down
1 change: 1 addition & 0 deletions frontend/packages/shared/src/types/CodeList.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type { CodeList } from '@studio/components';
7 changes: 7 additions & 0 deletions frontend/packages/shared/src/types/CodeListData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { CodeListItem } from '@studio/components';

export type CodeListData = {
title: string;
data?: CodeListItem[];
hasError?: boolean;
};
3 changes: 3 additions & 0 deletions frontend/packages/shared/src/types/api/CodeListsResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import type { CodeListData } from '../CodeListData';

export type CodeListsResponse = CodeListData[];
Loading