Add store location map manager #20
@ -269,7 +269,10 @@ async function getMapItems(db, householdId, locationId) {
|
||||
)
|
||||
WHERE hl.household_id = $1
|
||||
AND hl.store_location_id = $2
|
||||
AND hl.bought = FALSE
|
||||
AND (
|
||||
hl.bought = FALSE
|
||||
OR hl.modified_on >= NOW() - INTERVAL '24 hours'
|
||||
)
|
||||
ORDER BY resolved_zone.sort_order ASC NULLS LAST, hsi.name ASC`,
|
||||
[householdId, locationId]
|
||||
);
|
||||
|
||||
@ -72,16 +72,28 @@ describe("location-map.model", () => {
|
||||
label: "Published Bakery",
|
||||
};
|
||||
const zones = [{ id: 501, name: "Bakery", sort_order: 10, item_count: 1 }];
|
||||
const items = [{
|
||||
id: 3001,
|
||||
item_id: 2001,
|
||||
item_name: "sourdough",
|
||||
quantity: 1,
|
||||
bought: false,
|
||||
zone_id: 501,
|
||||
zone: "Bakery",
|
||||
added_by_users: ["Owner"],
|
||||
}];
|
||||
const items = [
|
||||
{
|
||||
id: 3001,
|
||||
item_id: 2001,
|
||||
item_name: "sourdough",
|
||||
quantity: 1,
|
||||
bought: false,
|
||||
zone_id: 501,
|
||||
zone: "Bakery",
|
||||
added_by_users: ["Owner"],
|
||||
},
|
||||
{
|
||||
id: 3002,
|
||||
item_id: 2002,
|
||||
item_name: "bagels",
|
||||
quantity: 1,
|
||||
bought: true,
|
||||
zone_id: 501,
|
||||
zone: "Bakery",
|
||||
added_by_users: ["Owner"],
|
||||
},
|
||||
];
|
||||
|
||||
storeModel.getLocationById.mockResolvedValue(location);
|
||||
pool.query.mockImplementation(async (sql, params = []) => {
|
||||
@ -151,6 +163,19 @@ describe("location-map.model", () => {
|
||||
expect(state.published_objects).toEqual([expect.objectContaining({ id: publishedObject.id })]);
|
||||
});
|
||||
|
||||
test("loads active and recent bought rows for map item layers", async () => {
|
||||
const { items } = mockMapStateQueries();
|
||||
|
||||
const state = await LocationMap.getMapState(1, 10, true);
|
||||
|
||||
expect(state.items).toEqual(items);
|
||||
expect(state.items.some((item) => item.bought)).toBe(true);
|
||||
expect(pool.query).toHaveBeenCalledWith(
|
||||
expect.stringContaining("OR hl.modified_on >= NOW() - INTERVAL '24 hours'"),
|
||||
[1, 10]
|
||||
);
|
||||
});
|
||||
|
||||
test("unlinks saved map objects from zones outside the current location", async () => {
|
||||
const client = createClient();
|
||||
pool.connect.mockResolvedValue(client);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user