fix: expose client fetch and signed adjustments
This commit is contained in:
@@ -40,3 +40,27 @@ test("meter distinguishes refusals from storage faults", async () => {
|
||||
fault: true,
|
||||
});
|
||||
});
|
||||
|
||||
test("adjust accepts signed non-zero amounts while other additions stay positive", async () => {
|
||||
const writes: number[] = [];
|
||||
const meter = defineMeter({
|
||||
store: {
|
||||
balance: async () => 0,
|
||||
reserve: async () => true,
|
||||
write: async (_subject, units) => {
|
||||
writes.push(units);
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(await meter.adjust("u1", -25, "correction")).toEqual({ ok: true });
|
||||
expect(await meter.adjust("u1", 10, "correction")).toEqual({ ok: true });
|
||||
expect(await meter.adjust("u1", 0, "correction")).toEqual({
|
||||
ok: false,
|
||||
reason: "units adjustment must be a non-zero whole number",
|
||||
});
|
||||
expect(await meter.grant("u1", -1, "invalid")).toEqual({
|
||||
ok: false,
|
||||
reason: "units must be a positive whole number",
|
||||
});
|
||||
expect(writes).toEqual([-25, 10]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user