inmemory to postgres
This commit is contained in:
@@ -5,6 +5,7 @@ import { LeagueWalletId } from '@core/racing/domain/entities/league-wallet/Leagu
|
||||
import { Transaction } from '@core/racing/domain/entities/league-wallet/Transaction';
|
||||
import { TransactionId } from '@core/racing/domain/entities/league-wallet/TransactionId';
|
||||
import { Money } from '@core/racing/domain/value-objects/Money';
|
||||
import { seedId } from './SeedIdHelper';
|
||||
|
||||
type LeagueWalletSeed = {
|
||||
wallets: LeagueWallet[];
|
||||
@@ -12,7 +13,10 @@ type LeagueWalletSeed = {
|
||||
};
|
||||
|
||||
export class RacingLeagueWalletFactory {
|
||||
constructor(private readonly baseDate: Date) {}
|
||||
constructor(
|
||||
private readonly baseDate: Date,
|
||||
private readonly persistence: 'postgres' | 'inmemory' = 'inmemory',
|
||||
) {}
|
||||
|
||||
create(leagues: League[]): LeagueWalletSeed {
|
||||
const wallets: LeagueWallet[] = [];
|
||||
@@ -20,7 +24,7 @@ export class RacingLeagueWalletFactory {
|
||||
|
||||
for (const league of leagues) {
|
||||
const leagueId = league.id.toString();
|
||||
const walletId = `wallet-${leagueId}`;
|
||||
const walletId = seedId(`wallet-${leagueId}`, this.persistence);
|
||||
const createdAt = faker.date.past({ years: 2, refDate: this.baseDate });
|
||||
|
||||
// Ensure coverage:
|
||||
@@ -55,7 +59,7 @@ export class RacingLeagueWalletFactory {
|
||||
: faker.number.int({ min: 2, max: 18 });
|
||||
|
||||
for (let i = 0; i < transactionCount; i++) {
|
||||
const id = TransactionId.create(`tx-${leagueId}-${i + 1}`);
|
||||
const id = TransactionId.create(seedId(`tx-${leagueId}-${i + 1}`, this.persistence));
|
||||
const type = this.pickTransactionType(i, leagueId);
|
||||
const amount = this.pickAmount(type, currency, leagueId);
|
||||
|
||||
@@ -100,7 +104,7 @@ export class RacingLeagueWalletFactory {
|
||||
// Explicit edge-case: pending prize payout shows up in "pending payouts"
|
||||
if (leagueId === 'league-5') {
|
||||
const pendingPrize = Transaction.create({
|
||||
id: TransactionId.create(`tx-${leagueId}-pending-prize`),
|
||||
id: TransactionId.create(seedId(`tx-${leagueId}-pending-prize`, this.persistence)),
|
||||
walletId: LeagueWalletId.create(walletId),
|
||||
type: 'prize_payout',
|
||||
amount: Money.create(600, currency),
|
||||
@@ -108,7 +112,7 @@ export class RacingLeagueWalletFactory {
|
||||
createdAt: faker.date.recent({ days: 15, refDate: this.baseDate }),
|
||||
completedAt: undefined,
|
||||
description: 'Season prize pool payout (pending)',
|
||||
metadata: { seasonId: 'season-2', placement: 'P1-P3' },
|
||||
metadata: { seasonId: seedId('season-2', this.persistence), placement: 'P1-P3' },
|
||||
});
|
||||
|
||||
transactions.push(pendingPrize);
|
||||
|
||||
Reference in New Issue
Block a user