Add store location map manager #20
@ -269,7 +269,10 @@ async function getMapItems(db, householdId, locationId) {
|
|||||||
)
|
)
|
||||||
WHERE hl.household_id = $1
|
WHERE hl.household_id = $1
|
||||||
AND hl.store_location_id = $2
|
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`,
|
ORDER BY resolved_zone.sort_order ASC NULLS LAST, hsi.name ASC`,
|
||||||
[householdId, locationId]
|
[householdId, locationId]
|
||||||
);
|
);
|
||||||
|
|||||||
@ -72,7 +72,8 @@ describe("location-map.model", () => {
|
|||||||
label: "Published Bakery",
|
label: "Published Bakery",
|
||||||
};
|
};
|
||||||
const zones = [{ id: 501, name: "Bakery", sort_order: 10, item_count: 1 }];
|
const zones = [{ id: 501, name: "Bakery", sort_order: 10, item_count: 1 }];
|
||||||
const items = [{
|
const items = [
|
||||||
|
{
|
||||||
id: 3001,
|
id: 3001,
|
||||||
item_id: 2001,
|
item_id: 2001,
|
||||||
item_name: "sourdough",
|
item_name: "sourdough",
|
||||||
@ -81,7 +82,18 @@ describe("location-map.model", () => {
|
|||||||
zone_id: 501,
|
zone_id: 501,
|
||||||
zone: "Bakery",
|
zone: "Bakery",
|
||||||
added_by_users: ["Owner"],
|
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);
|
storeModel.getLocationById.mockResolvedValue(location);
|
||||||
pool.query.mockImplementation(async (sql, params = []) => {
|
pool.query.mockImplementation(async (sql, params = []) => {
|
||||||
@ -151,6 +163,19 @@ describe("location-map.model", () => {
|
|||||||
expect(state.published_objects).toEqual([expect.objectContaining({ id: publishedObject.id })]);
|
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 () => {
|
test("unlinks saved map objects from zones outside the current location", async () => {
|
||||||
const client = createClient();
|
const client = createClient();
|
||||||
pool.connect.mockResolvedValue(client);
|
pool.connect.mockResolvedValue(client);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user