Skip to content

Commit de3e2a5

Browse files
committed
Test tweaks
1 parent af3adde commit de3e2a5

File tree

1 file changed

+20
-25
lines changed

1 file changed

+20
-25
lines changed

src/api/providers/__tests__/glama.test.ts

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,18 @@ jest.mock("openai", () => {
1919
const stream = {
2020
[Symbol.asyncIterator]: async function* () {
2121
yield {
22-
choices: [
23-
{
24-
delta: { content: "Test response" },
25-
index: 0,
26-
},
27-
],
22+
choices: [{ delta: { content: "Test response" }, index: 0 }],
2823
usage: null,
2924
}
3025
yield {
31-
choices: [
32-
{
33-
delta: {},
34-
index: 0,
35-
},
36-
],
37-
usage: {
38-
prompt_tokens: 10,
39-
completion_tokens: 5,
40-
total_tokens: 15,
41-
},
26+
choices: [{ delta: {}, index: 0 }],
27+
usage: { prompt_tokens: 10, completion_tokens: 5, total_tokens: 15 },
4228
}
4329
},
4430
}
4531

4632
const result = mockCreate(...args)
33+
4734
if (args[0].stream) {
4835
mockWithResponse.mockReturnValue(
4936
Promise.resolve({
@@ -58,6 +45,7 @@ jest.mock("openai", () => {
5845
)
5946
result.withResponse = mockWithResponse
6047
}
48+
6149
return result
6250
},
6351
},
@@ -72,10 +60,10 @@ describe("GlamaHandler", () => {
7260

7361
beforeEach(() => {
7462
mockOptions = {
75-
apiModelId: "anthropic/claude-3-7-sonnet",
76-
glamaModelId: "anthropic/claude-3-7-sonnet",
7763
glamaApiKey: "test-api-key",
64+
glamaModelId: "anthropic/claude-3-7-sonnet",
7865
}
66+
7967
handler = new GlamaHandler(mockOptions)
8068
mockCreate.mockClear()
8169
mockWithResponse.mockClear()
@@ -101,7 +89,7 @@ describe("GlamaHandler", () => {
10189
describe("constructor", () => {
10290
it("should initialize with provided options", () => {
10391
expect(handler).toBeInstanceOf(GlamaHandler)
104-
expect(handler.getModel().id).toBe(mockOptions.apiModelId)
92+
expect(handler.getModel().id).toBe(mockOptions.glamaModelId)
10593
})
10694
})
10795

@@ -152,7 +140,7 @@ describe("GlamaHandler", () => {
152140
expect(result).toBe("Test response")
153141
expect(mockCreate).toHaveBeenCalledWith(
154142
expect.objectContaining({
155-
model: mockOptions.apiModelId,
143+
model: mockOptions.glamaModelId,
156144
messages: [{ role: "user", content: "Test prompt" }],
157145
temperature: 0,
158146
max_tokens: 8192,
@@ -196,13 +184,20 @@ describe("GlamaHandler", () => {
196184
})
197185
})
198186

199-
describe("getModel", () => {
200-
it("should return model info", () => {
201-
const modelInfo = handler.getModel()
202-
expect(modelInfo.id).toBe(mockOptions.apiModelId)
187+
describe("fetchModel", () => {
188+
it("should return model info", async () => {
189+
const modelInfo = await handler.fetchModel()
190+
expect(modelInfo.id).toBe(mockOptions.glamaModelId)
203191
expect(modelInfo.info).toBeDefined()
204192
expect(modelInfo.info.maxTokens).toBe(8192)
205193
expect(modelInfo.info.contextWindow).toBe(200_000)
206194
})
195+
196+
it("should return default model when invalid model provided", async () => {
197+
const handlerWithInvalidModel = new GlamaHandler({ ...mockOptions, glamaModelId: "invalid/model" })
198+
const modelInfo = await handlerWithInvalidModel.fetchModel()
199+
expect(modelInfo.id).toBe("anthropic/claude-3-7-sonnet")
200+
expect(modelInfo.info).toBeDefined()
201+
})
207202
})
208203
})

0 commit comments

Comments
 (0)