chore: enable unit tests

This commit is contained in:
Yordis Prieto
2024-10-18 12:32:57 -04:00
parent 1f396dffec
commit 4afa3c00ae
5 changed files with 179 additions and 138 deletions

View File

@@ -1,20 +1,24 @@
import { Int32Value, Int32ValueSchema, StringValueSchema } from "@bufbuild/protobuf/wkt";
import { Int32Value } from "@bufbuild/protobuf/wkt";
import { compileService } from "@bufbuild/protocompile";
import { createRouterTransport, HandlerContext } from "@connectrpc/connect";
import { describe, expect, test, vitest } from "vitest";
import { NewAuthorizationBearerInterceptor } from "./interceptors";
const TestService = {
typeName: "handwritten.TestService",
methods: {
unary: {
input: Int32ValueSchema,
output: StringValueSchema,
methodKind: "unary",
},
},
} as const;
const TestService = compileService(`
syntax = "proto3";
package handwritten;
service TestService {
rpc Unary(Int32Value) returns (StringValue);
}
message Int32Value {
int32 value = 1;
}
message StringValue {
string value = 1;
}
`);
describe.skip("NewAuthorizationBearerInterceptor", () => {
describe("NewAuthorizationBearerInterceptor", () => {
const transport = {
interceptors: [NewAuthorizationBearerInterceptor("mytoken")],
};
@@ -25,13 +29,13 @@ describe.skip("NewAuthorizationBearerInterceptor", () => {
});
const service = createRouterTransport(
({ service }) => {
service(TestService, { unary: handler });
({ rpc }) => {
rpc(TestService.method.unary, handler);
},
{ transport },
);
await service.unary(TestService, TestService.methods.unary, undefined, undefined, {}, { value: 9001 });
await service.unary(TestService.method.unary, undefined, undefined, {}, { value: 9001 });
expect(handler).toBeCalled();
expect(handler.mock.calls[0][1].requestHeader.get("Authorization")).toBe("Bearer mytoken");
@@ -43,14 +47,14 @@ describe.skip("NewAuthorizationBearerInterceptor", () => {
});
const service = createRouterTransport(
({ service }) => {
service(TestService, { unary: handler });
({ rpc }) => {
rpc(TestService.method.unary, handler);
},
{ transport },
);
await service.unary(
TestService.methods.unary,
TestService.method.unary,
undefined,
undefined,
{ Authorization: "Bearer somethingelse" },