Skip to content

Commit

Permalink
Added aother test
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-sachs committed Oct 26, 2023
1 parent 3a35a26 commit b01b18e
Showing 1 changed file with 50 additions and 13 deletions.
63 changes: 50 additions & 13 deletions packages/connect/src/router-transport.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { createAsyncIterable } from "./protocol/async-iterable.js";
import { createRouterTransport } from "./router-transport.js";
import { ConnectError } from "./connect-error.js";
import { Code } from "./code.js";
import { MethodType } from "./method-type.js";

describe("createRoutesTransport", function () {
const testService = {
Expand Down Expand Up @@ -226,22 +227,58 @@ describe("createRoutesTransport", function () {
});
});
describe("supports self describing method type", function () {
const methodDefinition = {
name: "Unary",
kind: MethodKind.Unary,
I: Int32Value,
O: StringValue,
service: testService,
idempotency: MethodIdempotency.NoSideEffects,
} as const;
const transport = createRouterTransport(({ rpc }) => {
rpc(methodDefinition, (request) => {
return { value: `${request.value}-RESPONSE` };
it("should work for unary", async function () {
const methodDefinition = {
name: "Unary",
kind: MethodKind.Unary,
I: Int32Value,
O: StringValue,
service: testService,
idempotency: MethodIdempotency.NoSideEffects,
} as const;
const transport = createRouterTransport(({ rpc }) => {
rpc(methodDefinition, (request) => {
return { value: `${request.value}-RESPONSE` };
});
});

const client = createPromiseClient(testService, transport);

const res = await client.unary({ value: 13 });
expect(res.value).toBe("13-RESPONSE");
});

const client = createPromiseClient(testService, transport);
it("should work for unary", async function () {
it("should work with method built from service", async function () {
const methodDefinition = {
...testService.methods.unary,
service: testService,
} as const;
const transport = createRouterTransport(({ rpc }) => {
rpc(methodDefinition, (request) => {
return { value: `${request.value}-RESPONSE` };
});
});

const client = createPromiseClient(testService, transport);

const res = await client.unary({ value: 13 });
expect(res.value).toBe("13-RESPONSE");
});

it("should work with method built with explicit type", async function () {
const methodDefinition: MethodType<Int32Value, StringValue> = {
...testService.methods.unary,
service: testService,
};

const transport = createRouterTransport(({ rpc }) => {
rpc(methodDefinition, (request) => {
return { value: `${request.value}-RESPONSE` };
});
});

const client = createPromiseClient(testService, transport);

const res = await client.unary({ value: 13 });
expect(res.value).toBe("13-RESPONSE");
});
Expand Down

0 comments on commit b01b18e

Please sign in to comment.