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

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

Comments

Loading...