Skip to content
Snippets Groups Projects

Il/prereq

Merged ilyaukin requested to merge IL/prereq into 1.0.x
16 files
+ 202
57
Compare changes
  • Side-by-side
  • Inline
Files
16
/// <reference types='Cypress' />
/// <reference types='Cypress' />
import fs from 'fs';
import fs from 'fs'
import YAML from 'yaml';
import YAML from 'yaml'
/**
/**
* Return a string of random characters of specified length.
* Return a string of random characters of specified length.
*
*
* @param {length} int Length of string to return.
* @param {length} int Length of string to return.
*/
*/
function createRandomString (length) {
function createRandomString(length) {
let result = ''
let result = ''
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
const charactersLength = characters.length
const charactersLength = characters.length
@@ -25,8 +25,8 @@ function createRandomString (length) {
@@ -25,8 +25,8 @@ function createRandomString (length) {
* @return {{userRoles: *[], userPassword: string, userEmail: string, userName: string}}
* @return {{userRoles: *[], userPassword: string, userEmail: string, userName: string}}
*/
*/
function createRandomUser() {
function createRandomUser() {
const name1 = createRandomString(6);
const name1 = createRandomString(6)
const name2 = createRandomString(6);
const name2 = createRandomString(6)
return {
return {
userName: `${name1} ${name2}`,
userName: `${name1} ${name2}`,
userEmail: `${name1.toLowerCase()}.${name2.toLowerCase()}@ethereal.email`,
userEmail: `${name1.toLowerCase()}.${name2.toLowerCase()}@ethereal.email`,
@@ -42,8 +42,33 @@ function createRandomUser() {
@@ -42,8 +42,33 @@ function createRandomUser() {
* @return {object}
* @return {object}
*/
*/
function readYAML(filename) {
function readYAML(filename) {
return cy.readFile(`cypress/data/${filename}`).then((text) => YAML.parse(text));
return cy.readFile(`cypress/data/${filename}`).then((text) => YAML.parse(text))
}
}
 
/**
 
* Get multi-level property from an object.
 
* E.g. if object is {"foo":{"bar":"buzz"}} and key is "foo.bar",
 
* "buzz" will be returned.
 
* If key at some level does not exist, null is returned.
 
*
 
* @param object {*} Initial object.
 
* @param key {string} Property path.
 
* @return {*}
 
*/
 
function getProperty(object, key) {
 
let result
 
result = object
 
for (const p of key.split('.')) {
 
if (result === undefined) {
 
return null
 
}
 
result = result[p]
 
}
 
 
if (result === undefined) {
 
return null
 
}
 
return result
 
}
export { createRandomString, createRandomUser, readYAML }
export { createRandomString, createRandomUser, readYAML, getProperty }
Loading