rtk: Add base to url and fix mock handler

This commit is contained in:
Ondrej Ezr 2024-07-18 12:47:57 +02:00 committed by Klara Simickova
parent 797ceddcd1
commit a1a49806e1
9 changed files with 3670 additions and 5233 deletions

View file

@ -117,7 +117,7 @@ import { FOOBAR_API } from '../constants';
// initialize an empty api service that we'll inject endpoints into later as needed
export const emptyFoobarApi = createApi({
reducerPath: 'foobarApi',
baseQuery: fetchBaseQuery({ baseUrl: FOO_BAR }),
baseQuery: fetchBaseQuery({ baseUrl: window.location.origin + FOO_BAR }),
endpoints: () => ({}),
});
```

8877
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -5,6 +5,8 @@ import { CONTENT_SOURCES_API } from '../constants';
// initialize an empty api service that we'll inject endpoints into later as needed
export const emptyContentSourcesApi = createApi({
reducerPath: 'contentSourcesApi',
baseQuery: fetchBaseQuery({ baseUrl: CONTENT_SOURCES_API }),
baseQuery: fetchBaseQuery({
baseUrl: window.location.origin + CONTENT_SOURCES_API,
}),
endpoints: () => ({}),
});

View file

@ -5,6 +5,6 @@ import { EDGE_API } from '../constants';
// initialize an empty api service that we'll inject endpoints into later as needed
export const emptyEdgeApi = createApi({
reducerPath: 'edgeApi',
baseQuery: fetchBaseQuery({ baseUrl: EDGE_API }),
baseQuery: fetchBaseQuery({ baseUrl: window.location.origin + EDGE_API }),
endpoints: () => ({}),
});

View file

@ -6,7 +6,7 @@ import { IMAGE_BUILDER_API } from '../constants';
export const emptyImageBuilderApi = createApi({
reducerPath: 'imageBuilderApi',
baseQuery: fetchBaseQuery({
baseUrl: IMAGE_BUILDER_API,
baseUrl: window.location.origin + IMAGE_BUILDER_API,
prepareHeaders: (headers) => {
// help the backend distinguish between requests from the UI and the API
headers.set('X-ImageBuilder-ui', 'true');

View file

@ -5,6 +5,8 @@ import { PROVISIONING_API } from '../constants';
// initialize an empty api service that we'll inject endpoints into later as needed
export const emptyProvisioningApi = createApi({
reducerPath: 'provisioningApi',
baseQuery: fetchBaseQuery({ baseUrl: PROVISIONING_API }),
baseQuery: fetchBaseQuery({
baseUrl: window.location.origin + PROVISIONING_API,
}),
endpoints: () => ({}),
});

View file

@ -5,6 +5,6 @@ import { RHSM_API } from '../constants';
// initialize an empty api service that we'll inject endpoints into later as needed
export const emptyRhsmApi = createApi({
reducerPath: 'rhsmApi',
baseQuery: fetchBaseQuery({ baseUrl: RHSM_API }),
baseQuery: fetchBaseQuery({ baseUrl: window.location.origin + RHSM_API }),
endpoints: () => ({}),
});

View file

@ -16,9 +16,9 @@ type RequestTypes = 'GET' | 'PUT' | 'POST' | 'DELETE';
export function spyOnRequest(pathname: string, method: RequestTypes) {
return new Promise((resolve) => {
// @ts-expect-error Parameter 'name' implicitly has an 'any' type.ts(7006)
const listener = async (req) => {
if (req.url.pathname === pathname && req.method === method) {
const listener = async ({ request: req }: { request: Request }) => {
const url = new URL(req.url);
if (url.pathname === pathname && req.method === method) {
const requestData = await req.clone().json();
resolve(requestData);
// Cleanup listener after successful intercept

View file

@ -1,10 +1,10 @@
import { configure } from '@testing-library/react';
import nodeFetch, { Request, Response } from 'node-fetch';
// import nodeFetch, { Request, Response } from 'node-fetch';
import { server } from './mocks/server';
import 'vitest-canvas-mock';
Object.assign(global, { fetch: nodeFetch, Request, Response });
// Object.assign(global, { fetch: nodeFetch, Request, Response });
// scrollTo is not defined in jsdom - needed for the navigation to the wizard
window.HTMLElement.prototype.scrollTo = function () {};