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
3 changes: 1 addition & 2 deletions apps/backend/test/mocks/classes/pos_deposit_mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { FileMetadata } from './../../../src/common/columns/metadata';
import { MatchStatus, MatchStatusAll } from '../../../src/common/const';
import { POSDepositEntity } from '../../../src/deposits/entities/pos-deposit.entity';
import { LocationEntity } from '../../../src/location/entities';
import { PaymentMethodEntity } from '../../../src/transaction/entities';

/*eslint-disable */
export class POSDepositMock extends POSDepositEntity {
Expand All @@ -21,7 +20,7 @@ export class POSDepositMock extends POSDepositEntity {
this.transaction_date = payment.transaction.transaction_date;
this.transaction_time = payment.transaction.transaction_time;
this.transaction_amt = payment.amount;
this.payment_method = new PaymentMethodEntity(payment.payment_method);
this.payment_method = payment.payment_method;
this.status = status ?? faker.helpers.arrayElement(MatchStatusAll);
}
}
7 changes: 5 additions & 2 deletions apps/backend/test/mocks/classes/transaction_mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ export class TransactionMock extends TransactionEntity {
this.transaction_date = dateRange.to_date;
this.transaction_time = `${faker.datatype.number({
min: 0,
max: 23
})}:${faker.datatype.number({ min: 0, max: 60 })}:00`;
max: 1
})}${faker.datatype.number({
min: 0,
max: 9
})}:00:00`;
this.total_transaction_amount = payments.reduce(
(acc: any, payment: PaymentEntity) => (acc += payment.amount),
0
Expand Down
15 changes: 13 additions & 2 deletions apps/backend/test/unit/deposits/pos_deposit.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,32 @@ import { In, Repository } from 'typeorm';
import * as fs from 'fs';
import path from 'path';
import { MatchStatus } from '../../../src/common/const';
import { ParseArgsTDI, FileTypes, Ministries } from '../../../src/constants';
import {
ParseArgsTDI,
FileTypes,
Ministries,
PaymentMethodClassification
} from '../../../src/constants';
import { POSDepositEntity } from '../../../src/deposits/entities/pos-deposit.entity';
import { PosDepositService } from '../../../src/deposits/pos-deposit.service';
import { TDI34Details } from '../../../src/flat-files';
import { parseTDI } from '../../../src/lambdas/utils/parseTDI';
import { LocationEntity } from '../../../src/location/entities/master-location-data.entity';
import { LocationService } from '../../../src/location/location.service';
import { generateLocation } from '../../mocks/const/location_mock';
import { MockData } from '../../mocks/mocks';

describe('POSDepositService', () => {
let service: PosDepositService;
let repository: Repository<POSDepositEntity>;
let posDepositMock: POSDepositEntity;
let locationService: LocationService;

beforeEach(async () => {
const mockPOSData = new MockData(PaymentMethodClassification.POS);
const posDepositsMock = mockPOSData.depositsMock as POSDepositEntity[];
posDepositMock = posDepositsMock[0];
jest.resetModules();
const module: TestingModule = await Test.createTestingModule({
providers: [
PosDepositService,
Expand All @@ -29,7 +40,7 @@ describe('POSDepositService', () => {
provide: getRepositoryToken(POSDepositEntity),
useValue: {
findOneByOrFail: jest.fn(),
find: jest.fn().mockResolvedValue(posDepositMock),
find: jest.fn().mockResolvedValue(posDepositsMock),
save: jest.fn().mockReturnValue(posDepositMock),
create: jest.fn().mockReturnValue(posDepositMock),
createQueryBuilder: jest
Expand Down
75 changes: 75 additions & 0 deletions apps/backend/test/unit/reconciliation/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { faker } from '@faker-js/faker';
import { differenceInMinutes, format, getTime, parse } from 'date-fns';
import { POSDepositEntity } from '../../../src/deposits/entities/pos-deposit.entity';
import { PaymentEntity } from '../../../src/transaction/entities';
import { paymentMethods } from '../../../test/mocks/const/payment-methods';
import { locations } from '../../mocks/const/locations';
import { MockData } from '../../mocks/mocks';

export const setSomePaymentsToTwentyMinutesLater = (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also "resetting" the payments right (as in setting the status to pending)?

I'd suggest just passing an array into this function and calling it something like resetPaymentsDataset or something, and doing the 20 minute thing for each even index within the function rather than passing in an index. With some comments to explain why.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The payments are reset between tests using:
(this is a recent change :) )

  afterEach(() => {
    jest.clearAllMocks();
  });

Function has been updated to receive an array, and status updates are removed (it was redundant since the mock data generates the status as PENDING and each test will generate new data)

:)

payments: PaymentEntity[]
) => {
return payments.map((itm: PaymentEntity, index: number) =>
index % 2 === 0
? {
...itm,
timestamp: itm.timestamp,
transaction: {
...itm.transaction,
transaction_time: format(
getTime(
parse(
`${itm.transaction.transaction_date} ${itm.transaction.transaction_time}`,
'yyyy-MM-dd HH:mm:ss',
new Date()
)
) +
1000 * 60 * 20,
'HH:mm:ss'
)
}
}
: {
...itm,
timestamp: itm.timestamp
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't itm.timestamp covered within ...itm?

}
);
};

export const unmatchedTestData = (
data: MockData
): { payments: PaymentEntity[]; deposits: POSDepositEntity[] } => {
const paymentData = data.paymentsMock;
const posData = data.depositsMock as POSDepositEntity[];
return {
payments: paymentData.map((itm) => ({
...itm,
transaction: {
...itm.transaction,
transaction_date: format(faker.date.recent(10), 'yyyy-MM-dd'),
location: faker.helpers.arrayElement(locations)
},
timestamp: parse(
format(faker.date.recent(10), 'yyyy-MM-dd'),
'yyyy-MM-dd',
new Date()
),
amount: faker.datatype.number({ min: 1, max: 1000 }),
payment_method: faker.helpers.arrayElement(paymentMethods)
})),
deposits: posData.map((itm) => ({
...itm,
timestamp: itm.timestamp,
transaction_amt: faker.datatype.number({ min: 1, max: 1000 })
}))
};
};

export const timeBetweenMatchedPaymentAndDeposit = (
payment: PaymentEntity,
deposit: POSDepositEntity
) =>
differenceInMinutes(
parse(payment.transaction.transaction_time, 'HH:mm:ss', new Date()),
parse(deposit.transaction_time, 'HH:mm:ss', new Date())
);
Loading