diff --git a/plugins/action-copy-grpcurl/src/index.ts b/plugins/action-copy-grpcurl/src/index.ts index bec5dde0..b332957d 100644 --- a/plugins/action-copy-grpcurl/src/index.ts +++ b/plugins/action-copy-grpcurl/src/index.ts @@ -11,7 +11,7 @@ export const plugin: PluginDefinition = { async onSelect(ctx, args) { const rendered_request = await ctx.grpcRequest.render({ grpcRequest: args.grpcRequest, - purpose: 'preview', + purpose: 'send', }); const data = await convert(rendered_request, args.protoFiles); await ctx.clipboard.copyText(data); @@ -103,7 +103,7 @@ export async function convert(request: Partial, allProtoFiles: stri // Add form params if (request.message) { - xs.push('-d', `${quote(JSON.stringify(JSON.parse(request.message)))}`); + xs.push('-d', quote(request.message)); xs.push(NEWLINE); } diff --git a/plugins/action-copy-grpcurl/tests/index.test.ts b/plugins/action-copy-grpcurl/tests/index.test.ts index 31910c98..51d43d02 100644 --- a/plugins/action-copy-grpcurl/tests/index.test.ts +++ b/plugins/action-copy-grpcurl/tests/index.test.ts @@ -151,7 +151,26 @@ describe('exporter-curl', () => { [ `grpcurl -import-path '/'`, `-proto '/foo.proto'`, - `-d '{"foo":"bar","baz":1}'`, + `-d '{\n "foo": "bar",\n "baz": 1\n}'`, + 'yaak.app', + ].join(' \\\n '), + ); + }); + + test('Sends data with unresolved template tags', async () => { + expect( + await convert( + { + url: 'https://yaak.app', + message: '{"timestamp": ${[ faker "timestamp" ]}, "foo": "bar"}', + }, + ['/foo.proto'], + ), + ).toEqual( + [ + `grpcurl -import-path '/'`, + `-proto '/foo.proto'`, + `-d '{"timestamp": \${[ faker "timestamp" ]}, "foo": "bar"}'`, 'yaak.app', ].join(' \\\n '), );