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

account.test.ts 2.0 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
  1. import { getUserEmail, setUserEmail, getAuthor } from '../src/globalConfig/accounts';
  2. import { readGlobalConfig, writeGlobalConfigPartial } from '../src/globalConfig/globalConfig';
  3. jest.mock('../src/globalConfig/globalConfig', () => ({
  4. writeGlobalConfig: jest.fn(),
  5. readGlobalConfig: jest.fn(),
  6. writeGlobalConfigPartial: jest.fn(),
  7. }));
  8. describe('accounts module', () => {
  9. beforeEach(() => {
  10. delete process.env.PROMPTFOO_AUTHOR;
  11. jest.resetModules();
  12. });
  13. describe('getUserEmail', () => {
  14. it('should return the email from global config', () => {
  15. jest.mocked(readGlobalConfig).mockReturnValue({
  16. id: 'test-id',
  17. account: { email: 'test@example.com' },
  18. });
  19. expect(getUserEmail()).toBe('test@example.com');
  20. });
  21. it('should return null if no email is set in global config', () => {
  22. jest.mocked(readGlobalConfig).mockReturnValue({
  23. id: 'test-id',
  24. });
  25. expect(getUserEmail()).toBeNull();
  26. });
  27. });
  28. describe('setUserEmail', () => {
  29. it('should write the email to global config', () => {
  30. const writeGlobalConfigSpy = jest.mocked(writeGlobalConfigPartial);
  31. setUserEmail('test@example.com');
  32. expect(writeGlobalConfigSpy).toHaveBeenCalledWith({ account: { email: 'test@example.com' } });
  33. });
  34. });
  35. describe('getAuthor', () => {
  36. it('should return the author from environment variable', () => {
  37. process.env.PROMPTFOO_AUTHOR = 'envAuthor';
  38. expect(getAuthor()).toBe('envAuthor');
  39. });
  40. it('should return the email if environment variable is not set', () => {
  41. jest.mocked(readGlobalConfig).mockReturnValue({
  42. id: 'test-id',
  43. account: { email: 'test@example.com' },
  44. });
  45. expect(getAuthor()).toBe('test@example.com');
  46. });
  47. it('should return null if neither environment variable nor email is set', () => {
  48. jest.mocked(readGlobalConfig).mockReturnValue({
  49. id: 'test-id',
  50. });
  51. expect(getAuthor()).toBeNull();
  52. });
  53. });
  54. });
Tip!

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

Comments

Loading...