@zohodesk/testinglibrary 4.1.3 → 4.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (24) hide show
  1. package/README.md +14 -0
  2. package/build/common/data-generator/steps/DataGenerator.spec.js +5 -5
  3. package/build/common/data-generator/steps/DataGeneratorStepsHelper.js +2 -2
  4. package/build/core/dataGenerator/DataGenerator.js +9 -4
  5. package/build/core/dataGenerator/DataGeneratorError.js +12 -2
  6. package/build/core/dataGenerator/authenticator/Authenticator.js +37 -0
  7. package/build/core/dataGenerator/authenticator/CookieAuthenticator.js +48 -0
  8. package/build/core/dataGenerator/authenticator/JWTauthenticator.js +64 -0
  9. package/build/core/dataGenerator/authenticator/OAuthAuthenticator.js +26 -0
  10. package/build/core/dataGenerator/authenticator/OrgOAuthAuthenticator.js +26 -0
  11. package/build/core/dataGenerator/authenticator/cookieAuthConfig.js +11 -0
  12. package/build/core/playwright/constants/reporterConstants.js +4 -0
  13. package/build/core/playwright/setup/ProjectConfiguration.js +3 -2
  14. package/build/core/playwright/setup/config-creator.js +3 -2
  15. package/build/core/playwright/setup/custom-reporter.js +23 -0
  16. package/build/test/core/dataGenerator/authenticator/__tests__/Authenticator.test.js +88 -0
  17. package/build/test/core/dataGenerator/authenticator/__tests__/JWTauthenticator.test.js +129 -0
  18. package/build/test/core/dataGenerator/authenticator/__tests__/OAuthAuthenticator.test.js +39 -0
  19. package/build/test/core/dataGenerator/authenticator/__tests__/OrgOAuthAuthenticator.test.js +39 -0
  20. package/build/test/core/playwright/__tests__/validateFeature.test.js +4 -1
  21. package/build/test/core/playwright/runner/__tests__/RunnerHelper.test.js +3 -0
  22. package/build/test/core/playwright/runner/__tests__/SpawnRunner.test.js +3 -0
  23. package/npm-shrinkwrap.json +146 -103
  24. package/package.json +1 -1
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _JWTauthenticator = _interopRequireDefault(require("../../../../../../src/core/dataGenerator/authenticator/JWTauthenticator"));
5
+ describe('JWTauthenticator', () => {
6
+ let fetchMock;
7
+ beforeEach(() => {
8
+ fetchMock = jest.fn();
9
+ global.fetch = fetchMock;
10
+ process.env.DG_JWT_AUTH_URL = 'https://jwt-auth.example.com';
11
+ process.env.DG_DOMAIN_URL = 'https://domain.example.com';
12
+ process.env.DG_JWT_AUTHENTICATOR_API = 'https://authenticator.example.com/jwtToken';
13
+ });
14
+ afterEach(() => {
15
+ delete global.fetch;
16
+ delete process.env.DG_JWT_AUTH_URL;
17
+ delete process.env.DG_DOMAIN_URL;
18
+ delete process.env.DG_JWT_AUTHENTICATOR_API;
19
+ });
20
+ it('should throw when jwt-oauth config is missing', async () => {
21
+ const jwtAuthenticator = new _JWTauthenticator.default();
22
+ const apiPayload = {
23
+ account: {}
24
+ };
25
+ const actorInfo = {
26
+ email: 'user@example.com',
27
+ 'data-generator': {
28
+ account: {}
29
+ }
30
+ };
31
+ await expect(jwtAuthenticator.constructPayload(apiPayload, actorInfo)).rejects.toThrow('JWT authentication failed: "jwt-oauth" is missing in actor configuration');
32
+ expect(fetchMock).not.toHaveBeenCalled();
33
+ });
34
+ it('should fetch jwt access token and set it in authHeaders', async () => {
35
+ fetchMock.mockResolvedValue({
36
+ ok: true,
37
+ json: async () => ({
38
+ access_token: 'access-token-123'
39
+ })
40
+ });
41
+ const jwtAuthenticator = new _JWTauthenticator.default();
42
+ const apiPayload = {
43
+ account: {}
44
+ };
45
+ const actorInfo = {
46
+ email: 'user.one@example.com',
47
+ 'data-generator': {
48
+ account: {
49
+ 'jwt-oauth': {
50
+ jwt_secret: 'jwt-secret',
51
+ response_type: 'token',
52
+ client_id: '12345.client-id',
53
+ token_url: 'https://token.example.com/12345/oauth'
54
+ }
55
+ }
56
+ }
57
+ };
58
+ const result = await jwtAuthenticator.constructPayload(apiPayload, actorInfo);
59
+ expect(fetchMock).toHaveBeenCalledTimes(1);
60
+ expect(fetchMock).toHaveBeenCalledWith('https://authenticator.example.com/jwtToken', expect.objectContaining({
61
+ method: 'POST',
62
+ headers: {
63
+ 'Content-Type': 'application/json'
64
+ }
65
+ }));
66
+ const requestBody = JSON.parse(fetchMock.mock.calls[0][1].body);
67
+ expect(requestBody).toEqual(expect.objectContaining({
68
+ user_token: encodeURIComponent('user.one@example.com'),
69
+ jwt_secret: 'jwt-secret',
70
+ jwt_auth_url: 'https://jwt-auth.example.com',
71
+ response_type: 'token',
72
+ client_id: '12345.client-id',
73
+ token_url: 'https://token.example.com/12345/oauth',
74
+ domain_url: 'https://domain.example.com'
75
+ }));
76
+ expect(result.account.authHeaders.Authorization).toBe('Zoho-oauthtoken access-token-123');
77
+ });
78
+ it('should throw a descriptive error when authenticator API returns non-ok response', async () => {
79
+ fetchMock.mockResolvedValue({
80
+ ok: false,
81
+ status: 500,
82
+ text: async () => 'internal error'
83
+ });
84
+ const jwtAuthenticator = new _JWTauthenticator.default();
85
+ const apiPayload = {
86
+ account: {}
87
+ };
88
+ const actorInfo = {
89
+ email: 'user@example.com',
90
+ 'data-generator': {
91
+ account: {
92
+ 'jwt-oauth': {
93
+ jwt_secret: 'jwt-secret',
94
+ response_type: 'token',
95
+ client_id: '12345.client-id',
96
+ token_url: 'https://token.example.com/12345/oauth'
97
+ }
98
+ }
99
+ }
100
+ };
101
+ await expect(jwtAuthenticator.constructPayload(apiPayload, actorInfo)).rejects.toThrow('JWT authenticator error! status: 500, body: internal error');
102
+ });
103
+ it('should throw when authenticator response has no access_token', async () => {
104
+ fetchMock.mockResolvedValue({
105
+ ok: true,
106
+ json: async () => ({
107
+ token_type: 'Bearer'
108
+ })
109
+ });
110
+ const jwtAuthenticator = new _JWTauthenticator.default();
111
+ const apiPayload = {
112
+ account: {}
113
+ };
114
+ const actorInfo = {
115
+ email: 'user@example.com',
116
+ 'data-generator': {
117
+ account: {
118
+ 'jwt-oauth': {
119
+ jwt_secret: 'jwt-secret',
120
+ response_type: 'token',
121
+ client_id: '12345.client-id',
122
+ token_url: 'https://token.example.com/12345/oauth'
123
+ }
124
+ }
125
+ }
126
+ };
127
+ await expect(jwtAuthenticator.constructPayload(apiPayload, actorInfo)).rejects.toThrow('JWT authenticator did not return access_token');
128
+ });
129
+ });
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _OAuthAuthenticator = _interopRequireDefault(require("../../../../../../src/core/dataGenerator/authenticator/OAuthAuthenticator"));
5
+ describe('OAuthAuthenticator', () => {
6
+ it('should assign oauth2 from actor info into payload account', async () => {
7
+ const oauthAuthenticator = new _OAuthAuthenticator.default();
8
+ const apiPayload = {
9
+ account: {}
10
+ };
11
+ const actorInfo = {
12
+ 'data-generator': {
13
+ account: {
14
+ oauth2: {
15
+ client_id: 'new-client',
16
+ scope: 'tickets.read'
17
+ }
18
+ }
19
+ }
20
+ };
21
+ const result = await oauthAuthenticator.constructPayload(apiPayload, actorInfo);
22
+ expect(result.account.oauth2).toEqual({
23
+ client_id: 'new-client',
24
+ scope: 'tickets.read'
25
+ });
26
+ });
27
+ it('should throw when oauth2 is absent in actor configuration', async () => {
28
+ const oauthAuthenticator = new _OAuthAuthenticator.default();
29
+ const apiPayload = {
30
+ account: {}
31
+ };
32
+ const actorInfo = {
33
+ 'data-generator': {
34
+ account: {}
35
+ }
36
+ };
37
+ await expect(oauthAuthenticator.constructPayload(apiPayload, actorInfo)).rejects.toThrow('OAuth2 authentication failed: "oauth2" is missing in actor configuration');
38
+ });
39
+ });
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _OrgOAuthAuthenticator = _interopRequireDefault(require("../../../../../../src/core/dataGenerator/authenticator/OrgOAuthAuthenticator"));
5
+ describe('OrgOAuthAuthenticator', () => {
6
+ it('should assign org_oauth from actor info into payload account', async () => {
7
+ const orgOAuthAuthenticator = new _OrgOAuthAuthenticator.default();
8
+ const apiPayload = {
9
+ account: {}
10
+ };
11
+ const actorInfo = {
12
+ 'data-generator': {
13
+ account: {
14
+ org_oauth: {
15
+ org_id: 'org-1001',
16
+ region: 'us'
17
+ }
18
+ }
19
+ }
20
+ };
21
+ const result = await orgOAuthAuthenticator.constructPayload(apiPayload, actorInfo);
22
+ expect(result.account.org_oauth).toEqual({
23
+ org_id: 'org-1001',
24
+ region: 'us'
25
+ });
26
+ });
27
+ it('should throw when org_oauth is absent in actor configuration', async () => {
28
+ const orgOAuthAuthenticator = new _OrgOAuthAuthenticator.default();
29
+ const apiPayload = {
30
+ account: {}
31
+ };
32
+ const actorInfo = {
33
+ 'data-generator': {
34
+ account: {}
35
+ }
36
+ };
37
+ await expect(orgOAuthAuthenticator.constructPayload(apiPayload, actorInfo)).rejects.toThrow('OrgOAuth authentication failed: "org_oauth" is missing in actor configuration');
38
+ });
39
+ });
@@ -13,7 +13,10 @@ jest.mock('../../../../core/playwright/helpers/parseUserArgs', () => ({
13
13
  }));
14
14
  jest.mock('../../../../core/playwright/readConfigFile');
15
15
  jest.mock('../../../../core/playwright/tagProcessor');
16
- jest.mock('../../../../core/playwright/test-runner');
16
+ jest.mock('../../../../core/playwright/test-runner', () => ({
17
+ __esModule: true,
18
+ runPreprocessing: jest.fn()
19
+ }));
17
20
  jest.mock('../../../../utils/logger', () => ({
18
21
  __esModule: true,
19
22
  Logger: {
@@ -3,6 +3,9 @@
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
4
  var _RunnerHelper = _interopRequireDefault(require("../../../../../core/playwright/runner/RunnerHelper"));
5
5
  var _SpawnRunner = _interopRequireDefault(require("../../../../../core/playwright/runner/SpawnRunner"));
6
+ jest.mock('../../../../../core/playwright/setup/config-utils', () => ({
7
+ getBrowsersList: jest.fn().mockReturnValue([])
8
+ }));
6
9
  describe('RunnerHelper', () => {
7
10
  describe('createRunner', () => {
8
11
  it('should throw error on invalid runner type', () => {
@@ -6,6 +6,9 @@ var _Runner = _interopRequireDefault(require("../../../../../core/playwright/run
6
6
  var _Configuration = _interopRequireDefault(require("../../../../../core/playwright/configuration/Configuration"));
7
7
  jest.mock('child_process');
8
8
  jest.mock('../../../../../utils/logger');
9
+ jest.mock('../../../../../core/playwright/setup/config-utils', () => ({
10
+ getBrowsersList: jest.fn().mockReturnValue([])
11
+ }));
9
12
  describe('SpawnRunner', () => {
10
13
  let spawnRunner;
11
14
  const runnerObj = new _Runner.default();