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.3 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
  1. import { cloudConfig } from '../src/globalConfig/cloud';
  2. import type Eval from '../src/models/eval';
  3. import { stripAuthFromUrl, createShareableUrl } from '../src/share';
  4. jest.mock('../src/logger');
  5. jest.mock('../src/globalConfig/cloud');
  6. jest.mock('../src/fetch', () => ({
  7. fetchWithProxy: jest.fn().mockResolvedValue({
  8. ok: true,
  9. json: jest.fn().mockResolvedValue({ id: 'mock-eval-id' }),
  10. }),
  11. }));
  12. describe('stripAuthFromUrl', () => {
  13. it('removes username and password from URL', () => {
  14. const input = 'https://user:pass@example.com/path?query=value#hash';
  15. const expected = 'https://example.com/path?query=value#hash';
  16. expect(stripAuthFromUrl(input)).toBe(expected);
  17. });
  18. it('handles URLs without auth info', () => {
  19. const input = 'https://example.com/path?query=value#hash';
  20. expect(stripAuthFromUrl(input)).toBe(input);
  21. });
  22. it('handles URLs with only username', () => {
  23. const input = 'https://user@example.com/path';
  24. const expected = 'https://example.com/path';
  25. expect(stripAuthFromUrl(input)).toBe(expected);
  26. });
  27. it('handles URLs with special characters in auth', () => {
  28. const input = 'https://user%40:p@ss@example.com/path';
  29. const expected = 'https://example.com/path';
  30. expect(stripAuthFromUrl(input)).toBe(expected);
  31. });
  32. it('returns original string for invalid URLs', () => {
  33. const input = 'not a valid url';
  34. expect(stripAuthFromUrl(input)).toBe(input);
  35. });
  36. it('handles URLs with IP addresses', () => {
  37. const input = 'http://user:pass@192.168.1.1:8080/path';
  38. const expected = 'http://192.168.1.1:8080/path';
  39. expect(stripAuthFromUrl(input)).toBe(expected);
  40. });
  41. });
  42. describe('createShareableUrl', () => {
  43. it('creates correct URL for cloud config', async () => {
  44. jest.mocked(cloudConfig.isEnabled).mockReturnValue(true);
  45. jest.mocked(cloudConfig.getAppUrl).mockReturnValue('https://app.example.com');
  46. jest.mocked(cloudConfig.getApiHost).mockReturnValue('https://api.example.com');
  47. jest.mocked(cloudConfig.getApiKey).mockReturnValue('mock-api-key');
  48. const mockEval: Partial<Eval> = {
  49. config: {},
  50. useOldResults: jest.fn().mockReturnValue(false),
  51. loadResults: jest.fn().mockResolvedValue(undefined),
  52. };
  53. const result = await createShareableUrl(mockEval as Eval);
  54. expect(result).toBe('https://app.example.com/eval/mock-eval-id');
  55. });
  56. });
Tip!

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

Comments

Loading...