server/spec/fixtures/user

Test utilities to generate user-related data.

Source:

Methods

(static) admin(dataopt) → {Promise.<User>}

Source:
See:

Generates a random user record with the admin role and saves it to the database.

Takes the same arguments as the user function.

Parameters:
Name Type Attributes Default Description
data object <optional>
{}

Custom user data.

Returns:

A promise that will be resolved with the saved user.

Type
Promise.<User>

(static) email() → {string}

Source:

Generates a unique random e-mail address.

Returns:

An e-mail address.

Type
string

(static) password() → {string}

Source:

Generates a unique random password for a user account.

Returns:

A password.

Type
string

(static) user(dataopt) → {Promise.<User>}

Source:

Generates a random user record and saves it to the database.

All of the generated user's properties are assigned random or default values unless changed with the data argument.

const userFixtures = require('../spec/fixtures/user');

const user = await userFixtures.user({
  password: 'letmein'
});

console.log(user.hasPassword('letmein'));  // true
console.log(user.get('email'));            // "bob.doe@example.com"
Parameters:
Name Type Attributes Default Description
data object <optional>
{}

Custom user data.

Properties
Name Type Attributes Default Description
email string <optional>
password string <optional>
active boolean <optional>
true
roles Array.<string> <optional>
[]
createdAt string <optional>
updatedAt string <optional>
Returns:

A promise that will be resolved with the saved user.

Type
Promise.<User>