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

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

Comments

Loading...