Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/zk UI 415 move overlay out of redux #688

Merged
merged 27 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
ad8d0ee
Refactor bucket overview
JBWatenbergScality Nov 20, 2023
8edfa57
Refactor object listing
JBWatenbergScality Nov 20, 2023
c5c226e
Refactor metadata edition
JBWatenbergScality Nov 20, 2023
8554936
Refactor object properties
JBWatenbergScality Nov 21, 2023
ea62791
Refactor endpoint creation
JBWatenbergScality Nov 21, 2023
8e81366
Refactor endpoint listing
JBWatenbergScality Nov 21, 2023
943deb3
Refactor location editor
JBWatenbergScality Nov 21, 2023
9215acd
Refactor create workflows
JBWatenbergScality Nov 21, 2023
2626709
Refactor workflow edit tab
JBWatenbergScality Nov 21, 2023
ec82f7d
Refactor Workflow content
JBWatenbergScality Nov 21, 2023
d00fa57
Refactor endpoint creation and deletion
JBWatenbergScality Nov 24, 2023
d14d9e4
Refactor bucket list
JBWatenbergScality Nov 24, 2023
e2fe058
Remove redux from endpoints management
JBWatenbergScality Nov 24, 2023
9c93fb4
Polish refactoring
JBWatenbergScality Nov 29, 2023
1c847bd
Fix test
JBWatenbergScality Nov 29, 2023
c0df65d
Fix tests
JBWatenbergScality Nov 29, 2023
973a29f
Remove unexpected key warning
JBWatenbergScality Nov 29, 2023
64527b3
test useWaitForRunningConfigurationVersionToBeUpdated
JBWatenbergScality Dec 4, 2023
0e21b74
tests: Remove some relicas jest-preview.debug()
JBWatenbergScality Dec 4, 2023
f5e7a65
Add a close button and a test to the account deletion error modal
JBWatenbergScality Dec 4, 2023
4a80989
Better error handling when we fail to load locations
JBWatenbergScality Dec 4, 2023
61e0004
Fix default location type
JBWatenbergScality Dec 4, 2023
9b471f2
Merge remote-tracking branch 'origin/development/2.2' into feature/ZK…
JBWatenbergScality Dec 4, 2023
8b21eb3
use refresh global hook
JBWatenbergScality Dec 4, 2023
7b434f4
Fix flacky
JBWatenbergScality Dec 4, 2023
226ab7a
src/react/ui-elements/Veeam/VeeamTable.test.tsx
JBWatenbergScality Dec 6, 2023
3d23388
fix test
JBWatenbergScality Dec 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion jestSetupAfterEnv.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import '@testing-library/jest-dom';
import fetch from 'node-fetch';
import { queryClient } from './src/react/utils/testUtil';
import { VEEAM_FEATURE } from './src/js/config';

window.fetch = (url, ...rest) =>
fetch(/^https?:/.test(url) ? url : new URL(url, 'http://localhost'), ...rest);
Expand Down Expand Up @@ -43,7 +44,7 @@ jest.mock('./src/react/next-architecture/ui/ConfigProvider', () => {
iamEndpoint: TEST_API_BASE_URL,
navbarEndpoint: TEST_API_BASE_URL,
navbarConfigUrl: TEST_API_BASE_URL,
features: [],
features: ['Veeam', 'XDM'],
basePath: '',
};
}),
Expand Down
3 changes: 2 additions & 1 deletion src/js/mock/S3Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {
} from '../../types/s3';
import type { AWSError } from '../../types/aws';
import { addTrailingSlash } from '../../react/utils';
import { azureblobstorage } from './managementClientMSWHandlers';
export const ownerName = 'bart';
export const bucketName = 'bucket';
export const fileName = 'file';
Expand Down Expand Up @@ -167,7 +168,7 @@ export const bucketInfoResponseVersioningDisabled: BucketInfo = {
versioning: 'Disabled',
isVersioning: false,
public: false,
locationConstraint: 'azure-blob',
locationConstraint: azureblobstorage,
objectLockConfiguration: {
ObjectLockEnabled: 'Disabled',
},
Expand Down
22 changes: 12 additions & 10 deletions src/js/mock/managementClientMSWHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { LatestUsedCapacity } from '../../react/next-architecture/domain/entitie

export const ACCOUNT_ID = '718643629313';
export const BUCKET_NAME = 'test-bucket';
const azureblobstorage = 'azureblobstorage';
export const azureblobstorage = 'azureblobstorage';

export const TRANSITION_WORKFLOW_CURRENT_ID =
'0d55a1d7-349c-4e79-932b-b502bcc45a8f';
Expand Down Expand Up @@ -157,22 +157,24 @@ export const LOCATIONS = {
},
};

export const ENDPOINTS = [
{
hostname: 'zenko-cloudserver-replicator',
isBuiltin: true,
locationName: 'us-east-1',
},
{ hostname: 's3.zenko.local', locationName: 'us-east-1' },
{ hostname: 'test.local', locationName: 'us-east-1' },
];

export const getConfigOverlay = (baseUrl: string, instanceId: string) => {
return rest.get(
`${baseUrl}/api/v1/config/overlay/view/${instanceId}`,
(req, res, ctx) =>
res(
ctx.json({
browserAccess: { enabled: true },
endpoints: [
{
hostname: 'zenko-cloudserver-replicator',
isBuiltin: true,
locationName: 'us-east-1',
},
{ hostname: 's3.zenko.local', locationName: 'us-east-1' },
{ hostname: 'test.local', locationName: 'us-east-1' },
],
endpoints: ENDPOINTS,
instanceId,
locations: LOCATIONS,
replicationStreams: [],
Expand Down
228 changes: 214 additions & 14 deletions src/js/mutations.test.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import { act, renderHook } from '@testing-library/react-hooks';
import { rest } from 'msw';
import { setupServer } from 'msw/node';
import { renderHook } from '@testing-library/react-hooks';
import {
useAttachPolicyToUserMutation,
useCreateIAMUserMutation,
useCreateEndpointMutation,
useCreateAccountMutation,
useCreatePolicyMutation,
usePutObjectMutation,
usePutBucketTaggingMutation,
useCreateUserAccessKeyMutation,
} from './mutations';
import { NewWrapper, TEST_API_BASE_URL } from '../react/utils/testUtil';
import { INSTANCE_ID } from '../react/actions/__tests__/utils/testUtil';
import {
GET_VEEAM_IMMUTABLE_POLICY,
SYSTEM_XML_CONTENT,
VEEAM_IMMUTABLE_POLICY_NAME,
VEEAM_XML_PREFIX,
} from '../react/ui-elements/Veeam/VeeamConstants';
import { INSTANCE_ID } from '../react/actions/__tests__/utils/testUtil';
import { NewWrapper, TEST_API_BASE_URL } from '../react/utils/testUtil';
import {
useAttachPolicyToUserMutation,
useCreateAccountMutation,
useCreateEndpointMutation,
useCreateIAMUserMutation,
useCreatePolicyMutation,
useCreateUserAccessKeyMutation,
usePutBucketTaggingMutation,
usePutObjectMutation,
useWaitForRunningConfigurationVersionToBeUpdated,
} from './mutations';

//Subject Under Testing
const SUT = jest.fn();
Expand All @@ -45,6 +46,137 @@ const veeamPolicyArn = `arn:aws:iam::${accountId}:policy/${veeamPolicyName}`;
const policyNameWithErrorTriggered = `${VEEAM_IMMUTABLE_POLICY_NAME}-${bucketNameWithErrorTriggered}`;
const veeamObjectKey = `${VEEAM_XML_PREFIX}/system.xml`;

const getLatestInstanceStatusFailingMock = () =>
rest.get(
`${TEST_API_BASE_URL}/api/v1/instance/${instanceId}/status`,
(req, res, ctx) => {
return res(ctx.status(500));
},
);

const getLatestInstanceStatusMock = (runningConfigurationVersion: number = 1) =>
rest.get(
`${TEST_API_BASE_URL}/api/v1/instance/${instanceId}/status`,
(req, res, ctx) => {
return res(
ctx.status(200),
ctx.json({
metrics: {
cpu: {
idle: 119998230,
nice: 1140,
sys: 8083540,
user: 35370130,
},
'crr-schedule': {
states: {
'eu-cloud-1': 'enabled',
'val-9464-location': 'enabled',
},
},
'crr-stats': {
backlog: {},
completions: {},
failures: {},
pending: {},
stalled: {},
throughput: {},
byLocation: {
'eu-cloud-1': {
backlog: {},
completions: {},
failures: {},
pending: {},
throughput: {},
},
'val-9464-location': {
backlog: {},
completions: {},
failures: {},
pending: {},
throughput: {},
},
},
},
'data-disk-usage': {
available: 89988096,
free: 92085248,
total: 95762432,
},
'ingest-schedule': {},
'ingest-stats': {
completions: {},
pending: {},
throughput: {},
},
'item-counts': {
bucketList: [
{
isVersioned: true,
location: 'us-east-1',
name: 'test',
ownerCanonicalId:
'eae2600b0c0cfbdcae63eb13b501814668d747e136e16f68092709a23fc77422',
},
],
buckets: 1,
dataManaged: {
byLocation: {
'22f31240-4bd3-11ee-98b3-1e5b6f897bc7': {
curr: 39472026504,
prev: 10256254,
},
'df6098b2-56cd-11ee-815e-f65a3b964922': {
curr: 1859580,
},
},
total: {
curr: 39473886084,
prev: 10256254,
},
},
objects: 47835,
versions: 12,
},
'md-disk-usage': {
available: 73761554432,
free: 73761554432,
total: 213578133504,
},
memory: {
free: 11772411904,
total: 33065947136,
},
},
state: {
capabilities: {
locationTypeCephRadosGW: true,
locationTypeDigitalOcean: true,
locationTypeHyperdriveV2: true,
locationTypeLocal: true,
locationTypeNFS: true,
locationTypeS3Custom: true,
locationTypeSproxyd: true,
managedLifecycle: true,
managedLifecycleTransition: true,
preferredReadLocation: true,
s3cIngestLocation: true,
secureChannel: true,
secureChannelOptimizedPath: true,
},
ipAddress: '10.233.9.177',
lastSeen: '2023-12-01T12:59:02.407Z',
latestConfigurationOverlay: {
version: runningConfigurationVersion,
},
runningConfigurationVersion,
serverVersion: 'ref: refs/heads/development/8.8\n',
},
}),
);
},
);

export const getVeeamMutationHandler = () => [
// create endpoint
rest.post(
Expand Down Expand Up @@ -247,7 +379,10 @@ export const getVeeamMutationHandler = () => [
},
),
];
const server = setupServer(...getVeeamMutationHandler());
const server = setupServer(
getLatestInstanceStatusMock(),
...getVeeamMutationHandler(),
);

beforeAll(() => server.listen());
afterEach(() => {
Expand All @@ -257,6 +392,71 @@ afterEach(() => {
afterAll(() => server.close());

describe('mutations', () => {
it('should return an error when failed to retrieve current running version while taking the reference', async () => {
//Setup
server.use(getLatestInstanceStatusFailingMock());
const { result, waitFor } = renderHook(
() => useWaitForRunningConfigurationVersionToBeUpdated(),
{
wrapper: NewWrapper(),
},
);
//Exercise
act(() => {
result.current.setReferenceVersion({});
});
//Verify
await waitFor(() => {
expect(result.current.status).toBe('error');
});
});

it('should return an error when failed to retrieve current running version while waiting for the new version', async () => {
//Setup
const { result, waitFor } = renderHook(
() => useWaitForRunningConfigurationVersionToBeUpdated(),
{
wrapper: NewWrapper(),
},
);
//Exercise
act(() => {
result.current.setReferenceVersion({
onRefTaken: () => {
server.use(getLatestInstanceStatusFailingMock());
result.current.waitForRunningConfigurationVersionToBeUpdated();
},
});
});
//Verify
await waitFor(() => {
expect(result.current.status).toBe('error');
});
});

it('should wait for running configuration to be updated', async () => {
//Setup
const { result, waitFor } = renderHook(
() => useWaitForRunningConfigurationVersionToBeUpdated(),
{
wrapper: NewWrapper(),
},
);
//Exercise
act(() => {
result.current.setReferenceVersion({
onRefTaken: () => {
server.use(getLatestInstanceStatusMock(2));
result.current.waitForRunningConfigurationVersionToBeUpdated();
},
});
});
//Verify
await waitFor(() => {
expect(result.current.status).toBe('success');
});
});

it('should handle the useCreateEndpointMutation', async () => {
//Setup
const { result, waitFor } = renderHook(() => useCreateEndpointMutation(), {
Expand Down
Loading
Loading