Skip to content

Commit

Permalink
refactor: use objectmother instead of faker directly
Browse files Browse the repository at this point in the history
Signed-off-by: rare-magma <[email protected]>
  • Loading branch information
rare-magma committed Oct 11, 2024
1 parent 388795f commit 63125df
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
15 changes: 7 additions & 8 deletions src/guitos/domain/budgetItem.mother.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { faker } from "@faker-js/faker";
import { BudgetItem } from "./budgetItem";
import { ObjectMother } from "./objectMother.mother";

Expand All @@ -8,22 +7,22 @@ export class BudgetItemsMother {
const list = [
new BudgetItem(
ObjectMother.positiveNumber(),
faker.lorem.word(),
faker.number.int(),
ObjectMother.word(),
ObjectMother.zeroOrPositiveNumber(),
),
new BudgetItem(
ObjectMother.positiveNumber(),
faker.lorem.word(),
faker.number.int(),
ObjectMother.word(),
ObjectMother.zeroOrPositiveNumber(),
),
new BudgetItem(
ObjectMother.positiveNumber(),
faker.lorem.word(),
faker.number.int(),
ObjectMother.word(),
ObjectMother.zeroOrPositiveNumber(),
),
];

return faker.helpers.arrayElements(list);
return ObjectMother.randomElementsFromList(list);
}

static itemForm1() {
Expand Down
12 changes: 12 additions & 0 deletions src/guitos/domain/objectMother.mother.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,16 @@ export class ObjectMother {
static recentDate(): Date {
return faker.date.recent();
}

static randomElementsFromList<T>(list: T[]): T[] {
return faker.helpers.arrayElements(list);
}

static currencyCode(): string {
return faker.finance.currencyCode();
}

static randomAlpha(): string {
return faker.string.alpha();
}
}
6 changes: 3 additions & 3 deletions src/guitos/domain/userOptions.mother.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { faker } from "@faker-js/faker";
import { UserOptions } from "./userOptions";
import { ObjectMother } from "./objectMother.mother";

// biome-ignore lint/complexity/noStaticOnlyClass: <explanation>
export class UserOptionsMother {
Expand All @@ -8,12 +8,12 @@ export class UserOptionsMother {
}

static random(): UserOptions {
const currencyCode = faker.finance.currencyCode();
const currencyCode = ObjectMother.currencyCode();
return new UserOptions(currencyCode, navigator.language);
}

static invalid(): UserOptions {
const currencyCode = faker.string.alpha();
const currencyCode = ObjectMother.randomAlpha();
return new UserOptions(currencyCode, navigator.language);
}

Expand Down

0 comments on commit 63125df

Please sign in to comment.