Phase 5 cleanup
This commit is contained in:
parent
5536acd67d
commit
76a516a417
136 changed files with 6322 additions and 1985 deletions
|
|
@ -45,7 +45,13 @@ describe(RefillsService.name, () => {
|
|||
describe('getAlerts', () => {
|
||||
it('returns empty array when no medicines are running low', async () => {
|
||||
mockRegimensService.calculateBurnRates.mockResolvedValue([
|
||||
{ medicineId: 'med-1', medicineName: 'Aspirin', dailyConsumption: 1, totalInCabinet: 100, daysUntilEmpty: 100 },
|
||||
{
|
||||
medicineId: 'med-1',
|
||||
medicineName: 'Aspirin',
|
||||
dailyConsumption: 1,
|
||||
totalInCabinet: 100,
|
||||
daysUntilEmpty: 100,
|
||||
},
|
||||
]);
|
||||
|
||||
const result = await service.getAlerts('hh1', 'user-1', 7);
|
||||
|
|
@ -55,7 +61,13 @@ describe(RefillsService.name, () => {
|
|||
|
||||
it('returns alerts for medicines below threshold', async () => {
|
||||
mockRegimensService.calculateBurnRates.mockResolvedValue([
|
||||
{ medicineId: 'med-1', medicineName: 'Aspirin', dailyConsumption: 2, totalInCabinet: 10, daysUntilEmpty: 5 },
|
||||
{
|
||||
medicineId: 'med-1',
|
||||
medicineName: 'Aspirin',
|
||||
dailyConsumption: 2,
|
||||
totalInCabinet: 10,
|
||||
daysUntilEmpty: 5,
|
||||
},
|
||||
]);
|
||||
mockCabinetRepo.getAggregateSummary.mockResolvedValue([
|
||||
{ _id: 'med-1', medicineStrength: 500, medicineStrengthUnit: 'mg' },
|
||||
|
|
@ -73,7 +85,13 @@ describe(RefillsService.name, () => {
|
|||
|
||||
it('attaches lastKnownPrice when available', async () => {
|
||||
mockRegimensService.calculateBurnRates.mockResolvedValue([
|
||||
{ medicineId: 'med-1', medicineName: 'Aspirin', dailyConsumption: 2, totalInCabinet: 5, daysUntilEmpty: 2 },
|
||||
{
|
||||
medicineId: 'med-1',
|
||||
medicineName: 'Aspirin',
|
||||
dailyConsumption: 2,
|
||||
totalInCabinet: 5,
|
||||
daysUntilEmpty: 2,
|
||||
},
|
||||
]);
|
||||
mockCabinetRepo.getAggregateSummary.mockResolvedValue([]);
|
||||
mockPricesRepo.getLatestForMedicine.mockResolvedValue({
|
||||
|
|
@ -93,12 +111,25 @@ describe(RefillsService.name, () => {
|
|||
|
||||
it('attaches cheapestOption from compareStores', async () => {
|
||||
mockRegimensService.calculateBurnRates.mockResolvedValue([
|
||||
{ medicineId: 'med-1', medicineName: 'Aspirin', dailyConsumption: 2, totalInCabinet: 5, daysUntilEmpty: 2 },
|
||||
{
|
||||
medicineId: 'med-1',
|
||||
medicineName: 'Aspirin',
|
||||
dailyConsumption: 2,
|
||||
totalInCabinet: 5,
|
||||
daysUntilEmpty: 2,
|
||||
},
|
||||
]);
|
||||
mockCabinetRepo.getAggregateSummary.mockResolvedValue([]);
|
||||
mockPricesRepo.getLatestForMedicine.mockResolvedValue(null);
|
||||
mockPricesRepo.compareStores.mockResolvedValue([
|
||||
{ storeId: 'st-1', storeName: 'CVS', latestPrice: 8, latestPricePerUnit: 0.08, currency: 'USD', date: new Date() },
|
||||
{
|
||||
storeId: 'st-1',
|
||||
storeName: 'CVS',
|
||||
latestPrice: 8,
|
||||
latestPricePerUnit: 0.08,
|
||||
currency: 'USD',
|
||||
date: new Date(),
|
||||
},
|
||||
]);
|
||||
|
||||
const result = await service.getAlerts('hh1', 'user-1', 7);
|
||||
|
|
@ -109,7 +140,13 @@ describe(RefillsService.name, () => {
|
|||
|
||||
it('includes pendingOrderStock and daysUntilEmptyWithOrders from ordered purchases', async () => {
|
||||
mockRegimensService.calculateBurnRates.mockResolvedValue([
|
||||
{ medicineId: 'med-1', medicineName: 'Aspirin', dailyConsumption: 2, totalInCabinet: 4, daysUntilEmpty: 2 },
|
||||
{
|
||||
medicineId: 'med-1',
|
||||
medicineName: 'Aspirin',
|
||||
dailyConsumption: 2,
|
||||
totalInCabinet: 4,
|
||||
daysUntilEmpty: 2,
|
||||
},
|
||||
]);
|
||||
mockCabinetRepo.getAggregateSummary.mockResolvedValue([]);
|
||||
mockPricesRepo.getLatestForMedicine.mockResolvedValue(null);
|
||||
|
|
@ -126,7 +163,13 @@ describe(RefillsService.name, () => {
|
|||
|
||||
it('excludes medicines with null daysUntilEmpty', async () => {
|
||||
mockRegimensService.calculateBurnRates.mockResolvedValue([
|
||||
{ medicineId: 'med-1', medicineName: 'Aspirin', dailyConsumption: 2, totalInCabinet: 0, daysUntilEmpty: null },
|
||||
{
|
||||
medicineId: 'med-1',
|
||||
medicineName: 'Aspirin',
|
||||
dailyConsumption: 2,
|
||||
totalInCabinet: 0,
|
||||
daysUntilEmpty: null,
|
||||
},
|
||||
]);
|
||||
|
||||
const result = await service.getAlerts('hh1', 'user-1', 7);
|
||||
|
|
@ -145,7 +188,9 @@ describe(RefillsService.name, () => {
|
|||
name: 'My List',
|
||||
fromAlerts: false,
|
||||
thresholdDays: 7,
|
||||
items: [{ medicineId: 'med-1', medicineName: 'Aspirin', quantity: 30, unit: 'tablet' as never }],
|
||||
items: [
|
||||
{ medicineId: 'med-1', medicineName: 'Aspirin', quantity: 30, unit: 'tablet' as never },
|
||||
],
|
||||
},
|
||||
'hh1',
|
||||
'user-1',
|
||||
|
|
@ -160,7 +205,11 @@ describe(RefillsService.name, () => {
|
|||
it('creates list with no items when neither fromAlerts nor items provided', async () => {
|
||||
mockRepo.create.mockResolvedValue({ _id: 'rl-1', items: [] });
|
||||
|
||||
await service.createList({ name: 'Empty List', fromAlerts: false, thresholdDays: 7 }, 'hh1', 'user-1');
|
||||
await service.createList(
|
||||
{ name: 'Empty List', fromAlerts: false, thresholdDays: 7 },
|
||||
'hh1',
|
||||
'user-1',
|
||||
);
|
||||
|
||||
expect(mockRepo.create).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ items: [], totalEstimatedCost: undefined }),
|
||||
|
|
@ -176,8 +225,20 @@ describe(RefillsService.name, () => {
|
|||
fromAlerts: false,
|
||||
thresholdDays: 7,
|
||||
items: [
|
||||
{ medicineId: 'med-1', medicineName: 'Aspirin', quantity: 30, unit: 'tablet' as never, estimatedPrice: 10 },
|
||||
{ medicineId: 'med-2', medicineName: 'Ibuprofen', quantity: 20, unit: 'tablet' as never, estimatedPrice: 8 },
|
||||
{
|
||||
medicineId: 'med-1',
|
||||
medicineName: 'Aspirin',
|
||||
quantity: 30,
|
||||
unit: 'tablet' as never,
|
||||
estimatedPrice: 10,
|
||||
},
|
||||
{
|
||||
medicineId: 'med-2',
|
||||
medicineName: 'Ibuprofen',
|
||||
quantity: 20,
|
||||
unit: 'tablet' as never,
|
||||
estimatedPrice: 8,
|
||||
},
|
||||
],
|
||||
},
|
||||
'hh1',
|
||||
|
|
@ -191,20 +252,28 @@ describe(RefillsService.name, () => {
|
|||
|
||||
it('creates list from alerts when fromAlerts is true', async () => {
|
||||
mockRegimensService.calculateBurnRates.mockResolvedValue([
|
||||
{ medicineId: 'med-1', medicineName: 'Aspirin', dailyConsumption: 2, totalInCabinet: 5, daysUntilEmpty: 2 },
|
||||
{
|
||||
medicineId: 'med-1',
|
||||
medicineName: 'Aspirin',
|
||||
dailyConsumption: 2,
|
||||
totalInCabinet: 5,
|
||||
daysUntilEmpty: 2,
|
||||
},
|
||||
]);
|
||||
mockCabinetRepo.getAggregateSummary.mockResolvedValue([]);
|
||||
mockPricesRepo.getLatestForMedicine.mockResolvedValue(null);
|
||||
mockPricesRepo.compareStores.mockResolvedValue([]);
|
||||
mockRepo.create.mockResolvedValue({ _id: 'rl-1', items: [] });
|
||||
|
||||
await service.createList({ name: 'Auto List', fromAlerts: true, thresholdDays: 7 }, 'hh1', 'user-1');
|
||||
await service.createList(
|
||||
{ name: 'Auto List', fromAlerts: true, thresholdDays: 7 },
|
||||
'hh1',
|
||||
'user-1',
|
||||
);
|
||||
|
||||
expect(mockRepo.create).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
items: expect.arrayContaining([
|
||||
expect.objectContaining({ medicineId: 'med-1' }),
|
||||
]),
|
||||
items: expect.arrayContaining([expect.objectContaining({ medicineId: 'med-1' })]),
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
|
@ -251,7 +320,9 @@ describe(RefillsService.name, () => {
|
|||
it('throws NotFoundError when list not found', async () => {
|
||||
mockRepo.findById.mockResolvedValue(null);
|
||||
|
||||
await expect(service.updateList('missing', 'hh1', {})).rejects.toThrow('Refill list not found');
|
||||
await expect(service.updateList('missing', 'hh1', {})).rejects.toThrow(
|
||||
'Refill list not found',
|
||||
);
|
||||
});
|
||||
|
||||
it('throws NotFoundError when update returns null', async () => {
|
||||
|
|
@ -290,7 +361,9 @@ describe(RefillsService.name, () => {
|
|||
it('throws NotFoundError when list not found', async () => {
|
||||
mockRepo.findById.mockResolvedValue(null);
|
||||
|
||||
await expect(service.updateItem('missing', 'hh1', 'item-1', {})).rejects.toThrow('Refill list not found');
|
||||
await expect(service.updateItem('missing', 'hh1', 'item-1', {})).rejects.toThrow(
|
||||
'Refill list not found',
|
||||
);
|
||||
});
|
||||
|
||||
it('throws NotFoundError when item not found', async () => {
|
||||
|
|
@ -308,7 +381,15 @@ describe(RefillsService.name, () => {
|
|||
mockRepo.findById.mockResolvedValue({
|
||||
_id: 'rl-1',
|
||||
items: [
|
||||
{ _id: { toString: () => 'item-1' }, medicineId: 'med-1', medicineName: 'Aspirin', quantity: 30, unit: 'tablet', checked: true, addedToCabinet: false },
|
||||
{
|
||||
_id: { toString: () => 'item-1' },
|
||||
medicineId: 'med-1',
|
||||
medicineName: 'Aspirin',
|
||||
quantity: 30,
|
||||
unit: 'tablet',
|
||||
checked: true,
|
||||
addedToCabinet: false,
|
||||
},
|
||||
],
|
||||
});
|
||||
mockCabinetService.addItem.mockResolvedValue({ _id: 'ci-1' });
|
||||
|
|
@ -324,7 +405,16 @@ describe(RefillsService.name, () => {
|
|||
mockRepo.findById.mockResolvedValue({
|
||||
_id: 'rl-1',
|
||||
items: [
|
||||
{ _id: { toString: () => 'item-1' }, medicineId: 'med-1', medicineName: 'Aspirin', quantity: 30, unit: 'tablet', actualPrice: 9, checked: true, addedToCabinet: false },
|
||||
{
|
||||
_id: { toString: () => 'item-1' },
|
||||
medicineId: 'med-1',
|
||||
medicineName: 'Aspirin',
|
||||
quantity: 30,
|
||||
unit: 'tablet',
|
||||
actualPrice: 9,
|
||||
checked: true,
|
||||
addedToCabinet: false,
|
||||
},
|
||||
],
|
||||
});
|
||||
mockCabinetService.addItem.mockResolvedValue({ _id: 'ci-1' });
|
||||
|
|
@ -343,7 +433,15 @@ describe(RefillsService.name, () => {
|
|||
mockRepo.findById.mockResolvedValue({
|
||||
_id: 'rl-1',
|
||||
items: [
|
||||
{ _id: 'item-1', medicineId: 'med-1', medicineName: 'Aspirin', quantity: 30, unit: 'tablet', checked: false, addedToCabinet: false },
|
||||
{
|
||||
_id: 'item-1',
|
||||
medicineId: 'med-1',
|
||||
medicineName: 'Aspirin',
|
||||
quantity: 30,
|
||||
unit: 'tablet',
|
||||
checked: false,
|
||||
addedToCabinet: false,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
|
|
@ -357,7 +455,15 @@ describe(RefillsService.name, () => {
|
|||
mockRepo.findById.mockResolvedValue({
|
||||
_id: 'rl-1',
|
||||
items: [
|
||||
{ _id: 'item-1', medicineId: 'med-1', medicineName: 'Aspirin', quantity: 30, unit: 'tablet', checked: true, addedToCabinet: true },
|
||||
{
|
||||
_id: 'item-1',
|
||||
medicineId: 'med-1',
|
||||
medicineName: 'Aspirin',
|
||||
quantity: 30,
|
||||
unit: 'tablet',
|
||||
checked: true,
|
||||
addedToCabinet: true,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue