Mock Service Worker: Add image handlers
This commit adds handlers to MSW for the composes, clones, and their respective status routes.
This commit is contained in:
parent
5bf3f5af35
commit
c3e86b95fd
3 changed files with 74 additions and 44 deletions
|
|
@ -36,7 +36,7 @@ jest.spyOn(api, 'getComposeStatus').mockImplementation((id) => {
|
|||
|
||||
jest.spyOn(api, 'getClones').mockImplementation((id) => {
|
||||
return id === '1579d95b-8f1d-4982-8c53-8c2afa4ab04c'
|
||||
? Promise.resolve(mockClones)
|
||||
? Promise.resolve(mockClones(id))
|
||||
: Promise.resolve(mockNoClones);
|
||||
});
|
||||
|
||||
|
|
@ -280,22 +280,22 @@ describe('Clones table', () => {
|
|||
expect(cloneRows).toHaveLength(5);
|
||||
|
||||
// prepend parent data
|
||||
const composeId = '1579d95b-8f1d-4982-8c53-8c2afa4ab04c';
|
||||
const clonesTableData = {
|
||||
uuid: [
|
||||
'1579d95b-8f1d-4982-8c53-8c2afa4ab04c',
|
||||
...mockClones.data.map((clone) => clone.id),
|
||||
],
|
||||
uuid: [composeId, ...mockClones(composeId).data.map((clone) => clone.id)],
|
||||
created: [
|
||||
'2021-04-27 12:31:12.794809 +0000 UTC',
|
||||
...mockClones.data.map((clone) => clone.created_at),
|
||||
...mockClones(composeId).data.map((clone) => clone.created_at),
|
||||
],
|
||||
account: [
|
||||
'123123123123',
|
||||
...mockClones.data.map((clone) => clone.request.share_with_accounts[0]),
|
||||
...mockClones(composeId).data.map(
|
||||
(clone) => clone.request.share_with_accounts[0]
|
||||
),
|
||||
],
|
||||
region: [
|
||||
'us-east-1',
|
||||
...mockClones.data.map(
|
||||
...mockClones(composeId).data.map(
|
||||
(clone) => mockCloneStatus[clone.id].options.region
|
||||
),
|
||||
],
|
||||
|
|
|
|||
78
src/test/fixtures/composes.js
vendored
78
src/test/fixtures/composes.js
vendored
|
|
@ -10,7 +10,7 @@ export const mockComposesEmpty = {
|
|||
|
||||
// ImagesTable mocks
|
||||
const currentDate = new Date();
|
||||
const currentDateInString = currentDate.toString();
|
||||
const currentDateInString = currentDate.toISOString();
|
||||
|
||||
export const mockComposes = {
|
||||
meta: {
|
||||
|
|
@ -349,41 +349,47 @@ export const mockNoClones = {
|
|||
data: null,
|
||||
};
|
||||
|
||||
export const mockClones = {
|
||||
data: [
|
||||
{
|
||||
created_at: '2021-04-27 12:31:12.794809 +0000 UTC',
|
||||
id: 'f9133ec4-7a9e-4fd9-9a9f-9636b82b0a5d',
|
||||
request: {
|
||||
region: 'us-west-1',
|
||||
share_with_accounts: ['123123123123'],
|
||||
},
|
||||
},
|
||||
{
|
||||
created_at: '2021-04-28 12:31:12.794809 +0000 UTC',
|
||||
id: '48fce414-0cc0-4a16-8645-e3f0edec3212',
|
||||
request: {
|
||||
region: 'us-west-1',
|
||||
share_with_accounts: ['123123123123'],
|
||||
},
|
||||
},
|
||||
{
|
||||
created_at: '2021-04-27 12:31:12.794809 +0000 UTC',
|
||||
id: '0169538e-515c-477e-b934-f12783939313',
|
||||
request: {
|
||||
region: 'us-west-2',
|
||||
share_with_accounts: ['123123123123'],
|
||||
},
|
||||
},
|
||||
{
|
||||
created_at: '2021-04-27 12:31:12.794809 +0000 UTC',
|
||||
id: '4a851db1-919f-43ca-a7ef-dd209877a77e',
|
||||
request: {
|
||||
region: 'eu-central-1',
|
||||
share_with_accounts: ['000000000000'],
|
||||
},
|
||||
},
|
||||
],
|
||||
export const mockClones = (composeId) => {
|
||||
if (composeId === '1579d95b-8f1d-4982-8c53-8c2afa4ab04c') {
|
||||
return {
|
||||
data: [
|
||||
{
|
||||
created_at: '2021-04-27 12:31:12.794809 +0000 UTC',
|
||||
id: 'f9133ec4-7a9e-4fd9-9a9f-9636b82b0a5d',
|
||||
request: {
|
||||
region: 'us-west-1',
|
||||
share_with_accounts: ['123123123123'],
|
||||
},
|
||||
},
|
||||
{
|
||||
created_at: '2021-04-28 12:31:12.794809 +0000 UTC',
|
||||
id: '48fce414-0cc0-4a16-8645-e3f0edec3212',
|
||||
request: {
|
||||
region: 'us-west-1',
|
||||
share_with_accounts: ['123123123123'],
|
||||
},
|
||||
},
|
||||
{
|
||||
created_at: '2021-04-27 12:31:12.794809 +0000 UTC',
|
||||
id: '0169538e-515c-477e-b934-f12783939313',
|
||||
request: {
|
||||
region: 'us-west-2',
|
||||
share_with_accounts: ['123123123123'],
|
||||
},
|
||||
},
|
||||
{
|
||||
created_at: '2021-04-27 12:31:12.794809 +0000 UTC',
|
||||
id: '4a851db1-919f-43ca-a7ef-dd209877a77e',
|
||||
request: {
|
||||
region: 'eu-central-1',
|
||||
share_with_accounts: ['000000000000'],
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
export const mockCloneStatus = {
|
||||
|
|
|
|||
|
|
@ -11,6 +11,12 @@ import {
|
|||
mockActivationKeysResults,
|
||||
} from '../fixtures/activationKeys';
|
||||
import { mockArchitecturesByDistro } from '../fixtures/architectures';
|
||||
import {
|
||||
mockClones,
|
||||
mockCloneStatus,
|
||||
mockComposes,
|
||||
mockStatus,
|
||||
} from '../fixtures/composes';
|
||||
import {
|
||||
mockPackagesResults,
|
||||
mockSourcesPackagesResults,
|
||||
|
|
@ -77,4 +83,22 @@ export const handlers = [
|
|||
const args = { available_for_arch, available_for_version, limit };
|
||||
return res(ctx.status(200), ctx.json(mockRepositoryResults(args)));
|
||||
}),
|
||||
rest.get(`${IMAGE_BUILDER_API}/composes`, (req, res, ctx) => {
|
||||
return res(ctx.status(200), ctx.json(mockComposes));
|
||||
}),
|
||||
rest.get(`${IMAGE_BUILDER_API}/composes/:composeId`, (req, res, ctx) => {
|
||||
const { composeId } = req.params;
|
||||
return res(ctx.status(200), ctx.json(mockStatus[composeId]));
|
||||
}),
|
||||
rest.get(
|
||||
`${IMAGE_BUILDER_API}/composes/:composeId/clones`,
|
||||
(req, res, ctx) => {
|
||||
const { composeId } = req.params;
|
||||
return res(ctx.status(200), ctx.json(mockClones(composeId)));
|
||||
}
|
||||
),
|
||||
rest.get(`${IMAGE_BUILDER_API}/clones/:cloneId`, (req, res, ctx) => {
|
||||
const { cloneId } = req.params;
|
||||
return res(ctx.status(200), ctx.json(mockCloneStatus[cloneId]));
|
||||
}),
|
||||
];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue