Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 22 additions & 18 deletions src/subdomains/supporting/log/__tests__/log-job.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,65 +466,69 @@ describe('LogJobService', () => {
});
});

// --- getUnmatchedSenders (reference-based matching) ---
// --- getUnmatchedSenders (reference-based matching via numeric ID) ---

it('should match sender and receiver by reference', () => {
const senderTx = [createCustomBankTx({ id: 1, created: Util.hoursBefore(24), remittanceInfo: 'DEPOSIT-100' })];
const receiverTx = [createCustomExchangeTx({ id: 1, created: Util.hoursBefore(20), txId: 'DEPOSIT-100' })];
it('should match sender and receiver by numeric reference ID', () => {
const senderTx = [createCustomBankTx({ id: 1, created: Util.hoursBefore(24), remittanceInfo: 'DFX Payout 80100' })];
const receiverTx = [createCustomExchangeTx({ id: 1, created: Util.hoursBefore(20), txId: 'DEPOSIT-80100' })];

expect(service.getUnmatchedSenders(senderTx, receiverTx)).toEqual([]);
});

it('should return sender when references do not match', () => {
const senderTx = [createCustomBankTx({ id: 1, created: Util.hoursBefore(24), remittanceInfo: 'DEPOSIT-100' })];
const receiverTx = [createCustomExchangeTx({ id: 1, created: Util.hoursBefore(20), txId: 'DEPOSIT-200' })];
it('should return sender when numeric reference IDs do not match', () => {
const senderTx = [createCustomBankTx({ id: 1, created: Util.hoursBefore(24), remittanceInfo: 'DFX Payout 80100' })];
const receiverTx = [createCustomExchangeTx({ id: 1, created: Util.hoursBefore(20), txId: 'DEPOSIT-80200' })];

expect(service.getUnmatchedSenders(senderTx, receiverTx)).toEqual(senderTx);
});

it('should return sender when sender has no reference', () => {
const senderTx = [createCustomBankTx({ id: 1, created: Util.hoursBefore(24), remittanceInfo: undefined })];
const receiverTx = [createCustomExchangeTx({ id: 1, created: Util.hoursBefore(20), txId: 'DEPOSIT-100' })];
const receiverTx = [createCustomExchangeTx({ id: 1, created: Util.hoursBefore(20), txId: 'DEPOSIT-80100' })];

expect(service.getUnmatchedSenders(senderTx, receiverTx)).toEqual(senderTx);
});

it('should return sender when receiver has no reference', () => {
const senderTx = [createCustomBankTx({ id: 1, created: Util.hoursBefore(24), remittanceInfo: 'DEPOSIT-100' })];
const senderTx = [createCustomBankTx({ id: 1, created: Util.hoursBefore(24), remittanceInfo: 'DFX Payout 80100' })];
const receiverTx = [createCustomExchangeTx({ id: 1, created: Util.hoursBefore(20), txId: undefined })];

expect(service.getUnmatchedSenders(senderTx, receiverTx)).toEqual(senderTx);
});

it('should filter out senders older than 7 days', () => {
const senderTx = [createCustomBankTx({ id: 1, created: Util.hoursBefore(200), remittanceInfo: 'DEPOSIT-100' })];
const receiverTx = [createCustomExchangeTx({ id: 1, created: Util.hoursBefore(20), txId: 'DEPOSIT-200' })];
const senderTx = [
createCustomBankTx({ id: 1, created: Util.hoursBefore(200), remittanceInfo: 'DFX Payout 80100' }),
];
const receiverTx = [createCustomExchangeTx({ id: 1, created: Util.hoursBefore(20), txId: 'DEPOSIT-80200' })];

expect(service.getUnmatchedSenders(senderTx, receiverTx)).toEqual([]);
});

it('should return all senders when receiver list is empty', () => {
const senderTx = [
createCustomBankTx({ id: 1, created: Util.hoursBefore(24), remittanceInfo: 'DEPOSIT-100' }),
createCustomBankTx({ id: 2, created: Util.hoursBefore(24), remittanceInfo: 'DEPOSIT-200' }),
createCustomBankTx({ id: 1, created: Util.hoursBefore(24), remittanceInfo: 'DFX Payout 80100' }),
createCustomBankTx({ id: 2, created: Util.hoursBefore(24), remittanceInfo: 'DFX Payout 80200' }),
];

expect(service.getUnmatchedSenders(senderTx, [])).toEqual(senderTx);
});

it('should match multiple senders partially', () => {
const senderTx = [
createCustomBankTx({ id: 1, created: Util.hoursBefore(48), remittanceInfo: 'DEPOSIT-100' }),
createCustomBankTx({ id: 2, created: Util.hoursBefore(24), remittanceInfo: 'DEPOSIT-200' }),
createCustomBankTx({ id: 1, created: Util.hoursBefore(48), remittanceInfo: 'DFX Payout 80100' }),
createCustomBankTx({ id: 2, created: Util.hoursBefore(24), remittanceInfo: 'DFX Payout 80200' }),
];
const receiverTx = [createCustomExchangeTx({ id: 1, created: Util.hoursBefore(20), txId: 'DEPOSIT-100' })];
const receiverTx = [createCustomExchangeTx({ id: 1, created: Util.hoursBefore(20), txId: 'DEPOSIT-80100' })];

expect(service.getUnmatchedSenders(senderTx, receiverTx)).toEqual([senderTx[1]]);
});

it('should match ExchangeTx senders by txId against BankTx receivers by remittanceInfo', () => {
const senderTx = [createCustomExchangeTx({ id: 1, created: Util.hoursBefore(24), txId: 'WITHDRAWAL-50' })];
const receiverTx = [createCustomBankTx({ id: 1, created: Util.hoursBefore(20), remittanceInfo: 'WITHDRAWAL-50' })];
const senderTx = [createCustomExchangeTx({ id: 1, created: Util.hoursBefore(24), txId: 'WITHDRAWAL-50050' })];
const receiverTx = [
createCustomBankTx({ id: 1, created: Util.hoursBefore(20), remittanceInfo: 'DFX Payout 50050' }),
];

expect(service.getUnmatchedSenders(senderTx, receiverTx)).toEqual([]);
});
Expand Down
7 changes: 5 additions & 2 deletions src/subdomains/supporting/log/log-job.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1079,8 +1079,11 @@ export class LogJobService {
}

private getTxReference(tx: BankTx | ExchangeTx): string | undefined {
if (tx instanceof BankTx) return tx.remittanceInfo?.trim() || undefined;
return tx.txId?.trim() || undefined;
const raw = tx instanceof BankTx ? tx.remittanceInfo?.trim() : tx.txId?.trim();
if (!raw) return undefined;

const match = raw.match(/\d+$/);
return match?.[0];
}

public filterSenderPendingList(
Expand Down
Loading