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

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

Comments

Loading...