|
| 1 | +import { enableFetchMocks } from 'jest-fetch-mock'; |
| 2 | +import { Hyper } from '../index'; |
| 3 | + |
| 4 | +enableFetchMocks(); |
| 5 | + |
| 6 | +const hyper = new Hyper('hyper_1234'); |
| 7 | + |
| 8 | +describe('Hypercode contexts API methods', () => { |
| 9 | + afterEach(() => fetchMock.resetMocks()); |
| 10 | + |
| 11 | + describe('list method', () => { |
| 12 | + it('should return the correct list of all created contexts', async () => { |
| 13 | + const expectedResult = [ |
| 14 | + { |
| 15 | + created_at: '2023-10-28T04:28:13.971776+00:00', |
| 16 | + id: 'f03f7113-d60e-472f-a266-8e0a1f091386', |
| 17 | + name: 'Data Analysis', |
| 18 | + }, |
| 19 | + { |
| 20 | + created_at: '2023-11-02T22:18:44.978052+00:00', |
| 21 | + id: 'a26d4182-4494-4ebc-b19f-1633fddc81d7', |
| 22 | + name: 'Project Management', |
| 23 | + }, |
| 24 | + { |
| 25 | + created_at: '2023-10-24T16:33:47.689614+00:00', |
| 26 | + id: '62df1b77-07e9-40e1-8de8-14f2075309e5', |
| 27 | + name: 'Human Resources', |
| 28 | + }, |
| 29 | + ]; |
| 30 | + |
| 31 | + fetchMock.mockOnce(JSON.stringify(expectedResult), { |
| 32 | + status: 200, |
| 33 | + }); |
| 34 | + |
| 35 | + const result = await hyper.contexts.list(); |
| 36 | + |
| 37 | + expect(result.data).toEqual(expectedResult); |
| 38 | + expect(fetchMock).toHaveBeenLastCalledWith( |
| 39 | + expect.any(String), // endpoint |
| 40 | + // body and headers |
| 41 | + expect.any(Object), |
| 42 | + ); |
| 43 | + }); |
| 44 | + }); |
| 45 | +}); |
0 commit comments