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

share.test.ts 2.7 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
  1. import request from 'supertest';
  2. import { runDbMigrations } from '../../src/migrate';
  3. import Eval from '../../src/models/eval';
  4. import { createApp } from '../../src/server/server';
  5. import { deleteAllEvals } from '../../src/util';
  6. import results_v3 from './v3evalToShare.json';
  7. import results_v4 from './v4evalToShare.json';
  8. describe('share', () => {
  9. let app: ReturnType<typeof createApp>;
  10. beforeAll(async () => {
  11. await runDbMigrations();
  12. });
  13. beforeEach(async () => {
  14. app = createApp();
  15. await deleteAllEvals();
  16. });
  17. it('should accept a version 3 results file', async () => {
  18. const res = await request(app).post('/api/eval').send(results_v3).timeout(5000);
  19. expect(res.status).toBe(200);
  20. expect(res.body).toHaveProperty('id');
  21. const eval_ = await Eval.findById(res.body.id as string);
  22. expect(eval_).not.toBeNull();
  23. expect(eval_?.version()).toBe(3);
  24. const results = await eval_?.getResults();
  25. expect(results).toBeDefined();
  26. expect(Array.isArray(results)).toBe(true);
  27. expect(results).toHaveLength(8);
  28. });
  29. it('should accept a new eval', async () => {
  30. const res = await request(app).post('/api/eval').send(results_v4).timeout(5000);
  31. expect(res.status).toBe(200);
  32. expect(res.body).toHaveProperty('id');
  33. const eval_ = await Eval.findById(res.body.id as string);
  34. expect(eval_).not.toBeNull();
  35. expect(eval_?.version()).toBe(4);
  36. const results = await eval_?.getResults();
  37. expect(results).toBeDefined();
  38. expect(Array.isArray(results)).toBe(true);
  39. expect(results).toHaveLength(8);
  40. });
  41. describe('error handling', () => {
  42. it('should handle empty request body', async () => {
  43. const res = await request(app).post('/api/eval').send({}).timeout(5000);
  44. expect(res.status).toBe(500);
  45. expect(res.body).toHaveProperty('error');
  46. expect(res.body.error).toBe('Failed to write eval to database');
  47. });
  48. it('should handle invalid v3 eval data', async () => {
  49. const res = await request(app)
  50. .post('/api/eval')
  51. .send({
  52. data: {
  53. results: null,
  54. config: null,
  55. },
  56. })
  57. .timeout(5000);
  58. expect(res.status).toBe(500);
  59. expect(res.body).toHaveProperty('error');
  60. expect(res.body.error).toBe('Failed to write eval to database');
  61. });
  62. it('should handle database errors', async () => {
  63. const res = await request(app)
  64. .post('/api/eval')
  65. .send({
  66. config: {},
  67. results: [],
  68. })
  69. .timeout(5000);
  70. expect(res.status).toBe(500);
  71. expect(res.body).toHaveProperty('error');
  72. expect(res.body.error).toBe('Failed to write eval to database');
  73. });
  74. });
  75. });
Tip!

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

Comments

Loading...