debian-image-builder-frontend/src/test/mocks/cockpit/cockpitHTTP.ts
Sanne Raymaekers dc98ca032f test/mocks: expand cockpit mocks
Use the data from the regular fixtures, but through cockpit APIs.

There are a few hacks to get around the fact that there are no composes
without blueprints, and the lack of paging support in the cockpit api.
2025-02-06 10:55:45 +01:00

28 lines
797 B
TypeScript

/* eslint-disable @typescript-eslint/no-unused-vars */
import path from 'path';
import type { Method, Headers, Params } from '../../../store/cockpit/types';
import { mockStatus } from '../../fixtures/composes';
type requestOptions = {
path: string;
method: Method;
body: unknown;
headers: Headers | undefined;
params: Params | undefined;
};
export const cockpitHTTP = (address: string, attr: object) => {
return {
request: (request: requestOptions): Promise<string> => {
if (request.path.startsWith('/api/image-builder-composer/v2/composes/')) {
return new Promise((resolve) => {
resolve(JSON.stringify(mockStatus(path.parse(request.path).name)));
});
}
return new Promise((resolve) => {
resolve('');
});
},
};
};