fix: harden dependencies and downstream delivery
This commit is contained in:
@@ -254,6 +254,7 @@ describe('OperationsService', () => {
|
||||
.mockResolvedValueOnce(1)
|
||||
.mockResolvedValueOnce(1)
|
||||
.mockResolvedValueOnce(2);
|
||||
prisma.accountTransaction.aggregate.mockResolvedValueOnce({ _count: { _all: 2 }, _sum: { amountCents: 10 } });
|
||||
const service = new OperationsService(prisma as never);
|
||||
|
||||
await expect(service.dashboard({ tenantId: 'tenant-1' })).resolves.toEqual(
|
||||
@@ -269,6 +270,7 @@ describe('OperationsService', () => {
|
||||
templates: 1,
|
||||
total: 5,
|
||||
},
|
||||
today: expect.objectContaining({ returnedCents: 10 }),
|
||||
gatewayConnections: [{ status: 'connected', _count: { _all: 1 }, _sum: { currentConnections: 2, desiredConnections: 2 } }],
|
||||
downstreamDeliverySummary: expect.objectContaining({
|
||||
pending: 3,
|
||||
@@ -282,7 +284,14 @@ describe('OperationsService', () => {
|
||||
}),
|
||||
);
|
||||
expect(prisma.cmppDownstreamDelivery.count).toHaveBeenNthCalledWith(4, {
|
||||
where: { tenantId: 'tenant-1', status: 'pending', createdAt: { lte: expect.any(Date) } },
|
||||
where: {
|
||||
tenantId: 'tenant-1',
|
||||
status: 'pending',
|
||||
OR: [
|
||||
{ lastRetriedAt: null, createdAt: { lte: expect.any(Date) } },
|
||||
{ lastRetriedAt: { lte: expect.any(Date) } },
|
||||
],
|
||||
},
|
||||
});
|
||||
expect(prisma.cmppDownstreamDelivery.count).toHaveBeenNthCalledWith(5, {
|
||||
where: { tenantId: 'tenant-1', status: 'awaiting_ack', ackDeadlineAt: { lte: expect.any(Date) } },
|
||||
@@ -294,6 +303,18 @@ describe('OperationsService', () => {
|
||||
updatedAt: { gte: expect.any(Date) },
|
||||
},
|
||||
});
|
||||
expect(prisma.accountTransaction.aggregate).toHaveBeenCalledWith({
|
||||
where: {
|
||||
tenantId: 'tenant-1',
|
||||
createdAt: { gte: expect.any(Date) },
|
||||
OR: [
|
||||
{ transactionType: 'refunded' },
|
||||
{ transactionType: 'released', relatedType: 'sms_message_record' },
|
||||
],
|
||||
},
|
||||
_sum: { amountCents: true },
|
||||
_count: { _all: true },
|
||||
});
|
||||
await service.statistics({ tenantId: 'tenant-1', groupBy: 'application' });
|
||||
|
||||
expect(prisma.smsMessageRecord.groupBy).toHaveBeenCalledWith({
|
||||
@@ -516,10 +537,16 @@ describe('OperationsService', () => {
|
||||
by: ['applicationId'],
|
||||
where: {
|
||||
AND: [
|
||||
{ tenantId: 'tenant-1', applicationId: 'app-1', deliveryType: undefined },
|
||||
{ tenantId: 'tenant-1', applicationId: 'app-1', deliveryType: undefined, createdAt: undefined },
|
||||
{
|
||||
OR: [
|
||||
{ status: 'pending', createdAt: { lte: expect.any(Date) } },
|
||||
{
|
||||
status: 'pending',
|
||||
OR: [
|
||||
{ lastRetriedAt: null, createdAt: { lte: expect.any(Date) } },
|
||||
{ lastRetriedAt: { lte: expect.any(Date) } },
|
||||
],
|
||||
},
|
||||
{ status: 'awaiting_ack', ackDeadlineAt: { lte: expect.any(Date) } },
|
||||
{ status: { in: ['failed', 'unconfirmed', 'rejected'] }, updatedAt: { gte: expect.any(Date) } },
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user