fix(puter-js): preserve zero amount in kv incr/decr (#3802)

parseCounterArgs used a falsy check, so incr(key, 0) sent amount 1. Only default when amount is undefined/null.
This commit is contained in:
Felix-Ayush
2026-09-08 22:30:02 -07:00
committed by GitHub
parent 8b872545dc
commit cdc524f504
2 changed files with 11 additions and 1 deletions
+10
View File
@@ -278,6 +278,11 @@ describe('kv.incr / kv.decr driver payloads', () => {
expect(lastBody().args).toEqual({ key: 'n', pathAndAmountMap: { '': 5 } });
});
it('incr(key, 0) preserves a zero amount instead of defaulting to 1', async () => {
await kv.incr('n', 0);
expect(lastBody().args).toEqual({ key: 'n', pathAndAmountMap: { '': 0 } });
});
it('incr(key, pathAndAmountMap) passes the map through', async () => {
await kv.incr('n', { 'user.score': 2 });
expect(lastBody().args).toEqual({ key: 'n', pathAndAmountMap: { 'user.score': 2 } });
@@ -326,6 +331,11 @@ describe('kv.incr / kv.decr driver payloads', () => {
await kv.decr('n', 4);
expect(lastBody().args).toEqual({ key: 'n', pathAndAmountMap: { '': 4 } });
});
it('decr(key, 0) preserves a zero amount instead of defaulting to 1', async () => {
await kv.decr('n', 0);
expect(lastBody().args).toEqual({ key: 'n', pathAndAmountMap: { '': 0 } });
});
});
describe('kv.add driver payloads', () => {
+1 -1
View File
@@ -63,7 +63,7 @@ export const parseCounterArgs = (keyOrOptions, amountOrMap, optConfig) => {
}
return {
key: keyOrOptions,
pathAndAmountMap: !amountOrMap ? { '': 1 } : typeof amountOrMap === 'number' ? { '': amountOrMap } : amountOrMap,
pathAndAmountMap: amountOrMap === undefined || amountOrMap === null ? { '': 1 } : typeof amountOrMap === 'number' ? { '': amountOrMap } : amountOrMap,
optConfig,
};
};