|
1 | 1 | import { enableFetchMocks } from 'jest-fetch-mock';
|
2 | 2 | import { Hyper } from '../index';
|
| 3 | +import type { AllowedTypes } from './@types'; |
3 | 4 |
|
4 | 5 | enableFetchMocks();
|
5 | 6 |
|
| 7 | +const baseUrl = process.env.HYPER_BASE_URL || 'https://api.gethyper.ai/v1'; |
| 8 | +const endpoint = '/types'; |
| 9 | +const fullEndpoint = (type: AllowedTypes) => `${baseUrl}${endpoint}/${type}`; |
| 10 | + |
6 | 11 | const hyper = new Hyper('hyper_1234');
|
7 | 12 |
|
8 | 13 | describe('Hypercode Types API methods', () => {
|
@@ -34,7 +39,7 @@ describe('Hypercode Types API methods', () => {
|
34 | 39 | expect(typeof result.data).toBe('string');
|
35 | 40 | expect(result.data).toBe('Elon Musk');
|
36 | 41 | expect(fetchMock).toHaveBeenLastCalledWith(
|
37 |
| - expect.any(String), // endpoint |
| 42 | + fullEndpoint('string'), // endpoint |
38 | 43 | // body and headers
|
39 | 44 | expect.objectContaining({
|
40 | 45 | body: expect.stringContaining(
|
@@ -69,15 +74,15 @@ describe('Hypercode Types API methods', () => {
|
69 | 74 | status: 200,
|
70 | 75 | });
|
71 | 76 |
|
72 |
| - const result = await hyper.types.string( |
| 77 | + const result = await hyper.types.integer( |
73 | 78 | 'How many planets are in the Solar System?',
|
74 | 79 | { contextId },
|
75 | 80 | );
|
76 | 81 |
|
77 | 82 | expect(typeof result.data).toBe('number');
|
78 | 83 | expect(result.data).toBe(42);
|
79 | 84 | expect(fetchMock).toHaveBeenLastCalledWith(
|
80 |
| - expect.any(String), // endpoint |
| 85 | + fullEndpoint('integer'), // endpoint |
81 | 86 | // body and headers
|
82 | 87 | expect.objectContaining({
|
83 | 88 | body: expect.stringContaining(
|
@@ -123,7 +128,7 @@ describe('Hypercode Types API methods', () => {
|
123 | 128 | expect(typeof result.data).toBe('number');
|
124 | 129 | expect(result.data).toBe(fixedStatistic);
|
125 | 130 | expect(fetchMock).toHaveBeenLastCalledWith(
|
126 |
| - expect.any(String), // endpoint |
| 131 | + fullEndpoint('float'), // endpoint |
127 | 132 | // body and headers
|
128 | 133 | expect.objectContaining({
|
129 | 134 | body: expect.stringContaining(
|
@@ -163,7 +168,7 @@ describe('Hypercode Types API methods', () => {
|
163 | 168 | expect(typeof result.data).toBe('boolean');
|
164 | 169 | expect(result.data).toBe(true);
|
165 | 170 | expect(fetchMock).toHaveBeenLastCalledWith(
|
166 |
| - expect.any(String), // endpoint |
| 171 | + fullEndpoint('boolean'), // endpoint |
167 | 172 | // body and headers
|
168 | 173 | expect.objectContaining({
|
169 | 174 | body: expect.stringContaining(
|
@@ -210,7 +215,7 @@ describe('Hypercode Types API methods', () => {
|
210 | 215 | expect(new Date(data!)).toBeInstanceOf(Date);
|
211 | 216 | expect(new Date(data!).getFullYear()).toBe(1969);
|
212 | 217 | expect(fetchMock).toHaveBeenLastCalledWith(
|
213 |
| - expect.any(String), // endpoint |
| 218 | + fullEndpoint('datetime'), // endpoint |
214 | 219 | // body and headers
|
215 | 220 | expect.objectContaining({
|
216 | 221 | body: expect.stringContaining(
|
|
0 commit comments