Skip to content

Commit

Permalink
chore: [IOBP-1143] add mock idpay expense type (#457)
Browse files Browse the repository at this point in the history
* feat: Add expense type into initiative list generator

* chore: Temporary added the IDPay definitions locally

* refactor: add real api definitions

* chore: update idpay openapi

* chore: added mock webviewurl

---------

Co-authored-by: Andrea <andrea.piai@pagopa.it>
  • Loading branch information
Hantex9 and Vangaorth authored Feb 4, 2025
1 parent febcdc7 commit a9158e4
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ const defaultConfig: IoDevServerConfig = {
refundNotConfiguredCount: 0,
refundUnsubscribedCount: 0,
refundSuspendedCount: 0,
discountCount: 1
discountCount: 1,
expenseCount: 1
}
},
services: {
Expand Down
66 changes: 66 additions & 0 deletions src/persistence/idpay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,21 @@ const generateRandomTransactionOperationDTO = (
};
};

const generateRandomTransactionOperationExpenseDTO = (
withInfo?: Partial<TransactionOperationDTO>
): TransactionOperationDTO => ({
operationType: getRandomEnumValue(TransactionOperationTypeEnum),
operationDate: new Date(),
operationId: ulid(),
accruedCents: faker.datatype.number({ min: 500, max: 2500 }),
amountCents: faker.datatype.number({ min: 5000, max: 10000 }),
circuitType: "01",
status: getRandomEnumValue(TransactionStatusEnum),
businessName: faker.company.name(),
eventId: ulid(),
...withInfo
});

const generateRandomRefundOperationDTO = (
withInfo?: Partial<RefundOperationDTO>
): RefundOperationDTO => ({
Expand Down Expand Up @@ -598,6 +613,57 @@ range(0, walletConfig.discountCount).forEach(() => {
};
});

range(0, walletConfig.expenseCount).forEach(() => {
const initiativeName = `${faker.company.name()} [E]`;
const initiative: InitiativeDTO = {
...generateRandomInitiativeDTO(),
initiativeName,
initiativeRewardType: InitiativeRewardTypeEnum.EXPENSE,
status: InitiativeStatus.REFUNDABLE,
webViewUrl: faker.internet.url()
};

const { initiativeId } = initiative;

initiatives = { ...initiatives, [initiativeId]: initiative };
instruments = {
...instruments,
[initiativeId]: [
{
instrumentId: ulid(),
idWallet: pagoPaWallet.idWallet?.toString(),
activationDate: new Date(),
status: InstrumentStatus.ACTIVE,
instrumentType: InstrumentTypeEnum.CARD
}
]
};
initiativeTimeline = {
...initiativeTimeline,
[initiativeId]: [
generateRandomRefundOperationDTO({
operationType: RefundOperationTypeEnum.PAID_REFUND
}),
generateRandomRefundOperationDTO({
operationType: RefundOperationTypeEnum.REJECTED_REFUND
}),
generateRandomTransactionOperationExpenseDTO({
operationType: TransactionOperationTypeEnum.TRANSACTION,
status: TransactionStatusEnum.AUTHORIZED
}),
generateRandomTransactionOperationExpenseDTO({
operationType: TransactionOperationTypeEnum.TRANSACTION,
status: TransactionStatusEnum.AUTHORIZED
}),
generateRandomTransactionOperationExpenseDTO({
operationType: TransactionOperationTypeEnum.TRANSACTION,
status: TransactionStatusEnum.AUTHORIZED
}),
generateRandomOnboardingOperationDTO()
]
};
});

// eslint-disable-next-line functional/no-let
export let idPayCode: string | undefined;

Expand Down
3 changes: 2 additions & 1 deletion src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ export const IoDevServerConfig = t.interface({
refundNotConfiguredCount: t.number,
refundSuspendedCount: t.number,
refundUnsubscribedCount: t.number,
discountCount: t.number
discountCount: t.number,
expenseCount: t.number
})
}),
t.partial({
Expand Down

0 comments on commit a9158e4

Please sign in to comment.