Skip to content

Commit

Permalink
chore(presets): add CH presets to accomodate transaction amnt issue
Browse files Browse the repository at this point in the history
  • Loading branch information
valoriecarli committed Feb 11, 2024
1 parent 71eb4f5 commit 648874f
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 13 deletions.
2 changes: 1 addition & 1 deletion models/commons/src/money/money-draft/builder.ts
Original file line number Diff line number Diff line change
@@ -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<TMoneyDraft>({
Expand Down
2 changes: 1 addition & 1 deletion models/commons/src/money/money-draft/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { TMoneyDraft } from '../types';

const generator = Generator<TMoneyDraft>({
fields: {
centAmount: fake((f) => f.number.int({ min: 5, max: 10 })),
centAmount: fake((f) => f.number.int({ min: 10 })),
currencyCode: oneOf('EUR', 'USD'),
},
});
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -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<TMoneyDraft>();

expect(usdCurrencyCodeMaxCent).toEqual(
expect.objectContaining({
currencyCode: 'USD',
centAmount: expect.any(Number),
})
);
});
});
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -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<TTransactionDraft>();
withTransactionUsdCurrencyCodeMaxCent().build<TTransactionDraft>();

expect(transactionWithUsdMoneyPreset).toEqual(
expect.objectContaining({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 648874f

Please sign in to comment.