Skip to content

Commit

Permalink
fix(core): z.cursor.set() returns TypeError with non-string arguments (
Browse files Browse the repository at this point in the history
…#705)

Co-authored-by: Raúl Negrón <[email protected]>
  • Loading branch information
rnegron and rnegron authored Sep 21, 2023
1 parent ca5b698 commit 1ab1636
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/core/src/tools/create-storekey-tool.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,18 @@ const createStoreKeyTool = (input) => {

return rpc('get_cursor');
},

set: (cursor) => {
if (!rpc) {
return ZapierPromise.reject(new Error('rpc is not available'));
}

if (!_.isString(cursor)) {
return ZapierPromise.reject(
new TypeError('cursor value must be a string')
);
}

return rpc('set_cursor', cursor);
},
};
Expand Down
41 changes: 41 additions & 0 deletions packages/core/test/tools/create-storekey-tools.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use strict';

const should = require('should');

const { makeRpc, mockRpcCall } = require('./mocky');
const createStoreKeyTool = require('../../src/tools/create-storekey-tool');

describe('storekey (cursor): get, set', () => {
const rpc = makeRpc();
const cursor = createStoreKeyTool({ _zapier: { rpc } });

it('storekey (cursor) get: should return the cursor value given a key', async () => {
const expected = 64;
mockRpcCall(expected);

const result = await cursor.get('existing-key');
should(result).eql(expected);
});

it('storekey (cursor) set: should raise TypeError on non-string value', async () => {
await should(cursor.set(64)).rejectedWith(TypeError, {
message: 'cursor value must be a string',
});

await should(cursor.set(null)).rejectedWith(TypeError, {
message: 'cursor value must be a string',
});

await should(cursor.set(undefined)).rejectedWith(TypeError, {
message: 'cursor value must be a string',
});
});

it('storekey (cursor) set: should set a cursor entry', async () => {
const expected = 'ok';
mockRpcCall(expected);

const result1 = await cursor.set('test-key');
should(result1).eql(expected);
});
});

0 comments on commit 1ab1636

Please sign in to comment.