@zohodesk/testinglibrary 0.0.46-n20-experimental → 0.0.47-n20-experimental
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.
- package/build/common/data-generator/steps/DataGenerator.spec.js +9 -9
- package/build/common/data-generator/steps/DataGeneratorStepsHelper.js +14 -13
- package/build/core/dataGenerator/DataGenerator.js +8 -12
- package/build/core/playwright/builtInFixtures/cacheLayer.js +0 -14
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/build/core/dataGenerator/CleanupTracker.js +0 -29
- package/build/core/dataGenerator/DataCleanup.js +0 -98
- package/zohodesk-testinglibrary-0.0.34-n20-experimental.tgz +0 -0
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { createBdd , test } from '@zohodesk/testinglibrary';
|
|
2
|
-
import { generateAndCacheTestData } from './DataGeneratorStepsHelper';
|
|
2
|
+
import { generateAndCacheTestData } from './DataGeneratorStepsHelper';
|
|
3
3
|
|
|
4
4
|
const { Given } = createBdd();
|
|
5
5
|
|
|
6
|
-
Given('generate a {string} entity {string} with generator {string}', async ({ page, context, i18N, cacheLayer,
|
|
7
|
-
await generateAndCacheTestData(executionContext, "template", generatorName, dataTable, cacheLayer, entityName
|
|
6
|
+
Given('generate a {string} entity {string} with generator {string}', async ({ page, context, i18N, cacheLayer, executionContext}, module, entityName, generatorName, dataTable) => {
|
|
7
|
+
await generateAndCacheTestData(executionContext, "template", generatorName, dataTable, cacheLayer, entityName);
|
|
8
8
|
});
|
|
9
9
|
|
|
10
|
-
Given('generate a {string} entity {string} with API {string}', async ({ page, context, i18N, cacheLayer,
|
|
11
|
-
await generateAndCacheTestData(executionContext, "API", operationId, dataTable, cacheLayer, entityName
|
|
10
|
+
Given('generate a {string} entity {string} with API {string}', async ({ page, context, i18N, cacheLayer, executionContext}, module, entityName, operationId, dataTable) => {
|
|
11
|
+
await generateAndCacheTestData(executionContext, "API", operationId, dataTable, cacheLayer, entityName);
|
|
12
12
|
});
|
|
13
|
-
Given('generate a {string} entity {string} with generator {string} using {string} profile', async ({ page, context, i18N, cacheLayer,
|
|
14
|
-
await generateAndCacheTestData(executionContext, "template", generatorName, dataTable, cacheLayer, entityName, profile
|
|
13
|
+
Given('generate a {string} entity {string} with generator {string} using {string} profile', async ({ page, context, i18N, cacheLayer, executionContext}, module, entityName, generatorName, profile, dataTable) => {
|
|
14
|
+
await generateAndCacheTestData(executionContext, "template", generatorName, dataTable, cacheLayer, entityName, profile);
|
|
15
15
|
});
|
|
16
16
|
|
|
17
|
-
Given('generate a {string} entity {string} with API {string} using {string} profile', async ({ page, context, i18N, cacheLayer,
|
|
18
|
-
await generateAndCacheTestData(executionContext, "API", operationId, dataTable, cacheLayer, entityName, profile
|
|
17
|
+
Given('generate a {string} entity {string} with API {string} using {string} profile', async ({ page, context, i18N, cacheLayer, executionContext}, module, entityName, operationId, profile, dataTable) => {
|
|
18
|
+
await generateAndCacheTestData(executionContext, "API", operationId, dataTable, cacheLayer, entityName, profile);
|
|
19
19
|
});
|
|
@@ -1,30 +1,31 @@
|
|
|
1
1
|
import { test } from '@zohodesk/testinglibrary';
|
|
2
2
|
import DataGenerator from '@zohodesk/testinglibrary/DataGenerator';
|
|
3
|
-
|
|
3
|
+
import {getUserForSelectedEditionAndProfile, getListOfActors} from '@zohodesk/testinglibrary/helpers'
|
|
4
4
|
|
|
5
5
|
const dataGenerator = new DataGenerator();
|
|
6
6
|
|
|
7
|
-
export async function generateAndCacheTestData(executionContext, type, identifier, dataTable, cacheLayer, entityName, profile = null
|
|
7
|
+
export async function generateAndCacheTestData(executionContext, type, identifier, dataTable, cacheLayer, entityName, profile = null) {
|
|
8
8
|
let actorInfo;
|
|
9
9
|
const testInfo = test.info();
|
|
10
10
|
const scenarioName = testInfo.title.split('/').pop() || 'Unknown Scenario';
|
|
11
11
|
|
|
12
12
|
if (profile) {
|
|
13
|
+
// Explicit profile requested — resolve that profile's credentials
|
|
13
14
|
const { edition, orgName: portal, beta } = executionContext.actorInfo;
|
|
14
15
|
actorInfo = await getUserForSelectedEditionAndProfile(edition, profile, beta, portal);
|
|
15
16
|
} else {
|
|
17
|
+
// Default — use current actor, fall back to org-level data-generator if profile has none
|
|
16
18
|
actorInfo = executionContext.actorInfo;
|
|
19
|
+
if (!actorInfo['data-generator']) {
|
|
20
|
+
const { edition, orgName: portal, beta } = actorInfo;
|
|
21
|
+
const actorsData = getListOfActors(beta);
|
|
22
|
+
const portalData = actorsData.editions[edition]?.find(e => e.orgName === portal);
|
|
23
|
+
if (portalData?.['data-generator']) {
|
|
24
|
+
actorInfo = { ...actorInfo, 'data-generator': portalData['data-generator'] };
|
|
25
|
+
}
|
|
26
|
+
}
|
|
17
27
|
}
|
|
18
|
-
|
|
19
|
-
const { response, generators } = await dataGenerator.generate(testInfo, actorInfo, type, identifier, scenarioName, dataTable ? dataTable.hashes() : []);
|
|
20
|
-
await cacheLayer.set(entityName, response.data);
|
|
21
28
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
entityName,
|
|
25
|
-
generators,
|
|
26
|
-
cachedData: response.data,
|
|
27
|
-
actorInfo
|
|
28
|
-
});
|
|
29
|
-
}
|
|
29
|
+
const { response } = await dataGenerator.generate(testInfo, actorInfo, type, identifier, scenarioName, dataTable ? dataTable.hashes() : []);
|
|
30
|
+
await cacheLayer.set(entityName, response.data);
|
|
30
31
|
}
|
|
@@ -9,9 +9,10 @@ var _path = _interopRequireDefault(require("path"));
|
|
|
9
9
|
var _fs = _interopRequireDefault(require("fs"));
|
|
10
10
|
var _logger = require("../../utils/logger");
|
|
11
11
|
var _DataGeneratorHelper = require("./DataGeneratorHelper");
|
|
12
|
-
var _helpers = require("@zohodesk/testinglibrary/helpers");
|
|
13
12
|
var _DataGeneratorError = require("./DataGeneratorError");
|
|
14
13
|
var _readConfigFile = require("../playwright/readConfigFile");
|
|
14
|
+
var _configConstants = _interopRequireDefault(require("../playwright/constants/configConstants"));
|
|
15
|
+
var _ConfigurationHelper = require("../playwright/configuration/ConfigurationHelper");
|
|
15
16
|
function _classPrivateMethodInitSpec(e, a) { _checkPrivateRedeclaration(e, a), a.add(e); }
|
|
16
17
|
function _classPrivateFieldInitSpec(e, t, a) { _checkPrivateRedeclaration(e, t), t.set(e, a); }
|
|
17
18
|
function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
|
|
@@ -31,7 +32,7 @@ class DataGenerator {
|
|
|
31
32
|
if (generatorType === 'API') {
|
|
32
33
|
generators = await _assertClassBrand(_DataGenerator_brand, this, _generateAPIGenerator).call(this, generatorName);
|
|
33
34
|
} else {
|
|
34
|
-
generators = await _assertClassBrand(_DataGenerator_brand, this, _getGenerator).call(this,
|
|
35
|
+
generators = await _assertClassBrand(_DataGenerator_brand, this, _getGenerator).call(this, generatorName);
|
|
35
36
|
}
|
|
36
37
|
const processedGenerators = await (0, _DataGeneratorHelper.processGenerator)(generators, dataTable);
|
|
37
38
|
const apiPayload = await _assertClassBrand(_DataGenerator_brand, this, _constructApiPayload).call(this, scenarioName, processedGenerators, actorInfo);
|
|
@@ -92,18 +93,13 @@ function _buildIndex(modulesRoot, pattern) {
|
|
|
92
93
|
_logger.Logger.log(_logger.Logger.INFO_TYPE, `Generator index built: ${index.size} generators found`);
|
|
93
94
|
return index;
|
|
94
95
|
}
|
|
95
|
-
function _getModulesRoot(
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
if (_path.default.basename(dir) === 'modules') return dir;
|
|
99
|
-
dir = _path.default.dirname(dir);
|
|
100
|
-
}
|
|
101
|
-
return null;
|
|
96
|
+
function _getModulesRoot() {
|
|
97
|
+
const stage = (0, _ConfigurationHelper.getRunStage)();
|
|
98
|
+
return _path.default.join(process.cwd(), _configConstants.default.TEST_SLICE_FOLDER, stage, 'modules');
|
|
102
99
|
}
|
|
103
|
-
async function _getGenerator(
|
|
100
|
+
async function _getGenerator(generatorName) {
|
|
104
101
|
if (!_classPrivateFieldGet(_generatorIndex, this)) {
|
|
105
|
-
const
|
|
106
|
-
const modulesRoot = _assertClassBrand(_DataGenerator_brand, this, _getModulesRoot).call(this, featureFilePath);
|
|
102
|
+
const modulesRoot = _assertClassBrand(_DataGenerator_brand, this, _getModulesRoot).call(this);
|
|
107
103
|
const {
|
|
108
104
|
generatorFilePattern: pattern = '*.generators.json'
|
|
109
105
|
} = (0, _readConfigFile.generateConfigFromFile)();
|
|
@@ -1,27 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.default = void 0;
|
|
8
|
-
var _CleanupTracker = _interopRequireDefault(require("../../dataGenerator/CleanupTracker"));
|
|
9
|
-
var _DataCleanup = _interopRequireDefault(require("../../dataGenerator/DataCleanup"));
|
|
10
7
|
const cacheMap = new Map();
|
|
11
8
|
var _default = exports.default = {
|
|
12
9
|
// eslint-disable-next-line no-empty-pattern
|
|
13
10
|
cacheLayer: async ({}, use) => {
|
|
14
11
|
await use(cacheMap);
|
|
15
|
-
},
|
|
16
|
-
// eslint-disable-next-line no-empty-pattern
|
|
17
|
-
cleanupTracker: async ({}, use) => {
|
|
18
|
-
const tracker = new _CleanupTracker.default();
|
|
19
|
-
await use(tracker);
|
|
20
|
-
const entries = tracker.getEntries();
|
|
21
|
-
if (entries.length > 0) {
|
|
22
|
-
const cleanup = new _DataCleanup.default();
|
|
23
|
-
await cleanup.cleanup(entries);
|
|
24
|
-
}
|
|
25
|
-
tracker.clear();
|
|
26
12
|
}
|
|
27
13
|
};
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zohodesk/testinglibrary",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.47-n20-experimental",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@zohodesk/testinglibrary",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.47-n20-experimental",
|
|
10
10
|
"hasInstallScript": true,
|
|
11
11
|
"license": "ISC",
|
|
12
12
|
"dependencies": {
|
package/package.json
CHANGED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
class CleanupTracker {
|
|
8
|
-
#entries = [];
|
|
9
|
-
track({
|
|
10
|
-
entityName,
|
|
11
|
-
generators,
|
|
12
|
-
cachedData,
|
|
13
|
-
actorInfo
|
|
14
|
-
}) {
|
|
15
|
-
this.#entries.push({
|
|
16
|
-
entityName,
|
|
17
|
-
generators,
|
|
18
|
-
cachedData,
|
|
19
|
-
actorInfo
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
getEntries() {
|
|
23
|
-
return [...this.#entries];
|
|
24
|
-
}
|
|
25
|
-
clear() {
|
|
26
|
-
this.#entries = [];
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
var _default = exports.default = CleanupTracker;
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.default = void 0;
|
|
8
|
-
var _jsonpath = _interopRequireDefault(require("jsonpath"));
|
|
9
|
-
var _logger = require("../../utils/logger");
|
|
10
|
-
var _DataGeneratorHelper = require("./DataGeneratorHelper");
|
|
11
|
-
function _classPrivateMethodInitSpec(e, a) { _checkPrivateRedeclaration(e, a), a.add(e); }
|
|
12
|
-
function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
|
|
13
|
-
function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
|
|
14
|
-
var _DataCleanup_brand = /*#__PURE__*/new WeakSet();
|
|
15
|
-
class DataCleanup {
|
|
16
|
-
constructor() {
|
|
17
|
-
_classPrivateMethodInitSpec(this, _DataCleanup_brand);
|
|
18
|
-
}
|
|
19
|
-
async cleanup(entries) {
|
|
20
|
-
for (const entry of [...entries].reverse()) {
|
|
21
|
-
for (const step of [...entry.generators].reverse()) {
|
|
22
|
-
if (!step.cleanup) continue;
|
|
23
|
-
try {
|
|
24
|
-
const entityId = _assertClassBrand(_DataCleanup_brand, this, _extractId).call(this, entry.cachedData, step.cleanup.idPath);
|
|
25
|
-
if (step.cleanup.type === 'oas') {
|
|
26
|
-
await _assertClassBrand(_DataCleanup_brand, this, _cleanupViaOAS).call(this, step.cleanup, entityId, entry.actorInfo);
|
|
27
|
-
} else if (step.cleanup.type === 'api') {
|
|
28
|
-
await _assertClassBrand(_DataCleanup_brand, this, _cleanupViaAPI).call(this, step.cleanup, entityId, entry.actorInfo);
|
|
29
|
-
}
|
|
30
|
-
_logger.Logger.log(_logger.Logger.SUCCESS_TYPE, `Cleanup: ${step.cleanup.method || 'delete'} ${step.name} (ID: ${entityId})`);
|
|
31
|
-
} catch (err) {
|
|
32
|
-
_logger.Logger.log(_logger.Logger.INFO_TYPE, `Cleanup warning for ${step.name}: ${err.message}`);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
function _extractId(cachedData, idPath) {
|
|
39
|
-
if (!cachedData || !idPath) {
|
|
40
|
-
throw new Error('Missing cached data or idPath for cleanup');
|
|
41
|
-
}
|
|
42
|
-
const result = _jsonpath.default.query(cachedData, idPath);
|
|
43
|
-
if (result.length === 0) {
|
|
44
|
-
throw new Error(`Could not extract ID using path "${idPath}" from cached data`);
|
|
45
|
-
}
|
|
46
|
-
return result[0];
|
|
47
|
-
}
|
|
48
|
-
async function _cleanupViaOAS(cleanupConfig, entityId, actorInfo) {
|
|
49
|
-
const dataGeneratorObj = actorInfo['data-generator'];
|
|
50
|
-
if (!dataGeneratorObj) {
|
|
51
|
-
throw new Error(`Data Generator configuration is missing for cleanup`);
|
|
52
|
-
}
|
|
53
|
-
const deleteGenerator = [{
|
|
54
|
-
type: 'dynamic',
|
|
55
|
-
generatorOperationId: cleanupConfig.operationId,
|
|
56
|
-
dataPath: '$.response.body:$',
|
|
57
|
-
name: cleanupConfig.operationId,
|
|
58
|
-
params: {
|
|
59
|
-
id: String(entityId)
|
|
60
|
-
}
|
|
61
|
-
}];
|
|
62
|
-
const apiPayload = {
|
|
63
|
-
scenario_name: 'cleanup',
|
|
64
|
-
data_generation_templates: deleteGenerator,
|
|
65
|
-
...dataGeneratorObj
|
|
66
|
-
};
|
|
67
|
-
const account = apiPayload.account;
|
|
68
|
-
if (account) {
|
|
69
|
-
account.email = actorInfo.email;
|
|
70
|
-
account.password = actorInfo.password;
|
|
71
|
-
}
|
|
72
|
-
const environmentDetails = apiPayload.environmentDetails || {};
|
|
73
|
-
environmentDetails.iam_url = process.env.DG_IAM_DOMAIN;
|
|
74
|
-
const domainUrl = new URL(process.env.domain);
|
|
75
|
-
environmentDetails.host = domainUrl.origin;
|
|
76
|
-
apiPayload.environmentDetails = environmentDetails;
|
|
77
|
-
await (0, _DataGeneratorHelper.makeRequest)(process.env.DG_SERVICE_DOMAIN + process.env.DG_SERVICE_API_PATH, apiPayload);
|
|
78
|
-
}
|
|
79
|
-
async function _cleanupViaAPI(cleanupConfig, entityId, actorInfo) {
|
|
80
|
-
const domainUrl = new URL(process.env.domain);
|
|
81
|
-
const apiPath = cleanupConfig.apiPath.replace('{id}', entityId);
|
|
82
|
-
const url = `${domainUrl.origin}${apiPath}`;
|
|
83
|
-
const fetchOptions = {
|
|
84
|
-
method: cleanupConfig.method,
|
|
85
|
-
headers: {
|
|
86
|
-
'Content-Type': 'application/json'
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
if (cleanupConfig.body) {
|
|
90
|
-
fetchOptions.body = JSON.stringify(cleanupConfig.body);
|
|
91
|
-
}
|
|
92
|
-
const response = await fetch(url, fetchOptions);
|
|
93
|
-
if (!response.ok) {
|
|
94
|
-
const errorBody = await response.text();
|
|
95
|
-
throw new Error(`API cleanup failed: ${cleanupConfig.method} ${apiPath} - status: ${response.status}, body: ${errorBody}`);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
var _default = exports.default = DataCleanup;
|
|
Binary file
|