Skip to content

Commit

Permalink
feat(taxonomy): removed comments
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerGauntlett committed Oct 9, 2024
1 parent fc302d3 commit 8f943f5
Showing 1 changed file with 1 addition and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ describe('metadataTaxonomyFetcher', () => {
const options: PaginationQueryInput = { marker: 'marker_1' };

beforeEach(() => {
// Create a mocked API instance
apiMock = {
getMetadataAPI: jest.fn().mockReturnValue({
getMetadataOptions: jest.fn(),
Expand All @@ -21,21 +20,17 @@ describe('metadataTaxonomyFetcher', () => {
});

test('should fetch metadata options and return formatted data', async () => {
// Mock data returned by getMetadataOptions
const mockMetadataOptions = {
entries: [
{ id: 'opt1', display_name: 'Option 1' },
{ id: 'opt2', display_name: 'Option 2' },
],
};

// Mock the getMetadataOptions method to return mock data
apiMock.getMetadataAPI(false).getMetadataOptions.mockResolvedValue(mockMetadataOptions);

// Call the function under test
const result = await metadataTaxonomyFetcher(apiMock, fileId, scope, templateKey, fieldKey, level, options);

// Expected output
const expectedResult = {
options: [
{ value: 'opt1', displayValue: 'Option 1' },
Expand All @@ -44,7 +39,6 @@ describe('metadataTaxonomyFetcher', () => {
marker: 'marker_1',
};

// Assertions
expect(apiMock.getMetadataAPI).toHaveBeenCalledWith(false);
expect(apiMock.getMetadataAPI(false).getMetadataOptions).toHaveBeenCalledWith(
fileId,
Expand All @@ -58,63 +52,43 @@ describe('metadataTaxonomyFetcher', () => {
});

test('should handle empty entries array', async () => {
// Mock data with empty entries
const mockMetadataOptions = {
entries: [],
};

// Mock the getMetadataOptions method to return mock data
apiMock.getMetadataAPI(false).getMetadataOptions.mockResolvedValue(mockMetadataOptions);

// Call the function under test
const result = await metadataTaxonomyFetcher(apiMock, fileId, scope, templateKey, fieldKey, level, options);

// Expected output
const expectedResult = {
options: [],
marker: 'marker_1',
};

// Assertions
expect(result).toEqual(expectedResult);
});

test('should set marker to null if not provided in options', async () => {
// Mock data returned by getMetadataOptions
const mockMetadataOptions = {
entries: [{ id: 'opt1', display_name: 'Option 1' }],
};

// Mock the getMetadataOptions method to return mock data
apiMock.getMetadataAPI(false).getMetadataOptions.mockResolvedValue(mockMetadataOptions);

// Call the function under test with options without marker
const result = await metadataTaxonomyFetcher(
apiMock,
fileId,
scope,
templateKey,
fieldKey,
level,
{}, // options without marker
);
const result = await metadataTaxonomyFetcher(apiMock, fileId, scope, templateKey, fieldKey, level, {});

// Expected output
const expectedResult = {
options: [{ value: 'opt1', displayValue: 'Option 1' }],
marker: null,
};

// Assertions
expect(result).toEqual(expectedResult);
});

test('should throw an error if getMetadataOptions fails', async () => {
// Mock the getMetadataOptions method to throw an error
const error = new Error('API Error');
apiMock.getMetadataAPI(false).getMetadataOptions.mockRejectedValue(error);

// Assertions
await expect(
metadataTaxonomyFetcher(apiMock, fileId, scope, templateKey, fieldKey, level, options),
).rejects.toThrow('API Error');
Expand Down

0 comments on commit 8f943f5

Please sign in to comment.