Skip to content

Commit 06b5ece

Browse files
committed
Merge branch 'improvement/ARTESCA-15091-policy-action-text-accuracy' into q/4.1
2 parents dc258d5 + 2386496 commit 06b5ece

2 files changed

Lines changed: 97 additions & 3 deletions

File tree

src/react/ISV/hooks/useMutationActions.test.ts

Lines changed: 91 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,85 @@ describe('useMutationActions', () => {
236236
});
237237

238238
describe('Basic functionality tests', () => {
239+
it.each([
240+
[
241+
'Create Policy',
242+
'create',
243+
{
244+
id: 'existing-account-id',
245+
preferredAssumableRoleArn:
246+
'arn:aws:iam::existing-account-id:role/test-role',
247+
},
248+
],
249+
[
250+
'Update Policy',
251+
'existing',
252+
{
253+
id: 'existing-account-id',
254+
preferredAssumableRoleArn:
255+
'arn:aws:iam::existing-account-id:role/test-role',
256+
},
257+
],
258+
['Create Policy', 'create', null], // Test when creating new account
259+
])(
260+
'should show "%s" when IAMUserNameType is "%s" and account is %p',
261+
(expectedPolicyAction, userNameType, accountValue) => {
262+
const { mockMutate, mockMutationsWithRetry } = mockSetupCommonMocks();
263+
264+
const props = {
265+
...mockBaseProps,
266+
...(userNameType && { IAMUserNameType: userNameType }),
267+
...(userNameType === 'existing' && { IAMUserName: 'existing-user' }),
268+
account: accountValue,
269+
};
270+
271+
const actions = [
272+
...(!accountValue
273+
? ['Create an Account', 'Update Configuration']
274+
: []),
275+
'Assume Account Role',
276+
'Create a Bucket: test-bucket-1',
277+
'Tag Bucket: test-bucket-1',
278+
'Prepare Veeam integrated object repository',
279+
'Enforce Veeam integrated object repository',
280+
'Set maximum repository capacity',
281+
'Create a Bucket: test-bucket-2',
282+
'Tag Bucket: test-bucket-2',
283+
'Prepare Veeam integrated object repository',
284+
'Enforce Veeam integrated object repository',
285+
'Set maximum repository capacity',
286+
...(!accountValue || userNameType === 'create'
287+
? ['Create a User', 'Generate Access key and Secret key']
288+
: []),
289+
expectedPolicyAction,
290+
'Attach Policy to User',
291+
];
292+
293+
const steps = actions.map((action, i) => ({
294+
status: 'success',
295+
data: { step: i },
296+
}));
297+
298+
(useChainedMutations as jest.Mock).mockReturnValue({
299+
mutate: mockMutate,
300+
steps,
301+
mutationsWithRetry: mockMutationsWithRetry,
302+
actions,
303+
});
304+
305+
const { result } = renderHook(() =>
306+
useMutationActions(props as any, mockBucketMutations),
307+
);
308+
309+
// Verify the expected policy action is in the actions
310+
const policyAction = result.current.data.find(
311+
(d) => d.action === expectedPolicyAction,
312+
);
313+
expect(policyAction).toBeDefined();
314+
expect(policyAction.action).toBe(expectedPolicyAction);
315+
},
316+
);
317+
239318
it('should return the correct data structure - create new account scenario', () => {
240319
const { mockMutate, mockMutationsWithRetry } = mockSetupCommonMocks();
241320

@@ -297,6 +376,11 @@ describe('useMutationActions', () => {
297376
retry: expect.any(Function),
298377
});
299378

379+
// Verify it shows "Create Policy" for new user
380+
expect(
381+
result.current.data.some((d) => d.action === 'Create Policy'),
382+
).toBe(true);
383+
300384
// Verify mutate was called
301385
expect(mockMutate).toHaveBeenCalled();
302386
});
@@ -328,7 +412,7 @@ describe('useMutationActions', () => {
328412
'Set maximum repository capacity',
329413
'Create a User',
330414
'Generate Access key and Secret key',
331-
'Create Policy',
415+
'Create Policy', // Since IAMUserNameType defaults to 'create', it's Create Policy
332416
'Attach Policy to User',
333417
];
334418

@@ -389,7 +473,7 @@ describe('useMutationActions', () => {
389473
'Prepare Veeam integrated object repository',
390474
'Enforce Veeam integrated object repository',
391475
'Set maximum repository capacity',
392-
'Create Policy',
476+
'Update Policy',
393477
'Attach Policy to User',
394478
];
395479

@@ -425,6 +509,11 @@ describe('useMutationActions', () => {
425509
// Verify returning existing key
426510
expect(result.current.accessKey).toBe('existing-access-key');
427511
expect(result.current.secretKey).toBe('');
512+
513+
// Verify it shows "Update Policy" for existing user
514+
expect(
515+
result.current.data.some((d) => d.action === 'Update Policy'),
516+
).toBe(true);
428517
});
429518
});
430519

src/react/ISV/hooks/useMutationActions.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,12 @@ export const useMutationActions = (
156156
});
157157
}
158158

159-
actions.push('Create Policy');
159+
const isCreatingNewPolicy = !account || IAMUserNameType === 'create';
160+
const policyAction = isCreatingNewPolicy
161+
? 'Create Policy'
162+
: 'Update Policy';
163+
164+
actions.push(policyAction);
160165
steps.push({
161166
...createPolicyMutation,
162167
key: 'createPolicy',

0 commit comments

Comments
 (0)