MSW: Add mock definition for /provisioning/v1/sources end point
This commit adds the necessarily handler, resolver, and server to use
MSW for mocking the /provisioning/v1/sources endpoint.
The server can be used in tests like so:
```javascript
// src/setupTests.js
import { server } from './mocks/server.js'
// Establish API mocking before all tests.
beforeAll(() => server.listen())
// Reset any request handlers that we may add during the tests,
// so they don't affect other tests.
afterEach(() => server.resetHandlers())
// Clean up after the tests are finished.
afterAll(() => server.close())
```
This commit is contained in:
parent
9d8236ad76
commit
131559b351
4 changed files with 31 additions and 2 deletions
|
|
@ -1,6 +1,7 @@
|
|||
export const IMAGE_BUILDER_API = '/api/image-builder/v1';
|
||||
export const RHSM_API = '/api/rhsm/v2';
|
||||
export const CONTENT_SOURCES = '/api/content-sources/v1';
|
||||
export const PROVISIONING_SOURCES_ENDPOINT = '/api/provisioning/v1/sources';
|
||||
export const RHEL_8 = 'rhel-87';
|
||||
export const RHEL_9 = 'rhel-91';
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
|
||||
|
||||
import { PROVISIONING_SOURCES_ENDPOINT } from '../constants';
|
||||
|
||||
export const apiSlice = createApi({
|
||||
reducerPath: 'api',
|
||||
baseQuery: fetchBaseQuery({ baseUrl: '/api' }),
|
||||
baseQuery: fetchBaseQuery({ baseUrl: '' }),
|
||||
endpoints: (builder) => ({
|
||||
getSources: builder.query({
|
||||
query: () => '/provisioning/v1/sources',
|
||||
query: () => PROVISIONING_SOURCES_ENDPOINT,
|
||||
}),
|
||||
}),
|
||||
});
|
||||
|
|
|
|||
21
src/test/mocks/handlers.js
Normal file
21
src/test/mocks/handlers.js
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import { rest } from 'msw';
|
||||
|
||||
import { PROVISIONING_SOURCES_ENDPOINT } from '../../constants';
|
||||
|
||||
const baseURL = 'http://localhost';
|
||||
|
||||
export const handlers = [
|
||||
rest.get(baseURL.concat(PROVISIONING_SOURCES_ENDPOINT), (req, res, ctx) => {
|
||||
return res(
|
||||
ctx.status(200),
|
||||
ctx.json([
|
||||
{
|
||||
id: '123',
|
||||
name: 'my_source',
|
||||
source_type_id: '1',
|
||||
uid: 'de5e35d4-4c1f-49d7-9ef3-7d08e6b9c76a',
|
||||
},
|
||||
])
|
||||
);
|
||||
}),
|
||||
];
|
||||
5
src/test/mocks/server.js
Normal file
5
src/test/mocks/server.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import { setupServer } from 'msw/node';
|
||||
|
||||
import { handlers } from './handlers';
|
||||
|
||||
export const server = setupServer(...handlers);
|
||||
Loading…
Add table
Add a link
Reference in a new issue