mirror of
https://github.com/HeyPuter/puter.git
synced 2026-09-09 14:55:47 +00:00
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:
@@ -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', () => {
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user