Skip to content

Commit 855867e

Browse files
committed
Fix tests
1 parent 6990ef5 commit 855867e

File tree

3 files changed

+31
-21
lines changed

3 files changed

+31
-21
lines changed

test/unit/gemini.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ describe('Gemini AI unit tests', () => {
3434
const res = await callGemini({ prompt: 'text prompt' })
3535

3636
expect(res).not.toBe(null)
37-
expect(res).toHaveLength(1)
37+
expect(res).toHaveProperty('response')
38+
expect(res.response).toHaveLength(1)
3839

3940
const expectedStrategy = mockedStrategies[0]
40-
const strategy = (res as Strategy[])[0]
41+
const strategy = (res.response as Strategy[])[0]
4142
expect(strategy.name).toEqual(expectedStrategy.name)
4243
expect(strategy.risk).toEqual(expectedStrategy.risk)
4344
expect(strategy.actions.length).toEqual(expectedStrategy.actions.length)

test/unit/grok.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@ describe('Grok unit tests', () => {
3838
const res = await callGrok({ prompt: 'text prompt' })
3939

4040
expect(res).not.toBe(null)
41-
expect(res).toHaveLength(1)
41+
expect(res).toHaveProperty('response')
42+
expect(res.response).toHaveLength(1)
4243

4344
const expectedStrategy = mockedStrategies[0]
44-
const strategy = (res as Strategy[])[0]
45+
const strategy = (res.response as Strategy[])[0]
4546
expect(strategy.name).toEqual(expectedStrategy.name)
4647
expect(strategy.risk).toEqual(expectedStrategy.risk)
4748
expect(strategy.actions.length).toEqual(expectedStrategy.actions.length)

test/unit/portfolio.test.ts

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { EMPTY_PORTFOLIO_STRATEGIES } from '../../lib'
22
import {
3+
LlmProcessOutput,
34
NetworkPortfolioLibResponse,
45
PortfolioLibToken,
5-
Strategy,
66
StrategyRisk
77
} from '../../lib/types'
88
import {
@@ -31,18 +31,24 @@ const mockedNetworkPortfolioResult: NetworkPortfolioLibResponse = {
3131
}
3232
]
3333
}
34-
const mockedStrategies: Strategy[] = [
35-
{
36-
actions: [
37-
{
38-
description: 'Example USDC strategy description',
39-
tokens: 'USDC, ETH'
40-
}
41-
],
42-
name: 'Example USDC strategy name',
43-
risk: StrategyRisk.LOW
44-
}
45-
]
34+
const mockedLlmOutput: LlmProcessOutput = {
35+
llm: {
36+
provider: 'mock',
37+
model: 'mock'
38+
},
39+
response: [
40+
{
41+
actions: [
42+
{
43+
description: 'Example USDC strategy description',
44+
tokens: 'USDC, ETH'
45+
}
46+
],
47+
name: 'Example USDC strategy name',
48+
risk: StrategyRisk.LOW
49+
}
50+
]
51+
}
4652

4753
jest.mock('ambire-common/dist/src/consts/networks', () => {
4854
const actual = jest.requireActual('ambire-common/dist/src/consts/networks')
@@ -99,30 +105,32 @@ describe('Portfolio unit tests', () => {
99105
address: TEST_WALLET,
100106
getPortfolio: getPortfolioVelcroV3,
101107
makePrompt: simplePrompt,
102-
llmProcessor: () => Promise.resolve(mockedStrategies)
108+
llmProcessor: () => Promise.resolve(mockedLlmOutput)
103109
})
104110

105111
expect(res).toHaveProperty('address')
106112
expect(res).toHaveProperty('portfolio')
107113
expect(res).toHaveProperty('strategies')
108114
expect(res.address).toEqual(TEST_WALLET)
109115
expect(res.portfolio).toHaveLength(1)
110-
expect(res.strategies).toBe(mockedStrategies)
116+
expect(res.strategies).toHaveLength(1)
117+
expect(res.strategies[0]).toBe(mockedLlmOutput)
111118
})
112119

113120
test('should process address with empty portfolio and get hardcoded strategy for it', async () => {
114121
const res = await processAddress({
115122
address: TEST_WALLET,
116123
getPortfolio: () => Promise.resolve([]),
117124
makePrompt: simplePrompt,
118-
llmProcessor: () => Promise.resolve(mockedStrategies)
125+
llmProcessor: () => Promise.resolve(mockedLlmOutput)
119126
})
120127

121128
expect(res).toHaveProperty('address')
122129
expect(res).toHaveProperty('portfolio')
123130
expect(res).toHaveProperty('strategies')
124131
expect(res.address).toEqual(TEST_WALLET)
125132
expect(res.portfolio).toHaveLength(0)
126-
expect(res.strategies).toBe(EMPTY_PORTFOLIO_STRATEGIES)
133+
expect(res.strategies).toHaveLength(1)
134+
expect(res.strategies[0].response).toBe(EMPTY_PORTFOLIO_STRATEGIES)
127135
})
128136
})

0 commit comments

Comments
 (0)