From 648874f71883805c5bcce492914373cb991b40d8 Mon Sep 17 00:00:00 2001 From: Valorie Carli Date: Sun, 11 Feb 2024 16:07:22 -0600 Subject: [PATCH] chore(presets): add CH presets to accomodate transaction amnt issue --- models/commons/src/money/money-draft/builder.ts | 2 +- .../commons/src/money/money-draft/generator.ts | 2 +- .../presets/change-history-data/index.ts | 3 ++- .../with-usd-currency-code-max-cent.spec.ts | 16 ++++++++++++++++ .../with-usd-currency-code-max-cent.ts | 11 +++++++++++ .../with-usd-currency-code.ts | 2 +- .../presets/change-history-data/index.ts | 4 ++-- ...s => with-usd-currency-code-max-cent.spec.ts} | 8 ++++---- ...ode.ts => with-usd-currency-code-max-cent.ts} | 6 +++--- 9 files changed, 41 insertions(+), 13 deletions(-) create mode 100644 models/commons/src/money/money-draft/presets/change-history-data/with-usd-currency-code-max-cent.spec.ts create mode 100644 models/commons/src/money/money-draft/presets/change-history-data/with-usd-currency-code-max-cent.ts rename models/payment/src/transaction/transaction-draft/presets/change-history-data/{with-usd-currency-code.spec.ts => with-usd-currency-code-max-cent.spec.ts} (58%) rename models/payment/src/transaction/transaction-draft/presets/change-history-data/{with-usd-currency-code.ts => with-usd-currency-code-max-cent.ts} (52%) diff --git a/models/commons/src/money/money-draft/builder.ts b/models/commons/src/money/money-draft/builder.ts index 2444ed9fc..4f517d133 100644 --- a/models/commons/src/money/money-draft/builder.ts +++ b/models/commons/src/money/money-draft/builder.ts @@ -1,7 +1,7 @@ import { Builder } from '@commercetools-test-data/core'; +import type { TMoneyDraft, TCreateMoneyBuilder } from '../types'; import generator from './generator'; import transformers from './transformers'; -import type { TMoneyDraft, TCreateMoneyBuilder } from '../types'; const Model: TCreateMoneyBuilder = () => Builder({ diff --git a/models/commons/src/money/money-draft/generator.ts b/models/commons/src/money/money-draft/generator.ts index 13734f148..ddba3362e 100644 --- a/models/commons/src/money/money-draft/generator.ts +++ b/models/commons/src/money/money-draft/generator.ts @@ -5,7 +5,7 @@ import { TMoneyDraft } from '../types'; const generator = Generator({ fields: { - centAmount: fake((f) => f.number.int({ min: 5, max: 10 })), + centAmount: fake((f) => f.number.int({ min: 10 })), currencyCode: oneOf('EUR', 'USD'), }, }); diff --git a/models/commons/src/money/money-draft/presets/change-history-data/index.ts b/models/commons/src/money/money-draft/presets/change-history-data/index.ts index 9370adda1..bd53b75b3 100644 --- a/models/commons/src/money/money-draft/presets/change-history-data/index.ts +++ b/models/commons/src/money/money-draft/presets/change-history-data/index.ts @@ -1,5 +1,6 @@ import withUsdCurrencyCode from './with-usd-currency-code'; +import withUsdCurrencyCodeCentMax from './with-usd-currency-code-max-cent'; -const presets = { withUsdCurrencyCode }; +const presets = { withUsdCurrencyCodeCentMax, withUsdCurrencyCode }; export default presets; diff --git a/models/commons/src/money/money-draft/presets/change-history-data/with-usd-currency-code-max-cent.spec.ts b/models/commons/src/money/money-draft/presets/change-history-data/with-usd-currency-code-max-cent.spec.ts new file mode 100644 index 000000000..f56ef247c --- /dev/null +++ b/models/commons/src/money/money-draft/presets/change-history-data/with-usd-currency-code-max-cent.spec.ts @@ -0,0 +1,16 @@ +import { TMoneyDraft } from '../../../types'; +import withUsdCurrencyCodeCentMax from './with-usd-currency-code-max-cent'; + +describe('MoneyDraft with a defined `USD` currencyCode and defined max cent', () => { + it('should return a currencyCode set to `USD` and max cent', () => { + const usdCurrencyCodeMaxCent = + withUsdCurrencyCodeCentMax().build(); + + expect(usdCurrencyCodeMaxCent).toEqual( + expect.objectContaining({ + currencyCode: 'USD', + centAmount: expect.any(Number), + }) + ); + }); +}); diff --git a/models/commons/src/money/money-draft/presets/change-history-data/with-usd-currency-code-max-cent.ts b/models/commons/src/money/money-draft/presets/change-history-data/with-usd-currency-code-max-cent.ts new file mode 100644 index 000000000..4e340778a --- /dev/null +++ b/models/commons/src/money/money-draft/presets/change-history-data/with-usd-currency-code-max-cent.ts @@ -0,0 +1,11 @@ +import { TMoneyDraftBuilder } from '../../../types'; +import MoneyDraft from '../../builder'; + +const random10DigitNumber = (): number => { + return Math.floor(1000000000 + Math.random() * 9000000000); +}; + +const withUsdCurrencyCodeCentMax = (): TMoneyDraftBuilder => + MoneyDraft().currencyCode('USD').centAmount(random10DigitNumber()); + +export default withUsdCurrencyCodeCentMax; diff --git a/models/payment/src/payment/payment-draft/presets/change-history-data/with-usd-currency-code.ts b/models/payment/src/payment/payment-draft/presets/change-history-data/with-usd-currency-code.ts index e13358e3d..078cccaa6 100644 --- a/models/payment/src/payment/payment-draft/presets/change-history-data/with-usd-currency-code.ts +++ b/models/payment/src/payment/payment-draft/presets/change-history-data/with-usd-currency-code.ts @@ -8,7 +8,7 @@ const withUsdCurrencyCode = (): TPaymentDraftBuilder => .anonymousId(undefined) .amountPlanned(MoneyDraft.presets.changeHistoryData.withUsdCurrencyCode()) .transactions([ - TransactionDraft.presets.changeHistoryData.withUsdCurrencyCode(), + TransactionDraft.presets.changeHistoryData.withTransactionUsdCurrencyCodeMaxCent(), ]); export default withUsdCurrencyCode; diff --git a/models/payment/src/transaction/transaction-draft/presets/change-history-data/index.ts b/models/payment/src/transaction/transaction-draft/presets/change-history-data/index.ts index d5fb7bc82..4e45e44e7 100644 --- a/models/payment/src/transaction/transaction-draft/presets/change-history-data/index.ts +++ b/models/payment/src/transaction/transaction-draft/presets/change-history-data/index.ts @@ -1,7 +1,7 @@ -import withUsdCurrencyCode from './with-usd-currency-code'; +import withTransactionUsdCurrencyCodeMaxCent from './with-usd-currency-code-max-cent'; const presets = { - withUsdCurrencyCode, + withTransactionUsdCurrencyCodeMaxCent, }; export default presets; diff --git a/models/payment/src/transaction/transaction-draft/presets/change-history-data/with-usd-currency-code.spec.ts b/models/payment/src/transaction/transaction-draft/presets/change-history-data/with-usd-currency-code-max-cent.spec.ts similarity index 58% rename from models/payment/src/transaction/transaction-draft/presets/change-history-data/with-usd-currency-code.spec.ts rename to models/payment/src/transaction/transaction-draft/presets/change-history-data/with-usd-currency-code-max-cent.spec.ts index da89b430a..f96aa84aa 100644 --- a/models/payment/src/transaction/transaction-draft/presets/change-history-data/with-usd-currency-code.spec.ts +++ b/models/payment/src/transaction/transaction-draft/presets/change-history-data/with-usd-currency-code-max-cent.spec.ts @@ -1,10 +1,10 @@ import { TTransactionDraft } from '../../../types'; -import withUsdCurrencyCode from './with-usd-currency-code'; +import withTransactionUsdCurrencyCodeMaxCent from './with-usd-currency-code-max-cent'; -describe('Transaction with with the amount money of `USD` currencyCode preset', () => { - it('should return the currencyCode of `USD`', () => { +describe('Transaction with with the amount money of `USD` currencyCode and max cent amount preset', () => { + it('should return the currencyCode of `USD` with a max cent amount', () => { const transactionWithUsdMoneyPreset = - withUsdCurrencyCode().build(); + withTransactionUsdCurrencyCodeMaxCent().build(); expect(transactionWithUsdMoneyPreset).toEqual( expect.objectContaining({ diff --git a/models/payment/src/transaction/transaction-draft/presets/change-history-data/with-usd-currency-code.ts b/models/payment/src/transaction/transaction-draft/presets/change-history-data/with-usd-currency-code-max-cent.ts similarity index 52% rename from models/payment/src/transaction/transaction-draft/presets/change-history-data/with-usd-currency-code.ts rename to models/payment/src/transaction/transaction-draft/presets/change-history-data/with-usd-currency-code-max-cent.ts index 0a7d54983..11d45b3c1 100644 --- a/models/payment/src/transaction/transaction-draft/presets/change-history-data/with-usd-currency-code.ts +++ b/models/payment/src/transaction/transaction-draft/presets/change-history-data/with-usd-currency-code-max-cent.ts @@ -2,9 +2,9 @@ import { MoneyDraft } from '@commercetools-test-data/commons'; import type { TTransactionDraftBuilder } from '../../../types'; import * as TransactionDraft from '../../index'; -const withUsdCurrencyCode = (): TTransactionDraftBuilder => +const withTransactionUsdCurrencyCodeMaxCent = (): TTransactionDraftBuilder => TransactionDraft.random().amount( - MoneyDraft.presets.changeHistoryData.withUsdCurrencyCode() + MoneyDraft.presets.changeHistoryData.withUsdCurrencyCodeCentMax() ); -export default withUsdCurrencyCode; +export default withTransactionUsdCurrencyCodeMaxCent;