This commit is contained in:
seb
2026-10-13 22:23:45 +02:00
parent 8a626b17fc
commit 3256ab233d
4 changed files with 39 additions and 6 deletions

View File

@@ -143,46 +143,55 @@ async function run() {
// 1. Search Alice
const resAlice = await store.order.list(googleAuthId, { search: 'Alice' });
assert.equal(resAlice.total, 2, 'Should find 2 orders for Alice');
assert.equal(resAlice.unfilteredTotal, 4, 'Unfiltered total should be 4');
assert.deepEqual(resAlice.orders.map((o) => o.number), ['O-1003', 'O-1001']);
// 2. Search Bob
const resBob = await store.order.list(googleAuthId, { search: 'Bob' });
assert.equal(resBob.total, 2, 'Should find 2 orders for Bob');
assert.equal(resBob.unfilteredTotal, 4, 'Unfiltered total should be 4');
assert.deepEqual(resBob.orders.map((o) => o.number), ['O-1004', 'O-1002']);
// 3. Search 1002
const res1002 = await store.order.list(googleAuthId, { search: '1002' });
assert.equal(res1002.total, 1, 'Should find 1 order for 1002');
assert.equal(res1002.unfilteredTotal, 4, 'Unfiltered total should be 4');
assert.equal(res1002.orders[0].number, 'O-1002');
// 4. onlyUnpaid (O-1004 is overpaid, so it also counts as unpaid!)
const resUnpaid = await store.order.list(googleAuthId, { onlyUnpaid: true });
assert.equal(resUnpaid.total, 3, 'O-1004 (overpaid), O-1003 (unpaid), O-1002 (unpaid) are unpaid');
assert.equal(resUnpaid.unfilteredTotal, 4, 'Unfiltered total should be 4');
assert.deepEqual(resUnpaid.orders.map((o) => o.number), ['O-1004', 'O-1003', 'O-1002']);
// 5. onlyUndelivered
const resUndelivered = await store.order.list(googleAuthId, { onlyUndelivered: true });
assert.equal(resUndelivered.total, 2, 'O-1001 and O-1003 are undelivered');
assert.equal(resUndelivered.unfilteredTotal, 4, 'Unfiltered total should be 4');
assert.deepEqual(resUndelivered.orders.map((o) => o.number), ['O-1003', 'O-1001']);
// 6. onlyUnpaid AND onlyUndelivered
const resBoth = await store.order.list(googleAuthId, { onlyUnpaid: true, onlyUndelivered: true });
assert.equal(resBoth.total, 1, 'Only O-1003 is both unpaid and undelivered');
assert.equal(resBoth.unfilteredTotal, 4, 'Unfiltered total should be 4');
assert.equal(resBoth.orders[0].number, 'O-1003');
// 7. seekMonths -1 (orders older than 1 month)
const resSeek = await store.order.list(googleAuthId, { seekMonths: -1 });
assert.equal(resSeek.total, 1, 'Only O-1001 is older than 1 month');
assert.equal(resSeek.unfilteredTotal, 4, 'Unfiltered total should be 4');
assert.equal(resSeek.orders[0].number, 'O-1001');
// 8. Paging
const resPaged = await store.order.list(googleAuthId, { offset: 0, limit: 1 });
assert.equal(resPaged.total, 4);
assert.equal(resPaged.unfilteredTotal, 4);
assert.equal(resPaged.orders.length, 1);
assert.equal(resPaged.orders[0].number, 'O-1004');
const resPaged2 = await store.order.list(googleAuthId, { offset: 1, limit: 1 });
assert.equal(resPaged2.total, 4);
assert.equal(resPaged2.unfilteredTotal, 4);
assert.equal(resPaged2.orders.length, 1);
assert.equal(resPaged2.orders[0].number, 'O-1003');