Skip to content

Commit

Permalink
ZKUI-397: No error toast in case of getBucketTagging NotSuchTagSet
Browse files Browse the repository at this point in the history
  • Loading branch information
ChengYanJin committed Nov 17, 2023
1 parent 20c259b commit b54dca7
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 8 deletions.
16 changes: 16 additions & 0 deletions src/js/mock/S3ClientMSWHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,19 @@ export const mockGetBucketTaggingError = (bucketName: string) => {
},
);
};

export const mockGetBucketTaggingNoSuchTagSet = (bucketName: string) => {
return rest.get(
`${zenkoUITestConfig.zenkoEndpoint}/${bucketName}`,
(req, res, ctx) => {
if (req.url.searchParams.has('tagging')) {
return res(
ctx.status(404),
ctx.xml(
`<?xml version="1.0" encoding="UTF-8"?><Error><Code>NoSuchTagSet</Code><Message>The TagSet does not exist</Message><Resource></Resource><RequestId>339248ffc345a202d25e</RequestId></Error>`,
),
);
}
},
);
};
24 changes: 19 additions & 5 deletions src/react/databrowser/buckets/details/__tests__/Overview.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ import {
mockBucketOperations,
mockGetBucketTagging,
mockGetBucketTaggingError,
mockGetBucketTaggingNoSuchTagSet,
} from '../../../../../js/mock/S3ClientMSWHandlers';
const mockResponse =
'<VersioningConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><Status>Enabled</Status></VersioningConfiguration>';
Expand Down Expand Up @@ -261,6 +262,10 @@ const selectors = {
within(screen.getByRole('status')).getByText(
/Encountered issues loading bucket tagging, causing uncertainty about the use-case. Please refresh the page./i,
),
bucketTaggingErorToastQuery: () =>
screen.queryByText(
/Encountered issues loading bucket tagging, causing uncertainty about the use-case. Please refresh the page./i,
),
};

describe('Overview', () => {
Expand Down Expand Up @@ -326,11 +331,20 @@ describe('Overview', () => {
userEvent.click(selectors.bucketTaggingErrorToastCloseButton());
//Verify
await waitFor(() => {
expect(
screen.queryByText(
/Encountered issues loading bucket tagging, causing uncertainty about the use-case. Please refresh the page./i,
),
).toBe(null);
expect(selectors.bucketTaggingErorToastQuery()).toBe(null);
});
});

it('should not show error toast if tags are not found', async () => {
//Setup
server.use(mockGetBucketTaggingNoSuchTagSet(bucketName));
//Exercise
render(<Overview bucket={{ name: bucketName }} />, {
wrapper: NewWrapper(),
});
//Verify
await waitFor(() => {
expect(selectors.bucketTaggingErorToastQuery()).toBe(null);
});
});
});
21 changes: 19 additions & 2 deletions src/react/next-architecture/domain/business/buckets.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
mockBucketOperations,
mockGetBucketTagging,
mockGetBucketTaggingError,
mockGetBucketTaggingNoSuchTagSet,
} from '../../../../js/mock/S3ClientMSWHandlers';
import { BUCKET_TAG_USECASE } from '../../../ui-elements/Veeam/VeeamConstants';

Expand Down Expand Up @@ -901,9 +902,9 @@ describe('Buckets domain', () => {
});

describe('useBucketTagging', () => {
const BUCKET_NAME = 'bucket-name';
it('should return the tags for a specific bucket', async () => {
//Setup
const BUCKET_NAME = 'bucket-name';
server.use(mockGetBucketTagging(BUCKET_NAME));
const { waitFor, result } = renderHook(
() => useBucketTagging({ bucketName: BUCKET_NAME }),
Expand All @@ -923,7 +924,6 @@ describe('Buckets domain', () => {
});
it('should return an error if the tags fetching failed', async () => {
//Setup
const BUCKET_NAME = 'bucket-name';
server.use(mockGetBucketTaggingError(BUCKET_NAME));
const { waitFor, result } = renderHook(
() => useBucketTagging({ bucketName: BUCKET_NAME }),
Expand All @@ -940,5 +940,22 @@ describe('Buckets domain', () => {
},
});
});
it('shuold return success if NoSuchTagSet', async () => {
//Setup
server.use(mockGetBucketTaggingNoSuchTagSet(BUCKET_NAME));
const { waitFor, result } = renderHook(
() => useBucketTagging({ bucketName: BUCKET_NAME }),
{ wrapper: NewWrapper() },
);
//Exercise
await waitFor(() => result.current.tags.status === 'success');
//Verify
expect(result.current).toEqual({
tags: {
status: 'success',
value: {},
},
});
});
});
});
10 changes: 9 additions & 1 deletion src/react/next-architecture/domain/business/buckets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ export const useBucketTagging = ({
bucketName: string;
}): BucketTaggingPromiseResult => {
const s3Client = useS3Client();
const { data, status } = useQuery({
const { data, status, error } = useQuery({
...queries.getBucketTagging(s3Client, bucketName),
});

Expand All @@ -533,6 +533,14 @@ export const useBucketTagging = ({
},
};
}
if (status === 'error' && error?.code === 'NoSuchTagSet') {
return {
tags: {
status: 'success',
value: {},
},
};
}
if (status === 'error') {
return {
tags: {
Expand Down

0 comments on commit b54dca7

Please sign in to comment.