Skip to content

Commit 474fee1

Browse files
committed
fun first test
1 parent c21559d commit 474fee1

File tree

2 files changed

+35
-9
lines changed

2 files changed

+35
-9
lines changed

src/index.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,35 @@
22
* Main entry point for the RxInfer Client package.
33
* @packageDocumentation
44
*/
5+
import { Client } from '@hey-api/client-fetch';
6+
import { type Config, type ClientOptions as DefaultClientOptions, createClient, createConfig } from '@hey-api/client-fetch';
7+
import { tokenGenerate } from './client/sdk.gen';
58

69
export * from './client/index';
10+
export { Client } from '@hey-api/client-fetch';
711

812
export class RxInferClient {
9-
constructor() { }
13+
constructor() {
14+
throw new Error('Use RxInferClient.create() to create a new client');
15+
}
16+
17+
static async create(baseUrl: string = 'http://localhost:8000/v1', apiKey: string | undefined = undefined): Promise<Client> {
18+
let token: string | undefined = apiKey;
19+
if (!token) {
20+
const tmpClient = createClient({
21+
baseUrl: baseUrl,
22+
});
23+
const tokenResponse = await tokenGenerate({
24+
client: tmpClient,
25+
});
26+
token = tokenResponse.data?.token;
27+
if (!token) {
28+
throw new Error('No API key provided');
29+
}
30+
}
31+
return createClient({
32+
baseUrl: baseUrl,
33+
auth: token,
34+
});
35+
}
1036
}

test/client.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import { RxInferClient } from '../src';
2+
import { pingServer } from '../src';
3+
import { Client } from '../src';
24

35
describe('RxInferClient', () => {
4-
let client: RxInferClient;
6+
let client: Client;
57

6-
beforeEach(() => {
7-
client = new RxInferClient();
8+
beforeEach(async () => {
9+
client = await RxInferClient.create();
810
});
911

1012
it('should instantiate the client', () => {
11-
expect(client).toBeInstanceOf(RxInferClient);
13+
expect(client).toBeDefined();
1214
});
1315

1416
it('should ping the server', async () => {
15-
// Mock the ping method if it exists in your client
16-
// This is a placeholder test that will need to be updated
17-
// once the OpenAPI client is generated
18-
expect(client).toBeDefined();
17+
const response = await pingServer({ client });
18+
expect(response.data).toEqual({ status: 'ok' });
1919
});
2020
});

0 commit comments

Comments
 (0)