FactoryFarm

new FactoryFarm()

A class to create and use factories

Members

_callPropertyDefinition

If definition is a function, calls the function. Otherwise, returns the definition.

add

Alias for this.store.add

factories :object

A hash of available factories. A factory is an object with a structure like: { name, type, attributes, relationships }.

Type:
  • object

singletons :object

A hash of singleton objects.

Type:
  • object

Methods

build(factoryName, overrideOptions, numberOfRecords) → {object}

Allows easy building of Store objects, including relationships. Takes parameters attributes and relationships to use for building.

const batchAction = store.build('cropBatchAction') store.build('basilBatch', { arbitrary_id: 'new_id' zone: 'bay1', crop_batch_actions: [ batchAction, store.build('batchAction') ] })

Parameters:
NameTypeDefaultDescription
factoryNamestring

the name of the factory to use

overrideOptionsobject

overrides for the factory

numberOfRecordsnumber1

optional number of models to build

Returns:

instance of an Store model

Type: 
object

define(name, options)

Creates a factory with { name, type, parent, ...attributesAndRelationships }, which can be used for building test data. The factory is named, with a set of options to use to configure it.

  • parent - use another factory as a basis for this one
  • type - the type of model to use (for use if no parent)
  • identity - whether this factory should be a singleton attributesAndRelationships - attributes and relationships. If properties are a function or an array of functions, they will be executed at runtime.
Parameters:
NameTypeDescription
namestring

the name to use for the factory

optionsobject

options that can be used to configure the factory

FactoryFarm

new FactoryFarm(store)

Sets up the store, and a private property to make it apparent the store is used for a FactoryFarm

Parameters:
NameTypeDescription
storeobject

the store to use under the hood

Members

_callPropertyDefinition

If definition is a function, calls the function. Otherwise, returns the definition.

add

Alias for this.store.add

factories :object

A hash of available factories. A factory is an object with a structure like: { name, type, attributes, relationships }.

Type:
  • object

singletons :object

A hash of singleton objects.

Type:
  • object

Methods

build(factoryName, overrideOptions, numberOfRecords) → {object}

Allows easy building of Store objects, including relationships. Takes parameters attributes and relationships to use for building.

const batchAction = store.build('cropBatchAction') store.build('basilBatch', { arbitrary_id: 'new_id' zone: 'bay1', crop_batch_actions: [ batchAction, store.build('batchAction') ] })

Parameters:
NameTypeDefaultDescription
factoryNamestring

the name of the factory to use

overrideOptionsobject

overrides for the factory

numberOfRecordsnumber1

optional number of models to build

Returns:

instance of an Store model

Type: 
object

define(name, options)

Creates a factory with { name, type, parent, ...attributesAndRelationships }, which can be used for building test data. The factory is named, with a set of options to use to configure it.

  • parent - use another factory as a basis for this one
  • type - the type of model to use (for use if no parent)
  • identity - whether this factory should be a singleton attributesAndRelationships - attributes and relationships. If properties are a function or an array of functions, they will be executed at runtime.
Parameters:
NameTypeDescription
namestring

the name to use for the factory

optionsobject

options that can be used to configure the factory