@amanat-qa/utils-backend 5.1.0 → 5.1.2

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.
@@ -1,50 +0,0 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const YAML = require('js-yaml');
4
-
5
- const projectDirectory = path.join(__dirname, '../../../../../');
6
- const specDirectory = path.join(projectDirectory, './test/tests/specs');
7
-
8
- const specFiles = fs.readdirSync(specDirectory);
9
- const jobs = specFiles.map((spec, index) => ({
10
- [`API tests ${index + 1}`]: {
11
- image: 'node:latest',
12
- stage: 'test',
13
- variables: {
14
- SPEC_PATTERN: index + 1,
15
- },
16
- only: [
17
- 'dev',
18
- ],
19
- tags: [
20
- 'k8s',
21
- ],
22
- before_script: [
23
- // eslint-disable-next-line no-template-curly-in-string
24
- 'echo "${ENV_TEST}" | tr -d "\r" > ./.env.test',
25
- 'apt-get update && apt-get install -y default-jre',
26
- 'npm install',
27
- ],
28
- script: [
29
- 'npm run lint',
30
- 'npm run test:split',
31
- ],
32
- artifacts: {
33
- when: 'always',
34
- expire_in: '1 month',
35
- paths: [
36
- 'test/artifacts',
37
- 'test/resources/data/configData.json',
38
- ],
39
- },
40
- },
41
- }));
42
-
43
- const gitlabCIConfig = {
44
- ...Object.assign({}, ...jobs),
45
- };
46
-
47
- fs.writeFileSync(
48
- path.join(projectDirectory, '.split-config.yml'),
49
- YAML.dump(gitlabCIConfig),
50
- );
@@ -1,8 +0,0 @@
1
- const DateFormats = Object.freeze({
2
- DMY: 'DD.MM.YYYY',
3
- YMD: 'YYYY-MM-DD',
4
- MDY: 'MM.DD.YYYY',
5
- YMDHms: 'YYYY-MM-DD[T]HH:mm:ss',
6
- });
7
-
8
- module.exports = DateFormats;
package/src/log/logger.js DELETED
@@ -1,57 +0,0 @@
1
- const path = require('path');
2
- const moment = require('moment');
3
- const { createWriteStream } = require('fs');
4
- const allureMocha = require('allure-mocha/runtime');
5
- const JSONLoader = require('../data/JSONLoader');
6
-
7
- const filePath = path.join(path.resolve(), 'test', 'artifacts', 'log.txt');
8
- const timeList = [];
9
- const logList = [];
10
-
11
- class Logger {
12
- static #title;
13
-
14
- static log(step, title) {
15
- logList.push(` ${step}`);
16
- const timeStamp = moment().format().slice(0, 19).replace('T', ' ');
17
- timeList.push(`${timeStamp}`);
18
- if (title) this.#title = title;
19
- allureMocha.allure.logStep(`${timeStamp} ${step}`);
20
- if (!JSONLoader.configData.parallel) {
21
- const stream = createWriteStream(filePath, { flags: 'a', autoClose: true });
22
- if (!title) stream.write(`${timeStamp} ${step}\n`);
23
- this.hideLogBodies(step);
24
- }
25
- }
26
-
27
- static hideLogBodies(step) {
28
- if (JSONLoader.configData.hiddenLogBodies && step.includes('[req]')) {
29
- const words = step.split(' ');
30
- const firstPart = words.slice(0, 3).join(' ');
31
- const secondPart = words.slice(words.length - 2).join(' ');
32
- console.log(` ${firstPart} ${secondPart}`); // eslint-disable-line no-console
33
- } else {
34
- console.log(` ${step}`); // eslint-disable-line no-console
35
- }
36
- }
37
-
38
- static logParallel() {
39
- logList.forEach((step) => this.hideLogBodies(step.trim()));
40
- }
41
-
42
- static logToFileParallel() {
43
- const zip = (a, b) => a.map((k, i) => [k, b[i]]);
44
- const summaryList = zip(timeList, logList);
45
- summaryList.shift();
46
- const fileName = filePath.split('/')
47
- .map((part, index, array) => (index === array.length - 1 ? `${this.#title}.${part}` : part))
48
- .join('/');
49
- const stream = createWriteStream(fileName, { flags: 'a', autoClose: true });
50
- summaryList.forEach((logString) => logString.forEach((logSubString, index) => {
51
- /* eslint no-unused-expressions: ["error", { "allowTernary": true }] */
52
- index % 2 !== 0 ? stream.write(`${logSubString}\n`) : stream.write(`${logSubString}`);
53
- }));
54
- }
55
- }
56
-
57
- module.exports = Logger;
@@ -1,106 +0,0 @@
1
- const TimeUtils = require('../time/timeUtils');
2
-
3
- class Randomizer {
4
- static getRandomString(
5
- hasLowerCase = false,
6
- hasUpperCase = false,
7
- hasNumber = false,
8
- hasCyrillic = false,
9
- chosenLetter = false,
10
- minLength = 1,
11
- maxLength = 10,
12
- ) {
13
- const upperCaseLetters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
14
- const lowerCaseLetters = 'abcdefghijklmnopqrstuvwxyz';
15
- const numbers = '0123456789';
16
- const cyrillicLetters = 'абвгдеёжзийклмнопрстуфхцчшщъыьэюя';
17
-
18
- const length = this.getRandomInteger(maxLength, minLength);
19
-
20
- let randomString = '';
21
- if (chosenLetter) randomString += chosenLetter;
22
-
23
- let requiredCharacters = '';
24
- if (hasLowerCase) {
25
- requiredCharacters
26
- += lowerCaseLetters.charAt(Math.floor(Math.random() * lowerCaseLetters.length));
27
- }
28
-
29
- if (hasUpperCase) {
30
- requiredCharacters
31
- += upperCaseLetters.charAt(Math.floor(Math.random() * upperCaseLetters.length));
32
- }
33
-
34
- if (hasNumber) {
35
- requiredCharacters
36
- += numbers.charAt(Math.floor(Math.random() * numbers.length));
37
- }
38
-
39
- if (hasCyrillic) {
40
- requiredCharacters
41
- += cyrillicLetters.charAt(Math.floor(Math.random() * cyrillicLetters.length));
42
- }
43
-
44
- randomString += requiredCharacters;
45
-
46
- const characters = (hasLowerCase ? lowerCaseLetters : '')
47
- + (hasUpperCase ? upperCaseLetters : '')
48
- + (hasNumber ? numbers : '')
49
- + (hasCyrillic ? cyrillicLetters : '');
50
- const charactersLength = characters.length;
51
- const randomLength = length - randomString.length;
52
-
53
- for (let i = 0; i < randomLength; i += 1) {
54
- randomString += characters.charAt(Math.floor(Math.random() * charactersLength));
55
- }
56
-
57
- return this.stringShuffler(randomString);
58
- }
59
-
60
- static stringShuffler(inputString) {
61
- const array = inputString.split('');
62
- let currentIndex = array.length;
63
- let temporaryValue;
64
- let randomIndex;
65
- while (currentIndex !== 0) {
66
- randomIndex = Math.floor(Math.random() * currentIndex);
67
- currentIndex -= 1;
68
- temporaryValue = array[currentIndex];
69
- array[currentIndex] = array[randomIndex];
70
- array[randomIndex] = temporaryValue;
71
- }
72
-
73
- return array.join('');
74
- }
75
-
76
- static getRandomInteger(max = 9, min = 0) {
77
- return Math.floor(Math.random() * (max - min + 1)) + min;
78
- }
79
-
80
- static getRandomFloat(min, max, precision = 2) {
81
- const factor = 10 ** precision;
82
- const value = Math.random() * (max - min) + min;
83
-
84
- return Math.round(value * factor) / factor;
85
- }
86
-
87
- static getRandomArrayElement(array) {
88
- return array[Randomizer.getRandomInteger(array.length - 1)];
89
- }
90
-
91
- static getRandomDate(startDate = '2000-01-01', endDate = null) {
92
- const start = new Date(startDate);
93
- const end = endDate ? new Date(endDate) : new Date();
94
-
95
- if (start > end) {
96
- throw new Error('startDate cannot be more than endDate (today)');
97
- }
98
-
99
- const randomTime = start.getTime() + Math.random() * (end.getTime() - start.getTime());
100
- const randomDate = new Date(randomTime);
101
-
102
- return TimeUtils.reformatDateFromMDYtoDMY(randomDate);
103
- }
104
- }
105
-
106
- module.exports = Randomizer;
@@ -1,71 +0,0 @@
1
- const moment = require('moment');
2
- const DateFormats = require('../enums/dateFormats');
3
-
4
- class TimeUtils {
5
- static getDatesInterval(count, unitOfTime, options = {}) {
6
- const { dateBegin } = options;
7
- const startNextDay = options.startNextDay ?? true;
8
- const isNotIncluded = options.isNotIncluded ?? true;
9
- const reverseInterval = options.reverseInterval ?? false;
10
-
11
- let startDate;
12
- if (reverseInterval) {
13
- startDate = startNextDay ? moment().subtract(1, 'days') : moment();
14
- } else {
15
- startDate = startNextDay ? moment().add(1, 'days') : moment();
16
- }
17
-
18
- let finishDate;
19
- if (reverseInterval) {
20
- finishDate = dateBegin
21
- ? moment(dateBegin, DateFormats.DMY).subtract(count, unitOfTime)
22
- : moment(startDate).subtract(count, unitOfTime);
23
- if (isNotIncluded) {
24
- finishDate = moment(finishDate).add(1, 'days');
25
- }
26
- } else {
27
- finishDate = dateBegin
28
- ? moment(dateBegin, DateFormats.DMY).add(count, unitOfTime)
29
- : moment(startDate).add(count, unitOfTime);
30
- if (isNotIncluded) {
31
- finishDate = moment(finishDate).subtract(1, 'days');
32
- }
33
- }
34
-
35
- startDate = moment(startDate).format(DateFormats.DMY);
36
- finishDate = moment(finishDate).format(DateFormats.DMY);
37
- return reverseInterval
38
- ? { startDate: finishDate, finishDate: dateBegin ?? startDate }
39
- : { startDate: dateBegin ?? startDate, finishDate };
40
- }
41
-
42
- static reformatDateFromYMDToDMY(date) {
43
- return moment(date, DateFormats.YMD)
44
- .format(DateFormats.DMY);
45
- }
46
-
47
- static reformatDateFromDMYToYMD(date) {
48
- return moment(date, DateFormats.DMY)
49
- .format(DateFormats.YMD);
50
- }
51
-
52
- static reformatDateFromDMYToYMDHms(date) {
53
- return moment(date, DateFormats.DMY)
54
- .format(DateFormats.YMDHms);
55
- }
56
-
57
- static reformatDateFromMDYtoDMY(date) {
58
- return moment(date, DateFormats.MDY)
59
- .format(DateFormats.DMY);
60
- }
61
-
62
- static dateFormats() {
63
- return DateFormats;
64
- }
65
-
66
- static testMethod() {
67
- return DateFormats;
68
- }
69
- }
70
-
71
- module.exports = TimeUtils;