Skip to content

Commit

Permalink
feat(product): improve default product factory field generation
Browse files Browse the repository at this point in the history
  • Loading branch information
griest024 committed Nov 21, 2023
1 parent f755ab8 commit 6e774d1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class DaffInMemoryBackendProductService implements InMemoryDbService {
'1033',
'1034',
'1035',
].map(id => this.productFactory.create({ id, url: `/${id}`, images: this.productImageFactory.createMany(5) }));
].map(id => this.productFactory.create({ id, url: `/${id}` }));
}

/**
Expand Down
24 changes: 16 additions & 8 deletions libs/product/testing/src/factories/default-product.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
DaffProductTypeEnum,
} from '@daffodil/product';

import { DaffProductImageFactory } from './product-image.factory';

/**
* Mocked DaffProduct object.
*/
Expand All @@ -24,14 +26,18 @@ export class MockProduct implements DaffProduct {
amount: this.stubDiscount,
percent: Math.floor((this.stubDiscount/this.stubPrice) * 100),
};
images = [];
thumbnail = null;
images = this.imageFactory.createMany(faker.datatype.number({ min: 1, max: 10 }));
thumbnail = this.imageFactory.create();
name = faker.commerce.productName();
brand = faker.company.companyName();
description = 'Lorem ipsum dolor sit amet, accumsan ullamcorper ei eam. Sint appetere ocurreret no per, et cum lorem disputationi. Sit ut magna delenit, assum vidisse vocibus sed ut. In aperiri malorum accusamus sea, novum mediocritatem ius at. Duo agam probo honestatis ut. Nec regione splendide cu, unum graeco vivendum in duo.';
short_description = 'Lorem ipsum dolor sit amet, accumsan ullamcorper ei eam. Sint appetere ocurreret no per, et cum lorem disputationi. Sit ut magna delenit, assum vidisse vocibus sed ut. In aperiri malorum accusamus sea, novum mediocritatem ius at. Duo agam probo honestatis ut.';
brand = faker.company.name();
description = faker.commerce.productDescription();
short_description = faker.commerce.productDescription();
meta_title = faker.commerce.productName();
meta_description = 'Lorem ipsum dolor sit amet, accumsan ullamcorper ei eam. Sint appetere ocurreret no per, et cum lorem disputationi. Sit ut magna delenit, assum vidisse vocibus sed ut. In aperiri malorum accusamus sea, novum mediocritatem ius at. Duo agam probo honestatis ut. Nec regione splendide cu, unum graeco vivendum in duo.';
meta_description = faker.commerce.productDescription();

constructor(
protected imageFactory: DaffProductImageFactory,
) {}
}

/**
Expand All @@ -41,7 +47,9 @@ export class MockProduct implements DaffProduct {
providedIn: 'root',
})
export class DaffDefaultProductFactory extends DaffModelFactory<DaffProduct> {
constructor() {
super(MockProduct);
constructor(
imageFactory: DaffProductImageFactory,
) {
super(MockProduct, imageFactory);
}
}

0 comments on commit 6e774d1

Please sign in to comment.