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 1.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
  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({ account: { email: 'test@example.com' } });
  16. expect(getUserEmail()).toBe('test@example.com');
  17. });
  18. it('should return null if no email is set in global config', () => {
  19. jest.mocked(readGlobalConfig).mockReturnValue({});
  20. expect(getUserEmail()).toBeNull();
  21. });
  22. });
  23. describe('setUserEmail', () => {
  24. it('should write the email to global config', () => {
  25. const writeGlobalConfigSpy = jest.mocked(writeGlobalConfigPartial);
  26. setUserEmail('test@example.com');
  27. expect(writeGlobalConfigSpy).toHaveBeenCalledWith({ account: { email: 'test@example.com' } });
  28. });
  29. });
  30. describe('getAuthor', () => {
  31. it('should return the author from environment variable', () => {
  32. process.env.PROMPTFOO_AUTHOR = 'envAuthor';
  33. expect(getAuthor()).toBe('envAuthor');
  34. });
  35. it('should return the email if environment variable is not set', () => {
  36. jest.mocked(readGlobalConfig).mockReturnValue({ account: { email: 'test@example.com' } });
  37. expect(getAuthor()).toBe('test@example.com');
  38. });
  39. it('should return null if neither environment variable nor email is set', () => {
  40. jest.mocked(readGlobalConfig).mockReturnValue({});
  41. expect(getAuthor()).toBeNull();
  42. });
  43. });
  44. });
Tip!

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

Comments

Loading...