Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

eval.test.ts 3.2 KB

You have to be logged in to leave a comment. Sign In
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
  1. import { getDb } from '../../src/database';
  2. import { getUserEmail } from '../../src/globalConfig/accounts';
  3. import { runDbMigrations } from '../../src/migrate';
  4. import Eval, { getSummaryOfLatestEvals } from '../../src/models/eval';
  5. import type { Prompt } from '../../src/types';
  6. import EvalFactory from '../factories/evalFactory';
  7. jest.mock('../../src/globalConfig/accounts', () => ({
  8. ...jest.requireActual('../../src/globalConfig/accounts'),
  9. getUserEmail: jest.fn(),
  10. }));
  11. describe('evaluator', () => {
  12. beforeAll(async () => {
  13. await runDbMigrations();
  14. });
  15. beforeEach(async () => {
  16. // Clear all tables before each test
  17. const db = getDb();
  18. // Delete related tables first
  19. await db.run('DELETE FROM eval_results');
  20. await db.run('DELETE FROM evals_to_datasets');
  21. await db.run('DELETE FROM evals_to_prompts');
  22. await db.run('DELETE FROM evals_to_tags');
  23. // Then delete from main table
  24. await db.run('DELETE FROM evals');
  25. });
  26. describe('summaryResults', () => {
  27. it('should return all evaluations', async () => {
  28. const eval1 = await EvalFactory.create();
  29. const eval2 = await EvalFactory.create();
  30. await EvalFactory.createOldResult();
  31. const evaluations = await getSummaryOfLatestEvals();
  32. expect(evaluations).toHaveLength(2);
  33. expect(evaluations).toContainEqual(
  34. expect.objectContaining({
  35. evalId: eval1.id,
  36. createdAt: eval1.createdAt,
  37. numTests: 2,
  38. }),
  39. );
  40. expect(evaluations).toContainEqual(
  41. expect.objectContaining({
  42. evalId: eval2.id,
  43. createdAt: eval2.createdAt,
  44. description: eval2.description || null,
  45. numTests: 2,
  46. }),
  47. );
  48. });
  49. });
  50. describe('delete', () => {
  51. it('should delete an evaluation', async () => {
  52. const eval1 = await EvalFactory.create();
  53. const eval_ = await Eval.findById(eval1.id);
  54. expect(eval_).toBeDefined();
  55. await eval1.delete();
  56. const eval_2 = await Eval.findById(eval1.id);
  57. expect(eval_2).toBeUndefined();
  58. });
  59. });
  60. describe('create', () => {
  61. it('should use provided author when available', async () => {
  62. const providedAuthor = 'provided@example.com';
  63. const config = { description: 'Test eval' };
  64. const renderedPrompts: Prompt[] = [
  65. { raw: 'Test prompt', display: 'Test prompt', label: 'Test label' },
  66. ];
  67. const evaluation = await Eval.create(config, renderedPrompts, { author: providedAuthor });
  68. expect(evaluation.author).toBe(providedAuthor);
  69. const persistedEval = await Eval.findById(evaluation.id);
  70. expect(persistedEval?.author).toBe(providedAuthor);
  71. });
  72. it('should use default author from getUserEmail when not provided', async () => {
  73. const mockEmail = 'default@example.com';
  74. jest.mocked(getUserEmail).mockReturnValue(mockEmail);
  75. const config = { description: 'Test eval' };
  76. const renderedPrompts: Prompt[] = [
  77. { raw: 'Test prompt', display: 'Test prompt', label: 'Test label' },
  78. ];
  79. const evaluation = await Eval.create(config, renderedPrompts);
  80. const persistedEval = await Eval.findById(evaluation.id);
  81. expect(persistedEval?.author).toBe(mockEmail);
  82. });
  83. });
  84. });
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...