Skip to content

Commit f20335b

Browse files
authored
Add mocks for code list endpoints (#14528)
1 parent 10be65e commit f20335b

File tree

7 files changed

+57
-0
lines changed

7 files changed

+57
-0
lines changed

frontend/packages/shared/src/api/mutations.ts

+9
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ import type { FormLayoutRequest } from 'app-shared/types/api/FormLayoutRequest';
7575
import type { Option } from 'app-shared/types/Option';
7676
import type { MaskinportenScopes } from 'app-shared/types/MaskinportenScope';
7777
import type { DataType } from '../types/DataType';
78+
import type { CodeListData } from 'app-shared/types/CodeListData';
79+
import type { CodeList } from 'app-shared/types/CodeList';
7880

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

168170
// Maskinporten
169171
export const updateSelectedMaskinportenScopes = (org: string, app: string, appScopesUpsertRequest: MaskinportenScopes) => put(selectedMaskinportenScopesPath(org, app), appScopesUpsertRequest);
172+
173+
// Organisation library:
174+
// Todo: Replace these with real API calls when endpoints are ready. https://github.com/Altinn/altinn-studio/issues/14505
175+
export const createCodeListForOrg = async (org: string, payload: CodeListData): Promise<void> => Promise.resolve();
176+
export const updateCodeListForOrg = async (org: string, codeListId: string, payload: CodeList): Promise<void> => Promise.resolve();
177+
export const deleteCodeListForOrg = async (org: string, codeListId: string): Promise<void> => Promise.resolve();
178+
export const uploadCodeListForOrg = async (org: string, app: string, payload: FormData): Promise<void> => Promise.resolve();

frontend/packages/shared/src/api/queries.ts

+5
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ import type { OptionListReferences } from 'app-shared/types/OptionListReferences
9999
import type { LayoutSetsModel } from '../types/api/dto/LayoutSetsModel';
100100
import type { AccessPackageResource, PolicyAccessPackageAreaGroup } from 'app-shared/types/PolicyAccessPackages';
101101
import type { DataType } from '../types/DataType';
102+
import { codeListsResponse } from '../mocks/codeListsResponse';
103+
import type { CodeListsResponse } from '../types/api/CodeListsResponse';
102104

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

177179
// Contact Page
178180
export const fetchBelongsToGiteaOrg = () => get(belongsToOrg());
181+
182+
// Organisation library
183+
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import type { CodeListsResponse } from '../types/api/CodeListsResponse';
2+
import type { CodeListData } from '@studio/content-library';
3+
4+
const codeList1: CodeListData = {
5+
title: 'codeList1',
6+
data: [
7+
{ label: 'Item 1', value: 'item1' },
8+
{ label: 'Item 2', value: 'item2' },
9+
],
10+
};
11+
12+
const codeList2: CodeListData = {
13+
title: 'codeList2',
14+
data: [
15+
{ label: 'A', value: 'a' },
16+
{ label: 'B', value: 'b' },
17+
{ label: 'C', value: 'c' },
18+
],
19+
};
20+
21+
const codeListWithError: CodeListData = {
22+
title: 'codeListWithError',
23+
hasError: true,
24+
};
25+
26+
export const codeListsResponse: CodeListsResponse = [codeList1, codeList2, codeListWithError];

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

+6
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ import type { OptionListReferences } from 'app-shared/types/OptionListReferences
7474
import type { LayoutSetsModel } from '../types/api/dto/LayoutSetsModel';
7575
import { layoutSetsExtendedMock } from '@altinn/ux-editor/testing/layoutSetsMock';
7676
import type { OptionListsResponse } from 'app-shared/types/api/OptionListsResponse';
77+
import type { CodeListsResponse } from 'app-shared/types/api/CodeListsResponse';
7778

7879
export const queriesMock: ServicesContextProps = {
7980
// Queries
@@ -83,6 +84,7 @@ export const queriesMock: ServicesContextProps = {
8384
.mockImplementation(() => Promise.resolve<AppReleasesResponse>(appReleasesResponse)),
8485
getAppVersion: jest.fn().mockImplementation(() => Promise.resolve<AppVersion>(appVersion)),
8586
getBranchStatus: jest.fn().mockImplementation(() => Promise.resolve<BranchStatus>(branchStatus)),
87+
getCodeListsForOrg: jest.fn().mockImplementation(() => Promise.resolve<CodeListsResponse>([])),
8688
getDataModel: jest.fn().mockImplementation(() => Promise.resolve<JsonSchema>({})),
8789
getDataModelMetadata: jest
8890
.fn()
@@ -214,6 +216,7 @@ export const queriesMock: ServicesContextProps = {
214216
.fn()
215217
.mockImplementation(() => Promise.resolve<CreateRepoCommitPayload>(createRepoCommitPayload)),
216218
copyApp: jest.fn().mockImplementation(() => Promise.resolve()),
219+
createCodeListForOrg: jest.fn().mockImplementation(() => Promise.resolve()),
217220
createDataModel: jest.fn().mockImplementation(() => Promise.resolve<JsonSchema>({})),
218221
updateDataType: jest.fn().mockImplementation(() => Promise.resolve<JsonSchema>({})),
219222
createDeployment: jest.fn().mockImplementation(() => Promise.resolve()),
@@ -222,6 +225,7 @@ export const queriesMock: ServicesContextProps = {
222225
.fn()
223226
.mockImplementation(() => Promise.resolve<CreateRepoCommitPayload>(createRepoCommitPayload)),
224227
deleteAppAttachmentMetadata: jest.fn().mockImplementation(() => Promise.resolve()),
228+
deleteCodeListForOrg: jest.fn().mockImplementation(() => Promise.resolve()),
225229
deleteDataModel: jest.fn().mockImplementation(() => Promise.resolve()),
226230
deleteDataTypeFromAppMetadata: jest.fn().mockImplementation(() => Promise.resolve()),
227231
deleteFormLayout: jest.fn().mockImplementation(() => Promise.resolve()),
@@ -248,8 +252,10 @@ export const queriesMock: ServicesContextProps = {
248252
updateAppPolicy: jest.fn().mockImplementation(() => Promise.resolve()),
249253
updateAppMetadata: jest.fn().mockImplementation(() => Promise.resolve()),
250254
updateAppConfig: jest.fn().mockImplementation(() => Promise.resolve()),
255+
updateCodeListForOrg: jest.fn().mockImplementation(() => Promise.resolve()),
251256
updateOptionList: jest.fn().mockImplementation(() => Promise.resolve()),
252257
updateOptionListId: jest.fn().mockImplementation(() => Promise.resolve()),
258+
uploadCodeListForOrg: jest.fn().mockImplementation(() => Promise.resolve()),
253259
uploadDataModel: jest.fn().mockImplementation(() => Promise.resolve<JsonSchema>({})),
254260
uploadOptionList: jest.fn().mockImplementation(() => Promise.resolve()),
255261
upsertTextResources: jest
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type { CodeList } from '@studio/components';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import type { CodeListItem } from '@studio/components';
2+
3+
export type CodeListData = {
4+
title: string;
5+
data?: CodeListItem[];
6+
hasError?: boolean;
7+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import type { CodeListData } from '../CodeListData';
2+
3+
export type CodeListsResponse = CodeListData[];

0 commit comments

Comments
 (0)