Class: MerchantBuilder
@arolariu/website / data/mocks/merchant / MerchantBuilder
Class: MerchantBuilder
Defined in: data/mocks/merchant.ts:61
Fluent builder for creating mock Merchant objects with customizable properties.
Remarks
Design Pattern: Implements the Builder pattern for flexible object construction.
Default Initialization:
- Random UUIDs for all identifiers
- Realistic company names from faker.js
- Random addresses and phone numbers
- LOCAL_SHOP category as default
- Non-deleted state (isSoftDeleted: false)
Method Chaining:
All with*() methods return this for fluent API usage.
Batch Building:
Use buildMany() to create multiple merchants with unique IDs.
Examples
// Basic usage
const merchant = new MerchantBuilder()
.withName("SuperMart")
.withCategory(MerchantCategory.SUPERMARKET)
.withAddress("123 Main St")
.build();
// Merchant chain
const parentId = faker.string.uuid();
const merchants = new MerchantBuilder()
.withParentCompanyId(parentId)
.withCategory(MerchantCategory.RESTAURANT_CHAIN)
.buildMany(5); // 5 locations of same chain
Constructors
Constructor
new MerchantBuilder():
MerchantBuilder
Defined in: data/mocks/merchant.ts:84
Creates a new MerchantBuilder with default random values.
Returns
MerchantBuilder
Remarks
Initialization Strategy:
- Generates unique UUIDs for all identifiers
- Uses faker.company.name() for realistic business names
- Creates fake addresses with street + city format
- Generates realistic phone numbers
- Defaults to LOCAL_SHOP category
- Sets random past/recent timestamps
- Randomly assigns importance flag
Example
const builder = new MerchantBuilder();
const merchant = builder.build();
// Result: Merchant with random but realistic data
Properties
merchant
privatemerchant:Merchant
Defined in: data/mocks/merchant.ts:62
Methods
withId()
withId(
id):this
Defined in: data/mocks/merchant.ts:121
Sets the unique identifier for the merchant.
Parameters
id
string
Unique identifier (typically UUID format)
Returns
this
The MerchantBuilder instance for method chaining
Example
const merchant = new MerchantBuilder()
.withId("123e4567-e89b-12d3-a456-426614174000")
.build();
withName()
withName(
name):this
Defined in: data/mocks/merchant.ts:140
Sets the business/store name for the merchant.
Parameters
name
string
Business name (e.g., "SuperMart", "Joe's Pizza")
Returns
this
The MerchantBuilder instance for method chaining
Example
const merchant = new MerchantBuilder()
.withName("Whole Foods Market")
.build();
withDescription()
withDescription(
description):this
Defined in: data/mocks/merchant.ts:158
Sets a detailed description for the merchant.
Parameters
description
string
Merchant description or notes
Returns
this
The MerchantBuilder instance for method chaining
Example
const merchant = new MerchantBuilder()
.withDescription("Organic grocery store specializing in local produce")
.build();
withCreatedAt()
withCreatedAt(
date):this
Defined in: data/mocks/merchant.ts:172
Sets when the merchant record was created.
Parameters
date
Date
Creation timestamp
Returns
this
The MerchantBuilder instance for method chaining
Remarks
Useful for testing temporal queries or filtering by creation date.
withCreatedBy()
withCreatedBy(
userId):this
Defined in: data/mocks/merchant.ts:184
Sets who created the merchant record.
Parameters
userId
string
Creator's user identifier (UUID format)
Returns
this
The MerchantBuilder instance for method chaining
withLastUpdatedAt()
withLastUpdatedAt(
date):this
Defined in: data/mocks/merchant.ts:196
Sets when the merchant record was last modified.
Parameters
date
Date
Last modification timestamp
Returns
this
The MerchantBuilder instance for method chaining
withLastUpdatedBy()
withLastUpdatedBy(
userId):this
Defined in: data/mocks/merchant.ts:207
Sets who last modified the merchant record.
Parameters
userId
string
Last updater's user identifier (UUID format)
Returns
this
The MerchantBuilder instance for method chaining
withNumberOfUpdates()
withNumberOfUpdates(
count):this
Defined in: data/mocks/merchant.ts:221
Sets how many times the merchant record was updated.
Parameters
count
number
Total number of updates (must be non-negative)
Returns
this
The MerchantBuilder instance for method chaining
Remarks
Useful for testing audit trails or versioning logic.
withIsImportant()
withIsImportant(
isImportant):this
Defined in: data/mocks/merchant.ts:231
Marks whether this merchant is important for the user.
Parameters
isImportant
boolean
Flag indicating importance
Returns
this
The MerchantBuilder instance for chaining
withIsSoftDeleted()
withIsSoftDeleted(
isSoftDeleted):this
Defined in: data/mocks/merchant.ts:241
Marks whether the merchant is logically deleted.
Parameters
isSoftDeleted
boolean
Flag indicating soft deletion status
Returns
this
The MerchantBuilder instance for chaining
withCategory()
withCategory(
category):this
Defined in: data/mocks/merchant.ts:251
Sets the business category of the merchant.
Parameters
category
Business type classification
Returns
this
The MerchantBuilder instance for chaining
withAddress()
withAddress(
address):this
Defined in: data/mocks/merchant.ts:269
Sets the merchant's physical address.
Parameters
address
string
Street address, city, state, zip
Returns
this
The MerchantBuilder instance for method chaining
Example
const merchant = new MerchantBuilder()
.withAddress("123 Main St, Springfield, IL 62701")
.build();
withPhoneNumber()
withPhoneNumber(
phoneNumber):this
Defined in: data/mocks/merchant.ts:287
Sets the merchant's contact phone number.
Parameters
phoneNumber
string
Phone number in any format
Returns
this
The MerchantBuilder instance for method chaining
Example
const merchant = new MerchantBuilder()
.withPhoneNumber("+1-555-123-4567")
.build();
withParentCompanyId()
withParentCompanyId(
companyId):this
Defined in: data/mocks/merchant.ts:314
Sets the parent company identifier for franchise/chain relationships.
Parameters
companyId
string
UUID of parent company/chain
Returns
this
The MerchantBuilder instance for method chaining
Remarks
Used to group multiple locations under a single parent entity (e.g., all McDonald's locations).
Example
const parentId = "corp-uuid";
const location1 = new MerchantBuilder()
.withParentCompanyId(parentId)
.withName("McDonald's - Downtown")
.build();
const location2 = new MerchantBuilder()
.withParentCompanyId(parentId)
.withName("McDonald's - Airport")
.build();
build()
build():
Merchant
Defined in: data/mocks/merchant.ts:323
Constructs the final merchant object from builder state.
Returns
The constructed Merchant object
buildMany()
buildMany(
count):Merchant[]
Defined in: data/mocks/merchant.ts:332
Creates multiple merchant instances with the same configuration.
Parameters
count
number
How many merchants to create
Returns
Merchant[]
An array of constructed Merchant objects