Skip to content

Commit

Permalink
Fix type error for web mock utils
Browse files Browse the repository at this point in the history
  • Loading branch information
cakecatz committed May 20, 2021
1 parent 86e8767 commit 0aa0c8b
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions pkg/app/web/src/mocks/create-handler.ts
Expand Up @@ -14,15 +14,18 @@ export function createHandler<T extends { serializeBinary(): Uint8Array }>(
serviceName: string,
getResponseMessage: (requestData: Uint8Array) => T
): HandlerType {
return rest.post(createMask(serviceName), (req, res, ctx) => {
const arr: Uint8Array =
typeof req.body === "string" ? encoder.encode(req.body) : req.body;
const message = getResponseMessage(arr.slice(5));
const data = serialize(message.serializeBinary());
return res(
ctx.status(200),
ctx.set("Content-Type", "application/grpc-web+proto"),
ctx.body(data)
);
});
return rest.post<Uint8Array | string>(
createMask(serviceName),
(req, res, ctx) => {
const arr: Uint8Array =
typeof req.body === "string" ? encoder.encode(req.body) : req.body;
const message = getResponseMessage(arr.slice(5));
const data = serialize(message.serializeBinary());
return res(
ctx.status(200),
ctx.set("Content-Type", "application/grpc-web+proto"),
ctx.body(data)
);
}
);
}

0 comments on commit 0aa0c8b

Please sign in to comment.