Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PDE-4304] fix(core): z.cursor.set() returns TypeError with non-string arguments #705

Merged
merged 1 commit into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
});