-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tests): add area service tests for getArea and getAreas methods
- Loading branch information
1 parent
16461e1
commit cb89732
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
); | ||
}); | ||
}); | ||
}); | ||
}); |