Skip to content

Commit

Permalink
feat(tests): add area service tests for getArea and getAreas methods
Browse files Browse the repository at this point in the history
  • Loading branch information
willian-viana committed Jan 21, 2025
1 parent 16461e1 commit cb89732
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions services/__tests__/areas.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { jest } from '@jest/globals';

import { getArea, getAreas } from '../areas';
import { apiAuthRequest } from '../../utils/request';

jest.mock('../../utils/request', () => ({
apiAuthRequest: {
get: jest.fn(),
},
}));

describe('Areas Service', () => {
afterEach(() => {
jest.clearAllMocks(); // Limpa os mocks após cada teste
});

describe('Getting a Single Area', () => {
describe('The Request to the API', () => {
it('should add source params for gadm 4.1', async () => {
// arrange
apiAuthRequest.get.mockResolvedValueOnce({
data: { data: { attributes: {} } },
});

// act
await getArea('abcdef123456789');

// assert
expect(apiAuthRequest.get).toHaveBeenCalledWith(
'/v2/area/abcdef123456789?source[provider]=gadm&source[version]=4.1',
{
headers: {},
}
);
});
});
});

describe('Getting Multiple Areas', () => {
describe('The Request to the API', () => {
it('should add source params for gadm 4.1', async () => {
// arrange
apiAuthRequest.get.mockResolvedValueOnce({
data: { data: [{ attributes: {} }] },
});

// act
await getAreas();

// assert
expect(apiAuthRequest.get).toHaveBeenCalledWith(
'/v2/area?source[provider]=gadm&source[version]=4.1'
);
});
});
});
});

0 comments on commit cb89732

Please sign in to comment.