Skip to content

Commit 016d7f5

Browse files
committed
test
1 parent a9d6da6 commit 016d7f5

2 files changed

Lines changed: 33 additions & 7 deletions

File tree

src/compare/compare.service.spec.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import { Test, TestingModule } from '@nestjs/testing';
2+
import { ConfigService } from '@nestjs/config';
23
import { PrismaService } from '../prisma/prisma.service';
34
import { CompareService } from './compare.service';
45
import { LookSameService } from './libs/looks-same/looks-same.service';
56
import { OdiffService } from './libs/odiff/odiff.service';
67
import { PixelmatchService } from './libs/pixelmatch/pixelmatch.service';
8+
import { VlmService } from './libs/vlm/vlm.service';
9+
import { OllamaService } from './libs/vlm/ollama.service';
710
import { StaticModule } from '../static/static.module';
811
import { ImageComparison } from '@prisma/client';
912
import * as utils from '../static/utils';
@@ -16,7 +19,21 @@ describe('CompareService', () => {
1619

1720
beforeEach(async () => {
1821
const module: TestingModule = await Test.createTestingModule({
19-
providers: [CompareService, OdiffService, PixelmatchService, LookSameService, PrismaService],
22+
providers: [
23+
CompareService,
24+
OdiffService,
25+
PixelmatchService,
26+
LookSameService,
27+
VlmService,
28+
OllamaService,
29+
PrismaService,
30+
{
31+
provide: ConfigService,
32+
useValue: {
33+
getOrThrow: jest.fn().mockReturnValue('http://localhost:11434'),
34+
},
35+
},
36+
],
2037
imports: [StaticModule],
2138
}).compile();
2239

src/compare/libs/vlm/vlm.service.spec.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,21 @@ describe('VlmService', () => {
139139
expect(result.diffName).toBeNull();
140140
});
141141

142-
it('should parse config with defaults for invalid input', async () => {
142+
it.each([
143+
['empty string', '', DEFAULT_CONFIG],
144+
['invalid JSON', 'invalid', DEFAULT_CONFIG],
145+
['partial config', '{"model":"llava:7b"}', { model: 'llava:7b' }],
146+
[
147+
'full config',
148+
'{"model":"llava:13b","prompt":"Custom prompt","temperature":0.2}',
149+
{
150+
model: 'llava:13b',
151+
prompt: 'Custom prompt',
152+
temperature: 0.2,
153+
},
154+
],
155+
])('should parse config: %s', async (_, configJson, expected) => {
143156
const service = await initService({});
144-
145-
expect(service.parseConfig('')).toStrictEqual(DEFAULT_CONFIG);
146-
expect(service.parseConfig('invalid')).toStrictEqual(DEFAULT_CONFIG);
147-
expect(service.parseConfig('{"model":"llava:7b"}').model).toBe('llava:7b');
148-
expect(service.parseConfig('{"model":"llava:7b"}').prompt).toBe(DEFAULT_CONFIG.prompt);
157+
expect(service.parseConfig(configJson)).toEqual(expected);
149158
});
150159
});

0 commit comments

Comments
 (0)