test: Move mock json blobs to fixtures

This moves all mock json blobs from the Mock Service Worker handlers and component tests into one central location under `/fixtures`.
This commit is contained in:
regexowl 2023-05-26 11:39:37 +02:00 committed by Lucas Garfield
parent 313c0f60b6
commit 8f021105b4
11 changed files with 983 additions and 970 deletions

View file

@ -16,19 +16,15 @@ import {
RHEL_9,
PROVISIONING_SOURCES_ENDPOINT,
} from '../../../constants.js';
import { mockComposesEmpty } from '../../fixtures/composes.js';
import { customizations, ids } from '../../fixtures/customizations.js';
import { mockPkgResultAlphaContentSources } from '../../fixtures/packages.js';
import { server } from '../../mocks/server.js';
import { renderWithReduxRouter } from '../../testUtils';
let router = undefined;
let store = undefined;
const mockComposes = {
meta: {
count: 0,
},
data: [],
};
jest.mock('@redhat-cloud-services/frontend-components/useChrome', () => ({
useChrome: () => ({
auth: {
@ -54,7 +50,7 @@ jest.mock('@redhat-cloud-services/frontend-components/useChrome', () => ({
// being unable to resolve that endpoint.
jest
.spyOn(api, 'getComposes')
.mockImplementation(() => Promise.resolve(mockComposes));
.mockImplementation(() => Promise.resolve(mockComposesEmpty));
function getBackButton() {
const back = screen.getByRole('button', { name: /Back/ });
@ -66,24 +62,6 @@ function getNextButton() {
return next;
}
const mockPkgResultAlphaContentSources = [
{
name: 'lib-test',
summary: 'lib-test package summary',
version: '1.0',
},
{
name: 'Z-test',
summary: 'Z-test package summary',
version: '1.0',
},
{
name: 'test',
summary: 'summary for test package',
version: '1.0',
},
];
const searchForAvailablePackages = async (searchbox, searchTerm) => {
const user = userEvent.setup();
await user.type(searchbox, searchTerm);
@ -809,69 +787,6 @@ describe('Click through all steps', () => {
expect(within(revtbody).getAllByRole('row')).toHaveLength(3);
// mock the backend API
const ids = [];
const customizations = {
custom_repositories: [
{
baseurl: ['http://yum.theforeman.org/releases/3.4/el8/x86_64/'],
check_gpg: true,
check_repo_gpg: false,
gpgkey: [
'-----BEGIN PGP PUBLIC KEY BLOCK-----\n\nmQINBGN9300BEAC1FLODu0cL6saMMHa7yJY1JZ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3rOSM\nV6puUzWRR7qcYs5C2In87AcYPn92P5ur1y/C32r8Ftg3fRWnEzI9QfRG52ojNOLK\nyGQ8ZC9PGe0q7VFcF7ridT/uzRU+NVKldbJg+rvBnszb1MjNuR7rUQHyvGmbsUVQ\nRCsgdovkee3lP4gfZHzk2SSLVSo0+NJRNaM90EmPk14Pgi/yfRSDGBVvLBbEanYI\nv1ZtdIPRyKi+/IaMOu/l7nayM/8RzghdU+0f1FAif5qf9nXuI13P8fqcqfu67gNd\nkh0UUF1XyR5UHHEZQQDqCuKEkZJ/+27jYlsG1ZiLb1odlIWoR44RP6k5OJl0raZb\nyLXbAfpITsXiJJBpCam9P9+XR5VSfgkqp5hIa7J8piN3DoMpoExg4PPQr6PbLAJy\nOUCOnuB7yYVbj0wYuMXTuyrcBHh/UymQnS8AMpQoEkCLWS/A/Hze/pD23LgiBoLY\nXIn5A2EOAf7t2IMSlA==\n=OanT\n-----END PGP PUBLIC KEY BLOCK-----',
],
id: 'dbad4dfc-1547-45f8-b5af-1d7fec0476c6',
name: '13lk3',
},
{
baseurl: [
'http://mirror.stream.centos.org/SIGs/8/kmods/x86_64/packages-main/',
],
check_gpg: false,
id: '9cf1d45d-aa06-46fe-87ea-121845cc6bbb',
name: '2lmdtj',
},
],
payload_repositories: [
{
baseurl: 'http://yum.theforeman.org/releases/3.4/el8/x86_64/',
check_gpg: true,
check_repo_gpg: false,
gpgkey:
'-----BEGIN PGP PUBLIC KEY BLOCK-----\n\nmQINBGN9300BEAC1FLODu0cL6saMMHa7yJY1JZUc+jQUI/HdECQrrsTaPXlcc7nM\nykYMMv6amPqbnhH/R5BW2Ano+OMse+PXtUr0NXU4OcvxbnnXkrVBVUf8mXI9DzLZ\njw8KoD+4/s0BuzO78zAJF5uhuyHMAK0ll9v0r92kK45Fas9iZTfRFcqFAzvgjScf\n5jeBnbRs5U3UTz9mtDy802mk357o1A8BD0qlu3kANDpjLbORGWdAj21A6sMJDYXy\nHS9FBNV54daNcr+weky2L9gaF2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Aif5qf9nXuI13P8fqcqfu67gNd\nkh0UUF1XyR5UHHEZQQDqCuKEkZJ/+27jYlsG1ZiLb1odlIWoR44RP6k5OJl0raZb\nyLXbAfpITsXiJJBpCam9P9+XR5VSfgkqp5hIa7J8piN3DoMpoExg4PPQr6PbLAJy\nOUCOnuB7yYVbj0wYuMXTuyrcBHh/UymQnS8AMpQoEkCLWS/A/Hze/pD23LgiBoLY\nXIn5A2EOAf7t2IMSlA==\n=OanT\n-----END PGP PUBLIC KEY BLOCK-----',
rhsm: false,
},
{
baseurl:
'http://mirror.stream.centos.org/SIGs/8/kmods/x86_64/packages-main/',
rhsm: false,
check_gpg: false,
},
],
filesystem: [
{
mountpoint: '/',
min_size: 10737418240,
},
{
mountpoint: '/home',
min_size: 1073741824,
},
{
mountpoint: '/var/tmp',
min_size: 104857600,
},
],
packages: ['test'],
subscription: {
'activation-key': 'name0',
insights: true,
rhc: true,
organization: 5,
'server-url': 'subscription.rhsm.redhat.com',
'base-url': 'https://cdn.redhat.com/',
},
};
const composeImage = jest
.spyOn(api, 'composeImage')
.mockImplementation((body) => {

View file

@ -11,25 +11,24 @@ import userEvent from '@testing-library/user-event';
import api from '../../../api.js';
import { RHEL_8 } from '../../../constants.js';
import { mockComposesEmpty } from '../../fixtures/composes.js';
import {
mockPkgResultAlpha,
mockPkgResultAll,
mockPkgResultPartial,
} from '../../fixtures/packages.js';
import { renderWithReduxRouter } from '../../testUtils';
let store = undefined;
let router = undefined;
const mockComposes = {
meta: {
count: 0,
},
data: [],
};
// Mocking getComposes is necessary because in many tests we call navigate()
// to navigate to the images table (via useNavigate hook), which will in turn
// result in a call to getComposes. If it is not mocked, tests fail due to MSW
// being unable to resolve that endpoint.
jest
.spyOn(api, 'getComposes')
.mockImplementation(() => Promise.resolve(mockComposes));
.mockImplementation(() => Promise.resolve(mockComposesEmpty));
jest.mock('@redhat-cloud-services/frontend-components/useChrome', () => ({
useChrome: () => ({
@ -70,52 +69,6 @@ function verifyCancelButton(cancel, router) {
expect(router.state.location.pathname).toBe('/insights/image-builder');
}
const mockPkgResultAlpha = {
meta: { count: 3 },
links: { first: '', last: '' },
data: [
{
name: 'lib-test',
summary: 'lib-test package summary',
version: '1.0',
},
{
name: 'Z-test',
summary: 'Z-test package summary',
version: '1.0',
},
{
name: 'test',
summary: 'summary for test package',
version: '1.0',
},
],
};
const mockPkgResultPartial = {
meta: { count: 132 },
links: { first: '', last: '' },
data: new Array(100).fill().map((_, i) => {
return {
name: 'testPkg-' + i,
summary: 'test package summary',
version: '1.0',
};
}),
};
const mockPkgResultAll = {
meta: { count: 132 },
links: { first: '', last: '' },
data: new Array(132).fill().map((_, i) => {
return {
name: 'testPkg-' + i,
summary: 'test package summary',
version: '1.0',
};
}),
};
const searchForAvailablePackages = async (searchbox, searchTerm) => {
const user = userEvent.setup();
await user.type(searchbox, searchTerm);

View file

@ -9,421 +9,15 @@ import { ImageBuildStatus } from '../../../Components/ImagesTable/ImageBuildStat
import ImageLink from '../../../Components/ImagesTable/ImageLink';
import Target from '../../../Components/ImagesTable/Target';
import '@testing-library/jest-dom';
import { RHEL_8 } from '../../../constants.js';
import {
mockComposes,
mockStatus,
mockClones,
mockCloneStatus,
mockNoClones,
} from '../../fixtures/composes.js';
import { renderWithProvider, renderWithReduxRouter } from '../../testUtils';
const currentDate = new Date();
const currentDateInString = currentDate.toString();
const mockComposes = {
meta: {
count: 12,
},
data: [
{
id: '1579d95b-8f1d-4982-8c53-8c2afa4ab04c',
image_name: 'testImageName',
created_at: '2021-04-27 12:31:12.794809 +0000 UTC',
request: {
distribution: RHEL_8,
image_requests: [
{
architecture: 'x86_64',
image_type: 'aws',
upload_request: {
type: 'aws',
options: {
share_with_accounts: ['123123123123'],
},
},
},
],
},
},
// kept "running" for backward compatibility
{
id: 'c1cfa347-4c37-49b5-8e73-6aa1d1746cfa',
created_at: '2021-04-27 12:31:12.794809 +0000 UTC',
request: {
distribution: RHEL_8,
image_requests: [
{
architecture: 'x86_64',
image_type: 'gcp',
upload_request: {
type: 'gcp',
options: {
share_with_accounts: ['serviceAccount:test@email.com'],
},
},
},
],
},
},
{
id: 'edbae1c2-62bc-42c1-ae0c-3110ab718f58',
created_at: '2021-04-27 12:31:12.794809 +0000 UTC',
request: {
distribution: RHEL_8,
image_requests: [
{
architecture: 'x86_64',
image_type: 'aws',
upload_request: {
type: 'aws',
options: {},
},
},
],
},
},
{
id: '42ad0826-30b5-4f64-a24e-957df26fd564',
created_at: '2021-04-27 12:31:12.794809 +0000 UTC',
request: {
distribution: RHEL_8,
image_requests: [
{
architecture: 'x86_64',
image_type: 'aws',
upload_request: {
type: 'aws',
options: {},
},
},
],
},
},
{
id: '955944a2-e149-4058-8ac1-35b514cb5a16',
created_at: '2021-04-27 12:31:12.794809 +0000 UTC',
request: {
distribution: RHEL_8,
image_requests: [
{
architecture: 'x86_64',
image_type: 'aws',
upload_request: {
type: 'aws',
options: {},
},
},
],
},
},
{
id: 'f7a60094-b376-4b58-a102-5c8c82dfd18b',
created_at: '2021-04-27 12:31:12.794809 +0000 UTC',
request: {
distribution: RHEL_8,
image_requests: [
{
architecture: 'x86_64',
image_type: 'aws',
upload_request: {
type: 'aws',
options: {},
},
},
],
},
},
{
id: '61b0effa-c901-4ee5-86b9-2010b47f1b22',
created_at: '2021-04-27 12:31:12.794809 +0000 UTC',
request: {
distribution: RHEL_8,
image_requests: [
{
architecture: 'x86_64',
image_type: 'aws',
upload_request: {
type: 'aws',
options: {},
},
},
],
},
},
{
id: 'ca03f120-9840-4959-871e-94a5cb49d1f2',
created_at: '2021-04-27 12:31:12.794809 +0000 UTC',
request: {
distribution: RHEL_8,
image_requests: [
{
architecture: 'x86_64',
image_type: 'gcp',
upload_request: {
type: 'gcp',
options: {
share_with_accounts: ['serviceAccount:test@email.com'],
},
},
},
],
},
},
{
id: '551de6f6-1533-4b46-a69f-7924051f9bc6',
created_at: '2021-04-27 12:31:12.794809 +0000 UTC',
request: {
distribution: RHEL_8,
image_requests: [
{
architecture: 'x86_64',
image_type: 'azure',
upload_request: {
type: 'azure',
options: {},
},
},
],
},
},
{
created_at: '2021-04-27 12:31:12.794809 +0000 UTC',
id: 'b7193673-8dcc-4a5f-ac30-e9f4940d8346',
request: {
distribution: RHEL_8,
image_requests: [
{
architecture: 'x86_64',
image_type: 'vsphere',
upload_request: {
options: {},
type: 'aws.s3',
},
},
],
},
},
{
created_at: '2021-04-27 12:31:12.794809 +0000 UTC',
id: '4873fd0f-1851-4b9f-b4fe-4639fce90794',
request: {
distribution: RHEL_8,
image_requests: [
{
architecture: 'x86_64',
image_type: 'image-installer',
upload_request: {
options: {},
type: 'aws.s3',
},
},
],
},
},
{
created_at: currentDateInString,
id: '7b7d0d51-7106-42ab-98f2-f89872a9d599',
request: {
distribution: RHEL_8,
image_requests: [
{
architecture: 'x86_64',
image_type: 'guest-image',
upload_request: {
options: {},
type: 'aws.s3',
},
},
],
},
},
],
};
const mockStatus = {
'1579d95b-8f1d-4982-8c53-8c2afa4ab04c': {
image_status: {
status: 'success',
upload_status: {
options: {
ami: 'ami-0217b81d9be50e44b',
region: 'us-east-1',
},
status: 'success',
type: 'aws',
},
},
},
// kept "running" for backward compatibility
'c1cfa347-4c37-49b5-8e73-6aa1d1746cfa': {
image_status: {
status: 'failure',
error: {
reason: 'A dependency error occured',
details: {
reason: 'Error in depsolve job',
},
},
},
},
'edbae1c2-62bc-42c1-ae0c-3110ab718f58': {
image_status: {
status: 'pending',
},
},
'42ad0826-30b5-4f64-a24e-957df26fd564': {
image_status: {
status: 'building',
},
},
'955944a2-e149-4058-8ac1-35b514cb5a16': {
image_status: {
status: 'uploading',
},
},
'f7a60094-b376-4b58-a102-5c8c82dfd18b': {
image_status: {
status: 'registering',
},
},
'61b0effa-c901-4ee5-86b9-2010b47f1b22': {
image_status: {
status: 'failure',
error: {
reason: 'A dependency error occured',
details: {
reason: 'Error in depsolve job',
},
},
},
},
'ca03f120-9840-4959-871e-94a5cb49d1f2': {
image_status: {
status: 'success',
upload_status: {
options: {
image_name: 'composer-api-d446d8cb-7c16-4756-bf7d-706293785b05',
project_id: 'red-hat-image-builder',
},
status: 'success',
type: 'gcp',
},
},
},
'551de6f6-1533-4b46-a69f-7924051f9bc6': {
image_status: {
status: 'building',
},
},
'b7193673-8dcc-4a5f-ac30-e9f4940d8346': {
image_status: {
status: 'success',
upload_status: {
options: {
url: 'https://s3.amazonaws.com/b7193673-8dcc-4a5f-ac30-e9f4940d8346-disk.vmdk',
},
status: 'success',
type: 'aws.s3',
},
},
},
'4873fd0f-1851-4b9f-b4fe-4639fce90794': {
image_status: {
status: 'success',
upload_status: {
options: {
url: 'https://s3.amazonaws.com/4873fd0f-1851-4b9f-b4fe-4639fce90794-installer.iso',
},
status: 'success',
type: 'aws.s3',
},
},
},
'7b7d0d51-7106-42ab-98f2-f89872a9d599': {
image_status: {
status: 'success',
upload_status: {
options: {
url: 'https://s3.amazonaws.com/7b7d0d51-7106-42ab-98f2-f89872a9d599-disk.qcow2',
},
status: 'success',
type: 'aws.s3',
},
},
},
};
const mockNoClones = {
data: null,
};
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'],
},
},
],
};
const mockCloneStatus = {
'f9133ec4-7a9e-4fd9-9a9f-9636b82b0a5d': {
options: {
ami: 'ami-0e778053cd490ad21',
region: 'us-west-1',
},
status: 'success',
type: 'aws',
},
'48fce414-0cc0-4a16-8645-e3f0edec3212': {
options: {
ami: 'ami-9f0asd1tlk2142124',
region: 'us-west-1',
},
status: 'success',
type: 'aws',
},
'0169538e-515c-477e-b934-f12783939313': {
options: {
ami: 'ami-9fdskj12fdsak1211',
region: 'us-west-2',
},
status: 'failure',
type: 'aws',
},
'4a851db1-919f-43ca-a7ef-dd209877a77e': {
options: {
ami: 'ami-9fdskj12fdsak1211',
region: 'eu-central-1',
},
status: 'success',
type: 'aws',
},
};
jest.mock('@redhat-cloud-services/frontend-components/useChrome', () => ({
useChrome: () => ({
isBeta: () => false,

View file

@ -3,7 +3,7 @@ import { act, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import api from '../../../api.js';
import { RHEL_8 } from '../../../constants.js';
import { mockState } from '../../fixtures/composes.js';
import { renderWithReduxRouter } from '../../testUtils';
jest.mock('@redhat-cloud-services/frontend-components/useChrome', () => ({
@ -14,150 +14,6 @@ jest.mock('@redhat-cloud-services/frontend-components/useChrome', () => ({
}),
}));
const mockComposes = {
count: 1,
allIds: ['1579d95b-8f1d-4982-8c53-8c2afa4ab04c'],
byId: {
'1579d95b-8f1d-4982-8c53-8c2afa4ab04c': {
id: '1579d95b-8f1d-4982-8c53-8c2afa4abc',
image_name: 'testImageName',
created_at: '2021-04-27 12:31:12.794809 +0000 UTC',
request: {
distribution: RHEL_8,
image_requests: [
{
architecture: 'x86_64',
image_type: 'aws',
upload_request: {
type: 'aws',
options: {
share_with_accounts: ['123123123123'],
},
},
},
],
},
clones: [
'f9133ec4-7a9e-4fd9-9a9f-9636b82b0a5d',
'48fce414-0cc0-4a16-8645-e3f0edec3212',
'0169538e-515c-477e-b934-f12783939313',
'4a851db1-919f-43ca-a7ef-dd209877a77e',
],
image_status: {
status: 'success',
upload_status: {
options: {
ami: 'ami-0217b81d9be50e44b',
region: 'us-east-1',
},
status: 'success',
type: 'aws',
},
},
},
},
error: null,
};
const mockClones = {
allIds: [
'f9133ec4-7a9e-4fd9-9a9f-9636b82b0a5d',
'48fce414-0cc0-4a16-8645-e3f0edec3212',
'0169538e-515c-477e-b934-f12783939313',
'4a851db1-919f-43ca-a7ef-dd209877a77e',
],
byId: {
'f9133ec4-7a9e-4fd9-9a9f-9636b82b0a5d': {
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'],
},
parent: '1579d95b-8f1d-4982-8c53-8c2afa4ab04c',
image_status: {
status: 'success',
upload_status: {
options: {
ami: 'ami-0e778053cd490ad21',
region: 'us-west-1',
},
status: 'success',
type: 'aws',
},
},
},
// Duplicate us-west-1 clone with different ami created one day later
'48fce414-0cc0-4a16-8645-e3f0edec3212': {
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'],
},
parent: '1579d95b-8f1d-4982-8c53-8c2afa4ab04c',
image_status: {
status: 'success',
upload_status: {
options: {
ami: 'ami-9f0asd1tlk2142124',
region: 'us-west-1',
},
status: 'success',
type: 'aws',
},
},
},
'0169538e-515c-477e-b934-f12783939313': {
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'],
},
parent: '1579d95b-8f1d-4982-8c53-8c2afa4ab04c',
image_status: {
status: 'failure',
upload_status: {
options: {
ami: 'ami-9fdskj12fdsak1211',
region: 'us-west-2',
},
status: 'failure',
type: 'aws',
},
},
},
'4a851db1-919f-43ca-a7ef-dd209877a77e': {
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'],
},
parent: '1579d95b-8f1d-4982-8c53-8c2afa4ab04c',
image_status: {
status: 'success',
upload_status: {
options: {
ami: 'ami-9fdskj12fdsak1211',
region: 'eu-central-1',
},
status: 'success',
type: 'aws',
},
},
},
},
error: null,
};
const mockState = {
clones: { ...mockClones },
composes: { ...mockComposes },
notifications: [],
};
const composeId = '1579d95b-8f1d-4982-8c53-8c2afa4ab04c';
describe('Create Share To Regions Modal', () => {

62
src/test/fixtures/activationKeys.js vendored Normal file
View file

@ -0,0 +1,62 @@
export const mockActivationKeysResults = () => {
return {
body: [
{
id: 0,
name: 'name0',
},
{
id: 1,
name: 'name1',
},
],
};
};
export const mockActivationKeyInformation = (key) => {
if (key === 'name0') {
return {
body: {
additionalRepositories: [
{
repositoryLabel: 'repository0',
},
{
repositoryLabel: 'repository1',
},
{
repositoryLabel: 'repository2',
},
],
id: '0',
name: 'name0',
releaseVersion: '',
role: '',
serviceLevel: 'Self-Support',
usage: 'Production',
},
};
} else if (key === 'name1') {
return {
body: {
additionalRepositories: [
{
repositoryLabel: 'repository3',
},
{
repositoryLabel: 'repository4',
},
{
repositoryLabel: 'repository5',
},
],
id: '1',
name: 'name1',
releaseVersion: '',
role: '',
serviceLevel: 'Premium',
usage: 'Production',
},
};
}
};

72
src/test/fixtures/architectures.js vendored Normal file
View file

@ -0,0 +1,72 @@
export const mockArchitecturesByDistro = (distro) => {
if (distro === 'rhel-92') {
return [
{
arch: 'x86_64',
repositories: [
{
baseurl:
'https://cdn.redhat.com/content/dist/rhel9/9.2/x86_64/baseos/os',
rhsm: true,
},
],
},
{
arch: 'aarch64',
repositories: [
{
baseurl:
'https://cdn.redhat.com/content/dist/rhel9/9.2/aarch64/baseos/os',
rhsm: true,
},
],
},
];
} else if (distro === 'rhel-87') {
return [
{
arch: 'x86_64',
repositories: [
{
baseurl:
'https://cdn.redhat.com/content/dist/rhel8/8.7/x86_64/baseos/os',
rhsm: true,
},
],
},
{
arch: 'aarch64',
repositories: [
{
baseurl:
'https://cdn.redhat.com/content/dist/rhel8/8.7/aarch64/baseos/os',
rhsm: true,
},
],
},
];
} else if (distro === 'centos-8') {
return [
{
arch: 'x86_64',
repositories: [
{
baseurl:
'http://mirror.centos.org/centos/8-stream/BaseOS/x86_64/os/',
rhsm: false,
},
],
},
{
arch: 'aarch64',
repositories: [
{
baseurl:
'http://mirror.centos.org/centos/8-stream/BaseOS/aarch64/os/',
rhsm: false,
},
],
},
];
}
};

567
src/test/fixtures/composes.js vendored Normal file
View file

@ -0,0 +1,567 @@
import { RHEL_8 } from '../../constants';
// CreateImageWizard mocks
export const mockComposesEmpty = {
meta: {
count: 0,
},
data: [],
};
// ImagesTable mocks
const currentDate = new Date();
const currentDateInString = currentDate.toString();
export const mockComposes = {
meta: {
count: 12,
},
data: [
{
id: '1579d95b-8f1d-4982-8c53-8c2afa4ab04c',
image_name: 'testImageName',
created_at: '2021-04-27 12:31:12.794809 +0000 UTC',
request: {
distribution: RHEL_8,
image_requests: [
{
architecture: 'x86_64',
image_type: 'aws',
upload_request: {
type: 'aws',
options: {
share_with_accounts: ['123123123123'],
},
},
},
],
},
},
// kept "running" for backward compatibility
{
id: 'c1cfa347-4c37-49b5-8e73-6aa1d1746cfa',
created_at: '2021-04-27 12:31:12.794809 +0000 UTC',
request: {
distribution: RHEL_8,
image_requests: [
{
architecture: 'x86_64',
image_type: 'gcp',
upload_request: {
type: 'gcp',
options: {
share_with_accounts: ['serviceAccount:test@email.com'],
},
},
},
],
},
},
{
id: 'edbae1c2-62bc-42c1-ae0c-3110ab718f58',
created_at: '2021-04-27 12:31:12.794809 +0000 UTC',
request: {
distribution: RHEL_8,
image_requests: [
{
architecture: 'x86_64',
image_type: 'aws',
upload_request: {
type: 'aws',
options: {},
},
},
],
},
},
{
id: '42ad0826-30b5-4f64-a24e-957df26fd564',
created_at: '2021-04-27 12:31:12.794809 +0000 UTC',
request: {
distribution: RHEL_8,
image_requests: [
{
architecture: 'x86_64',
image_type: 'aws',
upload_request: {
type: 'aws',
options: {},
},
},
],
},
},
{
id: '955944a2-e149-4058-8ac1-35b514cb5a16',
created_at: '2021-04-27 12:31:12.794809 +0000 UTC',
request: {
distribution: RHEL_8,
image_requests: [
{
architecture: 'x86_64',
image_type: 'aws',
upload_request: {
type: 'aws',
options: {},
},
},
],
},
},
{
id: 'f7a60094-b376-4b58-a102-5c8c82dfd18b',
created_at: '2021-04-27 12:31:12.794809 +0000 UTC',
request: {
distribution: RHEL_8,
image_requests: [
{
architecture: 'x86_64',
image_type: 'aws',
upload_request: {
type: 'aws',
options: {},
},
},
],
},
},
{
id: '61b0effa-c901-4ee5-86b9-2010b47f1b22',
created_at: '2021-04-27 12:31:12.794809 +0000 UTC',
request: {
distribution: RHEL_8,
image_requests: [
{
architecture: 'x86_64',
image_type: 'aws',
upload_request: {
type: 'aws',
options: {},
},
},
],
},
},
{
id: 'ca03f120-9840-4959-871e-94a5cb49d1f2',
created_at: '2021-04-27 12:31:12.794809 +0000 UTC',
request: {
distribution: RHEL_8,
image_requests: [
{
architecture: 'x86_64',
image_type: 'gcp',
upload_request: {
type: 'gcp',
options: {
share_with_accounts: ['serviceAccount:test@email.com'],
},
},
},
],
},
},
{
id: '551de6f6-1533-4b46-a69f-7924051f9bc6',
created_at: '2021-04-27 12:31:12.794809 +0000 UTC',
request: {
distribution: RHEL_8,
image_requests: [
{
architecture: 'x86_64',
image_type: 'azure',
upload_request: {
type: 'azure',
options: {},
},
},
],
},
},
{
created_at: '2021-04-27 12:31:12.794809 +0000 UTC',
id: 'b7193673-8dcc-4a5f-ac30-e9f4940d8346',
request: {
distribution: RHEL_8,
image_requests: [
{
architecture: 'x86_64',
image_type: 'vsphere',
upload_request: {
options: {},
type: 'aws.s3',
},
},
],
},
},
{
created_at: '2021-04-27 12:31:12.794809 +0000 UTC',
id: '4873fd0f-1851-4b9f-b4fe-4639fce90794',
request: {
distribution: RHEL_8,
image_requests: [
{
architecture: 'x86_64',
image_type: 'image-installer',
upload_request: {
options: {},
type: 'aws.s3',
},
},
],
},
},
{
created_at: currentDateInString,
id: '7b7d0d51-7106-42ab-98f2-f89872a9d599',
request: {
distribution: RHEL_8,
image_requests: [
{
architecture: 'x86_64',
image_type: 'guest-image',
upload_request: {
options: {},
type: 'aws.s3',
},
},
],
},
},
],
};
export const mockStatus = {
'1579d95b-8f1d-4982-8c53-8c2afa4ab04c': {
image_status: {
status: 'success',
upload_status: {
options: {
ami: 'ami-0217b81d9be50e44b',
region: 'us-east-1',
},
status: 'success',
type: 'aws',
},
},
},
// kept "running" for backward compatibility
'c1cfa347-4c37-49b5-8e73-6aa1d1746cfa': {
image_status: {
status: 'failure',
error: {
reason: 'A dependency error occured',
details: {
reason: 'Error in depsolve job',
},
},
},
},
'edbae1c2-62bc-42c1-ae0c-3110ab718f58': {
image_status: {
status: 'pending',
},
},
'42ad0826-30b5-4f64-a24e-957df26fd564': {
image_status: {
status: 'building',
},
},
'955944a2-e149-4058-8ac1-35b514cb5a16': {
image_status: {
status: 'uploading',
},
},
'f7a60094-b376-4b58-a102-5c8c82dfd18b': {
image_status: {
status: 'registering',
},
},
'61b0effa-c901-4ee5-86b9-2010b47f1b22': {
image_status: {
status: 'failure',
error: {
reason: 'A dependency error occured',
details: {
reason: 'Error in depsolve job',
},
},
},
},
'ca03f120-9840-4959-871e-94a5cb49d1f2': {
image_status: {
status: 'success',
upload_status: {
options: {
image_name: 'composer-api-d446d8cb-7c16-4756-bf7d-706293785b05',
project_id: 'red-hat-image-builder',
},
status: 'success',
type: 'gcp',
},
},
},
'551de6f6-1533-4b46-a69f-7924051f9bc6': {
image_status: {
status: 'building',
},
},
'b7193673-8dcc-4a5f-ac30-e9f4940d8346': {
image_status: {
status: 'success',
upload_status: {
options: {
url: 'https://s3.amazonaws.com/b7193673-8dcc-4a5f-ac30-e9f4940d8346-disk.vmdk',
},
status: 'success',
type: 'aws.s3',
},
},
},
'4873fd0f-1851-4b9f-b4fe-4639fce90794': {
image_status: {
status: 'success',
upload_status: {
options: {
url: 'https://s3.amazonaws.com/4873fd0f-1851-4b9f-b4fe-4639fce90794-installer.iso',
},
status: 'success',
type: 'aws.s3',
},
},
},
'7b7d0d51-7106-42ab-98f2-f89872a9d599': {
image_status: {
status: 'success',
upload_status: {
options: {
url: 'https://s3.amazonaws.com/7b7d0d51-7106-42ab-98f2-f89872a9d599-disk.qcow2',
},
status: 'success',
type: 'aws.s3',
},
},
},
};
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 mockCloneStatus = {
'f9133ec4-7a9e-4fd9-9a9f-9636b82b0a5d': {
options: {
ami: 'ami-0e778053cd490ad21',
region: 'us-west-1',
},
status: 'success',
type: 'aws',
},
'48fce414-0cc0-4a16-8645-e3f0edec3212': {
options: {
ami: 'ami-9f0asd1tlk2142124',
region: 'us-west-1',
},
status: 'success',
type: 'aws',
},
'0169538e-515c-477e-b934-f12783939313': {
options: {
ami: 'ami-9fdskj12fdsak1211',
region: 'us-west-2',
},
status: 'failure',
type: 'aws',
},
'4a851db1-919f-43ca-a7ef-dd209877a77e': {
options: {
ami: 'ami-9fdskj12fdsak1211',
region: 'eu-central-1',
},
status: 'success',
type: 'aws',
},
};
// ShareImageModal mocks
export const mockComposesShareImageModal = {
count: 1,
allIds: ['1579d95b-8f1d-4982-8c53-8c2afa4ab04c'],
byId: {
'1579d95b-8f1d-4982-8c53-8c2afa4ab04c': {
id: '1579d95b-8f1d-4982-8c53-8c2afa4abc',
image_name: 'testImageName',
created_at: '2021-04-27 12:31:12.794809 +0000 UTC',
request: {
distribution: RHEL_8,
image_requests: [
{
architecture: 'x86_64',
image_type: 'aws',
upload_request: {
type: 'aws',
options: {
share_with_accounts: ['123123123123'],
},
},
},
],
},
clones: [
'f9133ec4-7a9e-4fd9-9a9f-9636b82b0a5d',
'48fce414-0cc0-4a16-8645-e3f0edec3212',
'0169538e-515c-477e-b934-f12783939313',
'4a851db1-919f-43ca-a7ef-dd209877a77e',
],
image_status: {
status: 'success',
upload_status: {
options: {
ami: 'ami-0217b81d9be50e44b',
region: 'us-east-1',
},
status: 'success',
type: 'aws',
},
},
},
},
error: null,
};
export const mockClonesShareImageModal = {
allIds: [
'f9133ec4-7a9e-4fd9-9a9f-9636b82b0a5d',
'48fce414-0cc0-4a16-8645-e3f0edec3212',
'0169538e-515c-477e-b934-f12783939313',
'4a851db1-919f-43ca-a7ef-dd209877a77e',
],
byId: {
'f9133ec4-7a9e-4fd9-9a9f-9636b82b0a5d': {
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'],
},
parent: '1579d95b-8f1d-4982-8c53-8c2afa4ab04c',
image_status: {
status: 'success',
upload_status: {
options: {
ami: 'ami-0e778053cd490ad21',
region: 'us-west-1',
},
status: 'success',
type: 'aws',
},
},
},
// Duplicate us-west-1 clone with different ami created one day later
'48fce414-0cc0-4a16-8645-e3f0edec3212': {
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'],
},
parent: '1579d95b-8f1d-4982-8c53-8c2afa4ab04c',
image_status: {
status: 'success',
upload_status: {
options: {
ami: 'ami-9f0asd1tlk2142124',
region: 'us-west-1',
},
status: 'success',
type: 'aws',
},
},
},
'0169538e-515c-477e-b934-f12783939313': {
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'],
},
parent: '1579d95b-8f1d-4982-8c53-8c2afa4ab04c',
image_status: {
status: 'failure',
upload_status: {
options: {
ami: 'ami-9fdskj12fdsak1211',
region: 'us-west-2',
},
status: 'failure',
type: 'aws',
},
},
},
'4a851db1-919f-43ca-a7ef-dd209877a77e': {
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'],
},
parent: '1579d95b-8f1d-4982-8c53-8c2afa4ab04c',
image_status: {
status: 'success',
upload_status: {
options: {
ami: 'ami-9fdskj12fdsak1211',
region: 'eu-central-1',
},
status: 'success',
type: 'aws',
},
},
},
},
error: null,
};
export const mockState = {
clones: { ...mockClonesShareImageModal },
composes: { ...mockComposesShareImageModal },
notifications: [],
};

63
src/test/fixtures/customizations.js vendored Normal file
View file

@ -0,0 +1,63 @@
export const ids = [];
export const customizations = {
custom_repositories: [
{
baseurl: ['http://yum.theforeman.org/releases/3.4/el8/x86_64/'],
check_gpg: true,
check_repo_gpg: false,
gpgkey: [
'-----BEGIN PGP PUBLIC KEY BLOCK-----\n\nmQINBGN9300BEAC1FLODu0cL6saMMHa7yJY1JZUc+jQUI/HdECQrrsTaPXlcc7nM\nykYMMv6amPqbnhH/R5BW2Ano+OMse+PXtUr0NXU4OcvxbnnXkrVBVUf8mXI9DzLZ\njw8KoD+4/s0BuzO78zAJF5uhuyHMAK0ll9v0r92kK45Fas9iZTfRFcqFAzvgjScf\n5jeBnbRs5U3UTz9mtDy802mk357o1A8BD0qlu3kANDpjLbORGWdAj21A6sMJDYXy\nHS9FBNV54daNcr+weky2L9gaF2yFjeu2rSEHCSfkbWfpSiVUx/bDTj7XS6XDOuJT\nJqvGS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CuKEkZJ/+27jYlsG1ZiLb1odlIWoR44RP6k5OJl0raZb\nyLXbAfpITsXiJJBpCam9P9+XR5VSfgkqp5hIa7J8piN3DoMpoExg4PPQr6PbLAJy\nOUCOnuB7yYVbj0wYuMXTuyrcBHh/UymQnS8AMpQoEkCLWS/A/Hze/pD23LgiBoLY\nXIn5A2EOAf7t2IMSlA==\n=OanT\n-----END PGP PUBLIC KEY BLOCK-----',
],
id: 'dbad4dfc-1547-45f8-b5af-1d7fec0476c6',
name: '13lk3',
},
{
baseurl: [
'http://mirror.stream.centos.org/SIGs/8/kmods/x86_64/packages-main/',
],
check_gpg: false,
id: '9cf1d45d-aa06-46fe-87ea-121845cc6bbb',
name: '2lmdtj',
},
],
payload_repositories: [
{
baseurl: 'http://yum.theforeman.org/releases/3.4/el8/x86_64/',
check_gpg: true,
check_repo_gpg: false,
gpgkey:
'-----BEGIN PGP PUBLIC KEY BLOCK-----\n\nmQINBGN9300BEAC1FLODu0cL6saMMHa7yJY1JZUc+jQUI/HdECQrrsTaPXlcc7nM\nykYMMv6amPqbnhH/R5BW2Ano+OMse+PXtUr0NXU4OcvxbnnXkrVBVUf8mXI9DzLZ\njw8KoD+4/s0BuzO78zAJF5uhuyHMAK0ll9v0r92kK45Fas9iZTfRFcqFAzvgjScf\n5jeBnbRs5U3UTz9mtDy802mk357o1A8BD0qlu3kANDpjLbORGWdAj21A6sMJDYXy\nHS9FBNV54daNcr+weky2L9gaF2yFjeu2rSEHCSfkbWfpSiVUx/bDTj7XS6XDOuJT\nJqvGS8jHqjHAIFBirhCA4cY/jLKxWyMr5N6IbXpPAYgt8/YYz2aOYVvdyB8tZ1u1\nkVsMYSGcvTBexZCn1cDkbO6I+waIlsc0uxGqUGBKF83AVYCQqOkBjF1uNnu9qefE\nkEc9obr4JZsAgnisboU25ss5ZJddKlmFMKSi66g4S5ChLEPFq7MB06PhLFioaD3L\nEXza7XitoW5VBwr0BSVKAHMC0T2xbm70zY06a6gQRlvr9a10lPmv4Tpt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baseurl:
'http://mirror.stream.centos.org/SIGs/8/kmods/x86_64/packages-main/',
rhsm: false,
check_gpg: false,
},
],
filesystem: [
{
mountpoint: '/',
min_size: 10737418240,
},
{
mountpoint: '/home',
min_size: 1073741824,
},
{
mountpoint: '/var/tmp',
min_size: 104857600,
},
],
packages: ['test'],
subscription: {
'activation-key': 'name0',
insights: true,
rhc: true,
organization: 5,
'server-url': 'subscription.rhsm.redhat.com',
'base-url': 'https://cdn.redhat.com/',
},
};

116
src/test/fixtures/packages.js vendored Normal file
View file

@ -0,0 +1,116 @@
export const mockPackagesResults = (search) => {
if (search === 'test') {
return {
data: [
{
name: 'testPkg',
summary: 'test package summary',
version: '1.0',
},
{
name: 'lib-test',
summary: 'lib-test package summary',
version: '1.0',
},
{
name: 'test',
summary: 'summary for test package',
version: '1.0',
},
],
meta: {
count: 3,
},
};
} else {
return { data: [], meta: 0 };
}
};
export const mockSourcesPackagesResults = (search) => {
if (search === 'test') {
return [
{
name: 'testPkg',
summary: 'test package summary',
version: '1.0',
},
{
name: 'lib-test',
summary: 'lib-test package summary',
version: '1.0',
},
{
name: 'test',
summary: 'summary for test package',
version: '1.0',
},
];
} else {
return [];
}
};
export const mockPkgResultAlpha = {
meta: { count: 3 },
links: { first: '', last: '' },
data: [
{
name: 'lib-test',
summary: 'lib-test package summary',
version: '1.0',
},
{
name: 'Z-test',
summary: 'Z-test package summary',
version: '1.0',
},
{
name: 'test',
summary: 'summary for test package',
version: '1.0',
},
],
};
export const mockPkgResultAlphaContentSources = [
{
name: 'lib-test',
summary: 'lib-test package summary',
version: '1.0',
},
{
name: 'Z-test',
summary: 'Z-test package summary',
version: '1.0',
},
{
name: 'test',
summary: 'summary for test package',
version: '1.0',
},
];
export const mockPkgResultPartial = {
meta: { count: 132 },
links: { first: '', last: '' },
data: new Array(100).fill().map((_, i) => {
return {
name: 'testPkg-' + i,
summary: 'test package summary',
version: '1.0',
};
}),
};
export const mockPkgResultAll = {
meta: { count: 132 },
links: { first: '', last: '' },
data: new Array(132).fill().map((_, i) => {
return {
name: 'testPkg-' + i,
summary: 'test package summary',
version: '1.0',
};
}),
};

55
src/test/fixtures/sources.js vendored Normal file
View file

@ -0,0 +1,55 @@
export const mockAccountIdentity = {
aws: {
account_id: '123456789012',
},
};
export const mockSourcesByProvider = (provider) => {
if (provider === 'aws') {
return [
{
id: '123',
name: 'my_source',
source_type_id: '1',
uid: 'de5e35d4-4c1f-49d7-9ef3-7d08e6b9c76a',
},
];
} else if (provider === 'azure') {
return [
{
id: '666',
name: 'azureSource1',
source_type_id: '3',
uid: '9f48059c-25db-47ac-81e8-dac7f8a76170',
},
{
id: '667',
name: 'azureSource2',
source_type_id: '3',
uid: '73d5694c-7a28-417e-9fca-55840084f508',
},
];
}
};
export const mockUploadInfo = (sourceId) => {
if (sourceId === '666') {
return {
provider: 'azure',
azure: {
tenant_id: '2fd7c95c-0d63-4e81-b914-3fbd5288daf7',
subscription_id: 'dfb83267-e016-4429-ae6e-b0768bf36d65',
resource_groups: ['myResourceGroup1', 'testResourceGroup'],
},
};
} else if (sourceId === '667') {
return {
provider: 'azure',
azure: {
tenant_id: '73d5694c-7a28-417e-9fca-55840084f508',
subscription_id: 'a66682d2-ce3e-46f7-a127-1d106c34e10c',
resource_groups: ['theirGroup2'],
},
};
}
};

View file

@ -2,10 +2,25 @@ import { rest } from 'msw';
import {
CONTENT_SOURCES,
IMAGE_BUILDER_API,
PROVISIONING_SOURCES_ENDPOINT,
RHSM_API,
} from '../../constants';
import {
mockActivationKeyInformation,
mockActivationKeysResults,
} from '../fixtures/activationKeys';
import { mockArchitecturesByDistro } from '../fixtures/architectures';
import {
mockPackagesResults,
mockSourcesPackagesResults,
} from '../fixtures/packages';
import { mockRepositoryResults } from '../fixtures/repositories';
import {
mockAccountIdentity,
mockSourcesByProvider,
mockUploadInfo,
} from '../fixtures/sources';
const baseURL = 'http://localhost';
@ -14,37 +29,7 @@ export const handlers = [
baseURL.concat(`${PROVISIONING_SOURCES_ENDPOINT}`),
(req, res, ctx) => {
const provider = req.url.searchParams.get('provider');
if (provider === 'aws') {
return res(
ctx.status(200),
ctx.json([
{
id: '123',
name: 'my_source',
source_type_id: '1',
uid: 'de5e35d4-4c1f-49d7-9ef3-7d08e6b9c76a',
},
])
);
} else if (provider === 'azure') {
return res(
ctx.status(200),
ctx.json([
{
id: '666',
name: 'azureSource1',
source_type_id: '3',
uid: '9f48059c-25db-47ac-81e8-dac7f8a76170',
},
{
id: '667',
name: 'azureSource2',
source_type_id: '3',
uid: '73d5694c-7a28-417e-9fca-55840084f508',
},
])
);
}
return res(ctx.status(200), ctx.json(mockSourcesByProvider(provider)));
}
),
rest.get(
@ -54,14 +39,7 @@ export const handlers = [
(req, res, ctx) => {
const { accountId } = req.params;
if (accountId === '123') {
return res(
ctx.status(200),
ctx.json({
aws: {
account_id: '123456789012',
},
})
);
return res(ctx.status(200), ctx.json(mockAccountIdentity));
} else {
return res(ctx.status(404));
}
@ -71,257 +49,39 @@ export const handlers = [
baseURL.concat(`${PROVISIONING_SOURCES_ENDPOINT}/:sourceId/upload_info`),
(req, res, ctx) => {
const { sourceId } = req.params;
if (sourceId === '666') {
return res(
ctx.status(200),
ctx.json({
provider: 'azure',
azure: {
tenant_id: '2fd7c95c-0d63-4e81-b914-3fbd5288daf7',
subscription_id: 'dfb83267-e016-4429-ae6e-b0768bf36d65',
resource_groups: ['myResourceGroup1', 'testResourceGroup'],
},
})
);
} else if (sourceId === '667') {
return res(
ctx.status(200),
ctx.json({
provider: 'azure',
azure: {
tenant_id: '73d5694c-7a28-417e-9fca-55840084f508',
subscription_id: 'a66682d2-ce3e-46f7-a127-1d106c34e10c',
resource_groups: ['theirGroup2'],
},
})
);
if (sourceId === '666' || sourceId === '667') {
return res(ctx.status(200), ctx.json(mockUploadInfo(sourceId)));
} else {
return res(ctx.status(404));
}
}
),
rest.post(
baseURL.concat('/api/content-sources/v1/rpms/names'),
baseURL.concat(`${CONTENT_SOURCES}/rpms/names`),
async (req, res, ctx) => {
const { search } = await req.json();
if (search === 'test') {
return res(
ctx.status(200),
ctx.json([
{
name: 'testPkg',
summary: 'test package summary',
version: '1.0',
},
{
name: 'lib-test',
summary: 'lib-test package summary',
version: '1.0',
},
{
name: 'test',
summary: 'summary for test package',
version: '1.0',
},
])
);
} else if (search === 'asdf') {
return res(ctx.status(200), ctx.json([]));
}
return res(ctx.status(200), ctx.json(mockSourcesPackagesResults(search)));
}
),
rest.get(baseURL.concat(`${IMAGE_BUILDER_API}/packages`), (req, res, ctx) => {
const search = req.url.searchParams.get('search');
return res(ctx.status(200), ctx.json(mockPackagesResults(search)));
}),
rest.get(
baseURL.concat('/api/image-builder/v1/packages'),
(req, res, ctx) => {
const search = req.url.searchParams.get('search');
if (search === 'test') {
return res(
ctx.status(200),
ctx.json({
data: [
{
name: 'testPkg',
summary: 'test package summary',
version: '1.0',
},
{
name: 'lib-test',
summary: 'lib-test package summary',
version: '1.0',
},
{
name: 'test',
summary: 'summary for test package',
version: '1.0',
},
],
meta: {
count: 3,
},
})
);
} else if (search === 'asdf') {
return res(ctx.status(200), ctx.json({ data: [], meta: 0 }));
}
}
),
rest.get(
baseURL.concat('/api/image-builder/v1/architectures/:distro'),
baseURL.concat(`${IMAGE_BUILDER_API}/architectures/:distro`),
(req, res, ctx) => {
const { distro } = req.params;
if (distro === 'rhel-92') {
return res(
ctx.status(200),
ctx.json([
{
arch: 'x86_64',
repositories: [
{
baseurl:
'https://cdn.redhat.com/content/dist/rhel9/9.2/x86_64/baseos/os',
rhsm: true,
},
],
},
{
arch: 'aarch64',
repositories: [
{
baseurl:
'https://cdn.redhat.com/content/dist/rhel9/9.2/aarch64/baseos/os',
rhsm: true,
},
],
},
])
);
} else if (distro === 'rhel-87') {
return res(
ctx.status(200),
ctx.json([
{
arch: 'x86_64',
repositories: [
{
baseurl:
'https://cdn.redhat.com/content/dist/rhel8/8.7/x86_64/baseos/os',
rhsm: true,
},
],
},
{
arch: 'aarch64',
repositories: [
{
baseurl:
'https://cdn.redhat.com/content/dist/rhel8/8.7/aarch64/baseos/os',
rhsm: true,
},
],
},
])
);
} else if (distro === 'centos-8') {
return res(
ctx.status(200),
ctx.json([
{
arch: 'x86_64',
repositories: [
{
baseurl:
'http://mirror.centos.org/centos/8-stream/BaseOS/x86_64/os/',
rhsm: false,
},
],
},
{
arch: 'aarch64',
repositories: [
{
baseurl:
'http://mirror.centos.org/centos/8-stream/BaseOS/aarch64/os/',
rhsm: false,
},
],
},
])
);
}
return res(ctx.status(200), ctx.json(mockArchitecturesByDistro(distro)));
}
),
rest.get(baseURL.concat(`${RHSM_API}/activation_keys`), (req, res, ctx) => {
return res(
ctx.status(200),
ctx.json({
body: [
{
id: 0,
name: 'name0',
},
{
id: 1,
name: 'name1',
},
],
})
);
return res(ctx.status(200), ctx.json(mockActivationKeysResults()));
}),
rest.get(
baseURL.concat(`${RHSM_API}/activation_keys/:key`),
(req, res, ctx) => {
const { key } = req.params;
if (key === 'name0') {
return res(
ctx.status(200),
ctx.json({
body: {
additionalRepositories: [
{
repositoryLabel: 'repository0',
},
{
repositoryLabel: 'repository1',
},
{
repositoryLabel: 'repository2',
},
],
id: '0',
name: 'name0',
releaseVersion: '',
role: '',
serviceLevel: 'Self-Support',
usage: 'Production',
},
})
);
} else if (key === 'name1') {
return res(
ctx.status(200),
ctx.json({
body: {
additionalRepositories: [
{
repositoryLabel: 'repository3',
},
{
repositoryLabel: 'repository4',
},
{
repositoryLabel: 'repository5',
},
],
id: '1',
name: 'name1',
releaseVersion: '',
role: '',
serviceLevel: 'Premium',
usage: 'Production',
},
})
);
}
return res(ctx.status(200), ctx.json(mockActivationKeyInformation(key)));
}
),
rest.get(