Skip to content
Snippets Groups Projects

Il/prereq

16 files
+ 202
57
Compare changes
  • Side-by-side
  • Inline

Files

+ 32
7
/// <reference types='Cypress' />
import fs from 'fs';
import YAML from 'yaml';
import fs from 'fs'
import YAML from 'yaml'
/**
* Return a string of random characters of specified length.
*
* @param {length} int Length of string to return.
*/
function createRandomString (length) {
function createRandomString(length) {
let result = ''
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
const charactersLength = characters.length
@@ -25,8 +25,8 @@ function createRandomString (length) {
* @return {{userRoles: *[], userPassword: string, userEmail: string, userName: string}}
*/
function createRandomUser() {
const name1 = createRandomString(6);
const name2 = createRandomString(6);
const name1 = createRandomString(6)
const name2 = createRandomString(6)
return {
userName: `${name1} ${name2}`,
userEmail: `${name1.toLowerCase()}.${name2.toLowerCase()}@ethereal.email`,
@@ -42,8 +42,33 @@ function createRandomUser() {
* @return {object}
*/
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