Files
yaak/plugins/action-copy-grpcurl/tests/index.test.ts
Gregory Schier b4a1c418bb Run oxfmt across repo, add format script and docs
Add .oxfmtignore to skip generated bindings and wasm-pack output.
Add npm format script, update DEVELOPMENT.md for Vite+ toolchain,
and format all non-generated files with oxfmt.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 10:15:49 -07:00

179 lines
4.7 KiB
TypeScript

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 "),
);
});
});