V2Wizard: add GCP target full test coverage
This commit is contained in:
parent
c56a011443
commit
bac8e1e57f
1 changed files with 156 additions and 0 deletions
|
|
@ -0,0 +1,156 @@
|
|||
import { screen } from '@testing-library/react';
|
||||
import { userEvent } from '@testing-library/user-event';
|
||||
|
||||
import { CREATE_BLUEPRINT } from '../../../../../constants';
|
||||
import {
|
||||
CreateBlueprintRequest,
|
||||
GcpUploadRequestOptions,
|
||||
ImageRequest,
|
||||
ImageTypes,
|
||||
} from '../../../../../store/imageBuilderApi';
|
||||
import { clickNext } from '../../../../testUtils';
|
||||
import {
|
||||
blueprintRequest,
|
||||
clickRegisterLater,
|
||||
enterBlueprintName,
|
||||
imageRequest,
|
||||
interceptBlueprintRequest,
|
||||
render,
|
||||
} from '../../wizardTestUtils';
|
||||
|
||||
jest.mock('@redhat-cloud-services/frontend-components/useChrome', () => ({
|
||||
useChrome: () => ({
|
||||
auth: {
|
||||
getUser: () => {
|
||||
return {
|
||||
identity: {
|
||||
internal: {
|
||||
org_id: 5,
|
||||
},
|
||||
},
|
||||
};
|
||||
},
|
||||
},
|
||||
isBeta: () => true,
|
||||
isProd: () => true,
|
||||
getEnvironment: () => 'prod',
|
||||
}),
|
||||
}));
|
||||
|
||||
const GCP_ACCOUNT = 'test@gmail.com';
|
||||
|
||||
const goToReview = async () => {
|
||||
await clickNext();
|
||||
await clickRegisterLater();
|
||||
await clickNext(); // OpenSCAP
|
||||
await clickNext(); // File system customization
|
||||
await clickNext(); // Custom repositories
|
||||
await clickNext(); // Additional packages
|
||||
await clickNext(); // Details
|
||||
await enterBlueprintName();
|
||||
await clickNext(); // Review
|
||||
};
|
||||
|
||||
const createGCPCloudImage = (
|
||||
image_type: ImageTypes,
|
||||
options: GcpUploadRequestOptions
|
||||
): ImageRequest => {
|
||||
return {
|
||||
...imageRequest,
|
||||
image_type,
|
||||
upload_request: {
|
||||
type: 'gcp',
|
||||
options,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
const clickGCPTarget = async () => {
|
||||
await render();
|
||||
const googleOption = await screen.findByTestId('upload-google');
|
||||
await userEvent.click(googleOption);
|
||||
await clickNext();
|
||||
};
|
||||
|
||||
const selectGoogleAccount = async (optionId: string) => {
|
||||
const googleAccountOption = await screen.findByTestId(optionId);
|
||||
await userEvent.click(googleAccountOption);
|
||||
const principalInput = await screen.findByTestId('principal');
|
||||
await userEvent.type(principalInput, GCP_ACCOUNT);
|
||||
};
|
||||
|
||||
describe('gcp image type request generated correctly', () => {
|
||||
test('share image with google account', async () => {
|
||||
await clickGCPTarget();
|
||||
await selectGoogleAccount('google-account');
|
||||
await goToReview();
|
||||
const receivedRequest = await interceptBlueprintRequest(CREATE_BLUEPRINT);
|
||||
|
||||
const expectedImageRequest = createGCPCloudImage('gcp', {
|
||||
share_with_accounts: [`user:${GCP_ACCOUNT}`],
|
||||
});
|
||||
const expectedRequest: CreateBlueprintRequest = {
|
||||
...blueprintRequest,
|
||||
image_requests: [expectedImageRequest],
|
||||
};
|
||||
expect(receivedRequest).toEqual(expectedRequest);
|
||||
});
|
||||
test('share image with service account', async () => {
|
||||
await clickGCPTarget();
|
||||
await selectGoogleAccount('service-account');
|
||||
await goToReview();
|
||||
const receivedRequest = await interceptBlueprintRequest(CREATE_BLUEPRINT);
|
||||
const expectedImageRequest = createGCPCloudImage('gcp', {
|
||||
share_with_accounts: [`serviceAccount:${GCP_ACCOUNT}`],
|
||||
});
|
||||
const expectedRequest: CreateBlueprintRequest = {
|
||||
...blueprintRequest,
|
||||
image_requests: [expectedImageRequest],
|
||||
};
|
||||
expect(receivedRequest).toEqual(expectedRequest);
|
||||
});
|
||||
test('share image with google group', async () => {
|
||||
await clickGCPTarget();
|
||||
await selectGoogleAccount('google-group');
|
||||
await goToReview();
|
||||
const receivedRequest = await interceptBlueprintRequest(CREATE_BLUEPRINT);
|
||||
const expectedImageRequest = createGCPCloudImage('gcp', {
|
||||
share_with_accounts: [`group:${GCP_ACCOUNT}`],
|
||||
});
|
||||
const expectedRequest: CreateBlueprintRequest = {
|
||||
...blueprintRequest,
|
||||
image_requests: [expectedImageRequest],
|
||||
};
|
||||
expect(receivedRequest).toEqual(expectedRequest);
|
||||
});
|
||||
test('share image with domain', async () => {
|
||||
await clickGCPTarget();
|
||||
await selectGoogleAccount('google-domain');
|
||||
await goToReview();
|
||||
const receivedRequest = await interceptBlueprintRequest(CREATE_BLUEPRINT);
|
||||
const expectedImageRequest = createGCPCloudImage('gcp', {
|
||||
share_with_accounts: [`domain:${GCP_ACCOUNT}`],
|
||||
});
|
||||
const expectedRequest: CreateBlueprintRequest = {
|
||||
...blueprintRequest,
|
||||
image_requests: [expectedImageRequest],
|
||||
};
|
||||
expect(receivedRequest).toEqual(expectedRequest);
|
||||
});
|
||||
test('share image with red hat insight only', async () => {
|
||||
await clickGCPTarget();
|
||||
const shareWithInsightOption = await screen.findByTestId(
|
||||
'share-with-insights'
|
||||
);
|
||||
|
||||
await userEvent.click(shareWithInsightOption);
|
||||
await goToReview();
|
||||
const receivedRequest = await interceptBlueprintRequest(CREATE_BLUEPRINT);
|
||||
const expectedImageRequest = createGCPCloudImage('gcp', {});
|
||||
const expectedRequest: CreateBlueprintRequest = {
|
||||
...blueprintRequest,
|
||||
image_requests: [expectedImageRequest],
|
||||
};
|
||||
expect(receivedRequest).toEqual(expectedRequest);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue