Fixtures

Fixtures

Source:

Fixtures and Factories for testing - Use these factories to test shops, users, example payment methods, example packages, orders, products, accounts, carts and user groups. See the meteor-factory documentation to learn how to define, extend and create your own factories.

Members

(static) account

Factory for Account

Source:
Properties:
Name Type Description
shopID String

getShop()._id

userId String

id - Factory.get("user")

emails Array

[{ address: faker.internet.email(), verified: faker.random.boolean() }]

acceptsMarketing Boolean

true

state String

"new"

note Note

faker.lorem.sentences()

profile Object

{ addressBook: [ getAddress() ] }

metafields Array

'[]'

createdAt Date

new Date()

updatedAt Date

new Date()

Example
Factory.create("account", { _id: "12345678", shopId });

(static) Cart

Define cart Factory

Source:
Properties:
Name Type Description
shopId string

id - getShop().id

accountId string

id - Factory.get("account")

email string

faker.internet.email()

items Array

[getCartItem(), getCartItem()]

shipping Array

[ { _id: Random.id(), shopId: getShop()._id, address: addressForOrder } ]

workflow Object

{ status: "checkoutPayment", workflow: [ "checkoutLogin", "checkoutAddressBook", "coreCheckoutShipping", "checkoutReview", "checkoutPayment" ] }

createdAt Date

faker.date.past()

updatedAt Date

new Date()

Types of Cart Factories:

  • cart: A cart with a user and two items
  • cartToOrder: A cart with shipping, billing info and at the Checkout workflow state
  • anonymousCart: An empty cart with an anonymous user
  • cartOne: A cart with one item
  • cartTwo: A cart with one item with quantity 2
  • cartMultiItems: A cart with two items, 1 each
  • cartMultiShop: A cart with two items, from different shops
  • cartNoItems: A cart with a user and no items
Example
const cart = Factory.create("cartMultiItems");

(static) createActiveShopFactory

Returns an active shop factory

Source:
Properties:
Name Type Description
workflow Object
status String

"active"

id String

Random.id()

(static) examplePackage

Create a new fixture based off of the Packages collection.

Source:
Since:
  • 1.5.5
Properties:
Name Type Description
name String

"example-package"

settings Object
Properties
Name Type Description
enabled Boolean

false

apiUrl String

http://example.com/api

shopId String

"random-shop-id"

(static) examplePaymentMethod

Create a new fixture based off an example payment package method

Source:
Properties:
Name Type Description
name String

"example-paymentmethod"

icon String

"fa fa-credit-card-alt"

shopId String

getShopId()

enabled Boolean

true

settings Object

Object

Properties
Name Type Description
mode Boolean

false

apikey String

""

example Object

Object

Properties
Name Type Description
enabled Boolean

false

example-paymentmethod Object

Object

Properties
Name Type Description
enabled Boolean

true

support Array

["Authorize", "Capture", "Refund"]

registry Array

[]

layout Object

null

Example
example = Factory.create("examplePaymentPackage");

(static) group

Factory for user group with permissions and a shop

Source:
Properties:
Name Type Description
name String

"default"

slug String

"default"

permissions Array

["test"]

shopID String

getShop()._id

createdAt Date

new Date()

updatedAt Date

new Date()

Example
let group = Factory.create("group", { shopId: shop._id, slug: "customer" });

(static) order

Create an Order Factory

Source:
Properties:
Name Type Description
status String

OrderItems - faker.lorem.sentence(3)

history Array

OrderItems History - []

documents Array

OrderItems Document - []

cartId String

Order - Random.id()

notes Array

Order - []

shopId String

Cart - shopId

Properties
Name Type Description
accountId String

Cart - accountId

email String

Cart - faker.internet.email()

workflow String

Cart - Object

Properties
Name Type Description
status String

Cart - "new"

workflow String

Cart - "coreOrderWorkflow/created"

items Array

Array of products

Properties
Name Type Description
_id String

Cart - Product - cart ID

title String

Cart - Product - "itemOne"

shopId String

Cart - Product - store ID

productId String

Cart - Product - product ID

quantity Number

Cart - Product - 1

variants Object

Cart - Product - variants

workflow Object

Cart - Product - Object

Properties
Name Type Description
status String

Cart - Product - "new"

supportedFulfillmentTypes Array.<String>

["shipping"]

shipping Array

Shipping - [{}]

Properties
Name Type Description
itemIds Array.<String>
payment Object

A payment

Properties
Name Type Description
_id String

Billing - Random.id()

address Object

Billing - Address object

displayName String

"MasterCard 2346"

method String

"credit"

processor String

"Example"

paymentPluginName String

"example-paymentmethod"

mode String

"authorize"

status String

"created"

amount Number

12.4

invoice Object

Object

Properties
Name Type Description
total Number

12.45

subtotal Number

12.45

discounts Number

0

taxes Number

0.12

shipping Number

4.0

state String

"new"

createdAt Date

new Date()

updatedAt Date

new Date()

Example
order = Factory.create("order")

(static) Product

Define a factory for Product

Source:
Properties:
Name Type Description
ancestors Array

[]

shopId String

getShop()._id

title String

faker.commerce.productName()

pageTitle String

faker.lorem.sentence()

description String

faker.lorem.paragraph()

type String

"simple" or "variant" for Product Variant

vendor String

faker.company.companyName()

price Object

priceRange

Properties
Name Type Description
range String

"1.00 - 12.99"

min Number

1.00

max Number

12.9

isLowQuantity Boolean

false

isSoldOut Boolean

false

isBackorder Boolean

false

metafields Array

[]

supportedFulfillmentTypes Array.<String>

["shipping"]

hashtags Array

[]

isVisible Boolean

true

publishedAt Date

new Date()

createdAt Date

new Date()

updatedAt Date

new Date()

Examples
const product = Factory.create("product")
Factory.create("variant", Object.assign({}, productVariant(options), { ancestors: [product._id, variant._id] }));

(static) tag

Define a Tag for Products

Source:
Properties:
Name Type Description
name String

"Tag"

slug String

"tag"

position Number

_.random(0, 100000)

isTopLevel Boolean

true

shopId String

getShop()._id

createdAt Date

faker.date.past()

updatedAt Date

new Date()

Example
Factory.create("tag")

(static) user

Define user Factory

Source:
Properties:
Name Type Description
username String

faker.internet.userName() + _.random(0, 1000)

name String

faker.name.findName()

emails Array

[{address: faker.internet.email(), verified: true}]

profile Object

{ name: this.name, email: faker.internet.email(), profilePictureUrl: faker.image.imageUrl() }

gender String

String: "Male", "Female", "Either"

description String

faker.lorem.paragraphs(3)

startTime Date

calculatedStartTime

createdAt Date

new Date()

roles Object

{shopId: ["guest", "anonymous", "product"]}

Types of User factories

  • user - A user
  • registeredUser - A user with a password, loginTokens and roles: account/profile, guest, product, tag, index, cart/checkout, cart/completed
  • anonymous - A user without an account with rules: guest, anonymous, product, tag, index, cart/checkout, cart/completed
Example
const user1 = Factory.create("user");

Methods

(static) addProduct(optionsopt) → {Object}

Create a product with variants

Source:
Parameters:
Name Type Attributes Default Description
options Object <optional>
{}

[description]

Properties
Name Type Attributes Description
_id String <optional>

id

parentId String <optional>

variant's parent's ID. Sets variant as child.

compareAtPrice String <optional>

MSRP Price / Compare At Price

weight String <optional>

productVariant weight

inventoryManagement String <optional>

Track inventory for this product?

inventoryPolicy String <optional>

Allow overselling of this product?

lowInventoryWarningThreshold String <optional>

Qty left of inventory that sets off warning

inventoryQuantity String <optional>

Inventory Quantity

price String <optional>

productVariant price

title String <optional>

productVariant title

optionTitle String <optional>

productVariant option title

sku String <optional>

productVariant sku

taxable String <optional>

is this productVariant taxable?

metafields Array.<Object> <optional>

productVariant metaFields

Returns:

Product

Type
Object

(static) addProductSingleVariant(optionsopt) → {Object}

Create a product with 1 variant

Source:
Parameters:
Name Type Attributes Default Description
options Object <optional>
{}

Product variant options object

Returns:

Product with Variant

Type
Object

(static) createActiveShop(optionsopt) → {Object}

Find and return an existing shop from option parameters, or create an active shop factory

Source:
Parameters:
Name Type Attributes Default Description
options Object <optional>
{}

Any shop properties

Returns:

Shop, with active status

Type
Object

(static) createCart(productId, variantId) → {Object}

Source:
Parameters:
Name Type Description
productId String

ID of Product

variantId String

ID of Product Variant

Returns:

Inserted cart object

Type
Object

(static) createShopFactory() → {Object}

Create Shop factory. Shop name should be unique for the slug to be unique.

Source:
Properties:
Name Type Description
name String

faker.internet.domainName()

description String

faker.company.catchPhrase()

keywords String

faker.company.bsAdjective()

addressBook Array

[getAddress()]

domains Array

["localhost"]

emails Array

[]

Properties
Name Type Description
address String

faker.internet.email()

verified Boolean

faker.random.boolean()

currency String

"USD" - Could use faker.finance.currencyCode()

currencies Object

{}

Properties
Name Type Description
USD Object

{}

Properties
Name Type Description
format String

"%s%v"

symbol String

"$"

EUR Object

{}

Properties
Name Type Description
format String

"%v %s"

symbol String

"€"

decimal String

","

thousand String

"."

locale String

"en"

locales Object

{}

Properties
Name Type Description
continents Object

{}

Properties
Name Type Description
NA String

"North America"

countries Object

{}

Properties
Name Type Description
US Object

{}

name String

"United States"

native String

"United States"

phone String

"1"

continent String

"NA"

capital String

"Washington D.C."

currency String

"USD,USN,USS"

languages String

"en"

baseUOL String

"in"

unitsOfLength Array

[{}]

Properties
Name Type Description
uol String

"in"

label String

"Inches"

default String

true

uol String

"cm"

label String

"Centimeters"

uol String

"ft"

label String

"Feet"

baseUOM String

"oz"

unitsOfMeasure Array

[{}]

Properties
Name Type Description
uom String

"oz"

label String

"Ounces"

default String

true

uom String

"lb"

label String

"Pounds"

uom String

"g"

label String

"Grams"

uom String

"kg"

label String

"Kilograms"

layout Array

[{}]

layout String

"coreLayout"

workflow String

"coreLayout"

theme String

"default"

enabled Boolean

true

layout String

"coreLayout"

workflow String

"coreCartWorkflow"

collection String

"Cart"

theme String

"default"

enabled Boolean

true

layout String

"coreLayout"

workflow String

"coreOrderWorkflow"

collection String

"Orders"

theme String

"default"

enabled Boolean

true

layout String

"coreLayout"

workflow String

"coreOrderShipmentWorkflow"

collection String

"Orders"

theme String

"default"

enabled Boolean

true

workflow Object

{}

Properties
Name Type Description
status String

"active"

public Boolean

true

brandAssets Array

[]

mediaId String

"J8Bhq3uTtdgwZx3rz"

type String

"navbarBrandImage"

timezone String

"US/Pacific"

metafields Array

[]

shopType String

"primary" - Not having a primary shop will cause test failures. one shop in the marketplace is required as default shop. This is used to control marketplace settings.

createdAt Date

new Date()

updatedAt Date

new Date()

Returns:

Shop with status "active"

Type
Object

(static) defineOrders() → {undefined}

Source:
Returns:
Type
undefined

(static) getAddress(optionsopt) → {Object}

Get an address, supplying options (optional)

Source:
Parameters:
Name Type Attributes Default Description
options Object <optional>
{}

Address options, optional

Properties
Name Type Attributes Description
fullName String <optional>

fullName - faker.name.findName()

address1 String <optional>

address1 - faker.address.streetAddress()

address2 String <optional>

address2 - faker.address.secondaryAddress()

city String <optional>

city - faker.address.city()

company String <optional>

company - faker.company.companyName()

phone String <optional>

phone - faker.phone.phoneNumber()

region String <optional>

region - faker.address.stateAbbr()

postal String <optional>

postal - faker.address.zipCode()

country String <optional>

country - faker.address.countryCode()

isCommercial String <optional>

isCommercial - faker.random.boolean()

isShippingDefault Boolean <optional>

isShippingDefault - faker.random.boolean()

isBillingDefault Boolean <optional>

isBillingDefault - faker.random.boolean()

metafields Array <optional>

metafields - []

Returns:

Address object

Type
Object

(static) getAddress(optionsopt) → {Object}

Source:
Parameters:
Name Type Attributes Default Description
options Object <optional>
{}

Address options, optional

Properties
Name Type Attributes Description
_id String <optional>

id of CartItem

fullName String <optional>

fullName

address1 String <optional>

address1

address2 String <optional>

address2

city String <optional>

city

company String <optional>

company

phone String <optional>

phone

region String <optional>

region

postal String <optional>

postal

country String <optional>

country

isCommercial Boolean <optional>

isCommercial

isShippingDefault Boolean <optional>

isShippingDefault

isBillingDefault Boolean <optional>

isBillingDefault

metafields Array <optional>

metafields

Returns:

Address object

Type
Object

(static) getCartItem(optionsopt) → {Object}

Source:
Parameters:
Name Type Attributes Description
options Object <optional>

Options object (optional)

Properties
Name Type Attributes Description
_id string <optional>

id of CartItem

productId string <optional>

_id of product that item came from

shopId string <optional>

_id of shop that item came from

quantity number <optional>

quantity of item in CartItem

variants Object <optional>

single variant object. ¯_(ツ)_/¯ why called variants

Returns:
  • randomly generated cartItem/orderItem data object
Type
Object

(static) getPkgData(pkgName) → {Object}

Get package data object, given a package name

Source:
Example
getPkgData("example-paymentmethod") ? getPkgData("example-paymentmethod")._id : "uiwneiwknekwewe"
Parameters:
Name Type Description
pkgName String

name of package

Returns:

Package object

Type
Object

(static) getProduct(optionsopt) → {Object}

Get a product

Source:
Parameters:
Name Type Attributes Default Description
options Object <optional>
{}

Product variant options object

Returns:

Product

Type
Object

(static) getProducts(limitopt) → {Array}

Get a number of products

Source:
Parameters:
Name Type Attributes Default Description
limit Object <optional>
2

Number of products

Returns:

Array of products

Type
Array

(static) getShop() → {Object}

Get an existing shop or create a shop factory

Source:
Returns:

Shop

Type
Object

(static) getShopId() → {String}

Get the first shop found and return the shop id

Source:
Returns:

Shop ID

Type
String

(static) getShopId() → {String}

Source:
Returns:

ID

Type
String

(static) getSingleCartItem(optionsopt) → {Object}

Source:
Parameters:
Name Type Attributes Description
options Object <optional>

Options object (optional)

Properties
Name Type Attributes Description
_id string <optional>

id of CartItem

productId string <optional>

_id of product that item came from

shopId string <optional>

_id of shop that item came from

Returns:
  • randomly generated cartItem/orderItem data object with only one cart item
Type
Object

(static) getUser() → {Object}

Source:
Returns:

Existing user or Factory user

Type
Object

(static) getUser() → {Object}

Source:
Returns:

Existing user or Factory user

Type
Object

(static) getUserId() → {String}

Source:
Returns:

ID

Type
String

(static) getUsers(limit) → {Array}

Source:
Parameters:
Name Type Description
limit Number

Default set to 2

Returns:

Array of existing users or Factory user

Type
Array

(static) metaField(optionsopt) → {Object}

Source:
Parameters:
Name Type Attributes Description
options Object <optional>

options object to override generated default values

Properties
Name Type Attributes Description
key String <optional>

metaField key

value String <optional>

metaField value

scope String <optional>

metaField scope

Returns:
  • randomly generated metaField
Type
Object

(static) productVariant(optionsopt) → {Object}

Source:
Parameters:
Name Type Attributes Description
options Object <optional>

Options object

Properties
Name Type Attributes Description
_id String <optional>

id

parentId String <optional>

variant's parent's ID. Sets variant as child.

compareAtPrice String <optional>

MSRP Price / Compare At Price

weight String <optional>

productVariant weight

inventoryManagement String <optional>

Track inventory for this product?

inventoryPolicy String <optional>

Allow overselling of this product?

lowInventoryWarningThreshold String <optional>

Qty left of inventory that sets off warning

inventoryQuantity String <optional>

Inventory Quantity

price String <optional>

productVariant price

title String <optional>

productVariant title

optionTitle String <optional>

productVariant option title

sku String <optional>

productVariant sku

taxable String <optional>

is this productVariant taxable?

metafields Array.<Object> <optional>

productVariant metaFields

Returns:
  • randomly generated productVariant
Type
Object

(static) randomMode() → {String}

Return a random credit card status, from: "authorize", "capture", "refund", "void"

Source:
Returns:

Payment status string

Type
String

(static) randomProcessor() → {String}

Return a random payment processor string, either: "Stripe" "Braintree"

Source:
Returns:

Name of payment processor

Type
String

(static) randomStatus() → {String}

Return a random payment status, from: "created", "approved", "failed", "canceled", "expired", "pending", "voided", "settled"

Source:
Returns:

Payment status string

Type
String