snapshot of https://github.com/mountain-loop/yaak.git (main, 2026-09-23; blobs > 131072B omitted)
This commit is contained in:
195
plugins/action-copy-grpcurl/tests/index.test.ts
Normal file
195
plugins/action-copy-grpcurl/tests/index.test.ts
Normal file
@@ -0,0 +1,195 @@
|
||||
import { describe, expect, test } from "vite-plus/test";
|
||||
import { convert } from "../src";
|
||||
|
||||
describe("exporter-curl", () => {
|
||||
test("Simple example", async () => {
|
||||
expect(
|
||||
await convert(
|
||||
{
|
||||
url: "https://yaak.app",
|
||||
},
|
||||
[],
|
||||
),
|
||||
).toEqual(["grpcurl yaak.app"].join(" \\\n "));
|
||||
});
|
||||
test("Basic metadata", async () => {
|
||||
expect(
|
||||
await convert(
|
||||
{
|
||||
url: "https://yaak.app",
|
||||
metadata: [
|
||||
{ name: "aaa", value: "AAA" },
|
||||
{ enabled: true, name: "bbb", value: "BBB" },
|
||||
{ enabled: false, name: "disabled", value: "ddd" },
|
||||
],
|
||||
},
|
||||
[],
|
||||
),
|
||||
).toEqual([`grpcurl -H 'aaa: AAA'`, `-H 'bbb: BBB'`, "yaak.app"].join(" \\\n "));
|
||||
});
|
||||
test("Basic auth", async () => {
|
||||
expect(
|
||||
await convert(
|
||||
{
|
||||
url: "https://yaak.app",
|
||||
authenticationType: "basic",
|
||||
authentication: {
|
||||
username: "user",
|
||||
password: "pass",
|
||||
},
|
||||
},
|
||||
[],
|
||||
),
|
||||
).toEqual([`grpcurl -H 'Authorization: Basic dXNlcjpwYXNz'`, "yaak.app"].join(" \\\n "));
|
||||
});
|
||||
|
||||
test("API key auth", async () => {
|
||||
expect(
|
||||
await convert(
|
||||
{
|
||||
url: "https://yaak.app",
|
||||
authenticationType: "apikey",
|
||||
authentication: {
|
||||
key: "X-Token",
|
||||
value: "tok",
|
||||
},
|
||||
},
|
||||
[],
|
||||
),
|
||||
).toEqual([`grpcurl -H 'X-Token: tok'`, "yaak.app"].join(" \\\n "));
|
||||
});
|
||||
|
||||
test("API key auth", async () => {
|
||||
expect(
|
||||
await convert(
|
||||
{
|
||||
url: "https://yaak.app",
|
||||
authenticationType: "apikey",
|
||||
authentication: {
|
||||
location: "query",
|
||||
key: "token",
|
||||
value: "tok 1",
|
||||
},
|
||||
},
|
||||
[],
|
||||
),
|
||||
).toEqual(["grpcurl", "yaak.app?token=tok%201"].join(" \\\n "));
|
||||
});
|
||||
|
||||
test("Single proto file", async () => {
|
||||
expect(await convert({ url: "https://yaak.app" }, ["/foo/bar/baz.proto"])).toEqual(
|
||||
[
|
||||
`grpcurl -import-path '/foo/bar'`,
|
||||
`-import-path '/foo'`,
|
||||
`-proto '/foo/bar/baz.proto'`,
|
||||
"yaak.app",
|
||||
].join(" \\\n "),
|
||||
);
|
||||
});
|
||||
test("Multiple proto files, same dir", async () => {
|
||||
expect(
|
||||
await convert({ url: "https://yaak.app" }, ["/foo/bar/aaa.proto", "/foo/bar/bbb.proto"]),
|
||||
).toEqual(
|
||||
[
|
||||
`grpcurl -import-path '/foo/bar'`,
|
||||
`-import-path '/foo'`,
|
||||
`-proto '/foo/bar/aaa.proto'`,
|
||||
`-proto '/foo/bar/bbb.proto'`,
|
||||
"yaak.app",
|
||||
].join(" \\\n "),
|
||||
);
|
||||
});
|
||||
test("Multiple proto files, different dir", async () => {
|
||||
expect(
|
||||
await convert({ url: "https://yaak.app" }, ["/aaa/bbb/ccc.proto", "/xxx/yyy/zzz.proto"]),
|
||||
).toEqual(
|
||||
[
|
||||
`grpcurl -import-path '/aaa/bbb'`,
|
||||
`-import-path '/aaa'`,
|
||||
`-import-path '/xxx/yyy'`,
|
||||
`-import-path '/xxx'`,
|
||||
`-proto '/aaa/bbb/ccc.proto'`,
|
||||
`-proto '/xxx/yyy/zzz.proto'`,
|
||||
"yaak.app",
|
||||
].join(" \\\n "),
|
||||
);
|
||||
});
|
||||
test("Single include dir", async () => {
|
||||
expect(await convert({ url: "https://yaak.app" }, ["/aaa/bbb"])).toEqual(
|
||||
[`grpcurl -import-path '/aaa/bbb'`, "yaak.app"].join(" \\\n "),
|
||||
);
|
||||
});
|
||||
test("Multiple include dir", async () => {
|
||||
expect(await convert({ url: "https://yaak.app" }, ["/aaa/bbb", "/xxx/yyy"])).toEqual(
|
||||
[`grpcurl -import-path '/aaa/bbb'`, `-import-path '/xxx/yyy'`, "yaak.app"].join(" \\\n "),
|
||||
);
|
||||
});
|
||||
test("Mixed proto and dirs", async () => {
|
||||
expect(
|
||||
await convert({ url: "https://yaak.app" }, ["/aaa/bbb", "/xxx/yyy", "/foo/bar.proto"]),
|
||||
).toEqual(
|
||||
[
|
||||
`grpcurl -import-path '/aaa/bbb'`,
|
||||
`-import-path '/xxx/yyy'`,
|
||||
`-import-path '/foo'`,
|
||||
`-import-path '/'`,
|
||||
`-proto '/foo/bar.proto'`,
|
||||
"yaak.app",
|
||||
].join(" \\\n "),
|
||||
);
|
||||
});
|
||||
test("Sends data", async () => {
|
||||
expect(
|
||||
await convert(
|
||||
{
|
||||
url: "https://yaak.app",
|
||||
message: JSON.stringify({ foo: "bar", baz: 1.0 }, null, 2),
|
||||
},
|
||||
["/foo.proto"],
|
||||
),
|
||||
).toEqual(
|
||||
[
|
||||
`grpcurl -import-path '/'`,
|
||||
`-proto '/foo.proto'`,
|
||||
`-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 "),
|
||||
);
|
||||
});
|
||||
|
||||
test("Quotes an apostrophe so the command still parses", async () => {
|
||||
// POSIX single quotes take no escapes: `\'` ends the string one
|
||||
// character early and leaves the rest of the command dangling.
|
||||
const command = await convert(
|
||||
{
|
||||
url: "https://yaak.app",
|
||||
service: "Service",
|
||||
method: "Method",
|
||||
message: `{"note":"don't stop"}`,
|
||||
metadata: [{ name: "x-note", value: "it's fine" }],
|
||||
},
|
||||
[],
|
||||
);
|
||||
expect(command).toContain(`'{"note":"don'\\''t stop"}'`);
|
||||
expect(command).toContain(`'x-note: it'\\''s fine'`);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user