1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
- import { getUserEmail } from '../../src/globalConfig/accounts';
- import { runDbMigrations } from '../../src/migrate';
- import Eval, { getSummaryOfLatestEvals } from '../../src/models/eval';
- import type { Prompt } from '../../src/types';
- import EvalFactory from '../factories/evalFactory';
- jest.mock('../../src/globalConfig/accounts', () => ({
- ...jest.requireActual('../../src/globalConfig/accounts'),
- getUserEmail: jest.fn(),
- }));
- describe('evaluator', () => {
- beforeAll(async () => {
- await runDbMigrations();
- });
- describe('summaryResults', () => {
- it('should return all evaluations', async () => {
- const eval1 = await EvalFactory.create();
- const eval2 = await EvalFactory.create();
- await EvalFactory.createOldResult();
- const evaluations = await getSummaryOfLatestEvals();
- expect(evaluations).toHaveLength(2);
- expect(evaluations).toContainEqual(
- expect.objectContaining({
- evalId: eval1.id,
- createdAt: eval1.createdAt,
- numTests: 2,
- }),
- );
- expect(evaluations).toContainEqual(
- expect.objectContaining({
- evalId: eval2.id,
- createdAt: eval2.createdAt,
- description: eval2.description || null,
- numTests: 2,
- }),
- );
- });
- });
- describe('delete', () => {
- it('should delete an evaluation', async () => {
- const eval1 = await EvalFactory.create();
- const eval_ = await Eval.findById(eval1.id);
- expect(eval_).toBeDefined();
- await eval1.delete();
- const eval_2 = await Eval.findById(eval1.id);
- expect(eval_2).toBeUndefined();
- });
- });
- describe('create', () => {
- it('should use provided author when available', async () => {
- const providedAuthor = 'provided@example.com';
- const config = { description: 'Test eval' };
- const renderedPrompts: Prompt[] = [
- { raw: 'Test prompt', display: 'Test prompt', label: 'Test label' },
- ];
- const evaluation = await Eval.create(config, renderedPrompts, { author: providedAuthor });
- expect(evaluation.author).toBe(providedAuthor);
- const persistedEval = await Eval.findById(evaluation.id);
- expect(persistedEval?.author).toBe(providedAuthor);
- });
- it('should use default author from getUserEmail when not provided', async () => {
- const mockEmail = 'default@example.com';
- jest.mocked(getUserEmail).mockReturnValue(mockEmail);
- const config = { description: 'Test eval' };
- const renderedPrompts: Prompt[] = [
- { raw: 'Test prompt', display: 'Test prompt', label: 'Test label' },
- ];
- const evaluation = await Eval.create(config, renderedPrompts);
- const persistedEval = await Eval.findById(evaluation.id);
- expect(persistedEval?.author).toBe(mockEmail);
- });
- });
- });
|