Firebase Functions测试未能包装v2函数。

huangapple go评论46阅读模式
英文:

Firebase Functions Test fails to wrap v2 function

问题

我有2个 Firebase 函数,hello 在 v1 中,hello2 在 v2 中

import { https } from "firebase-functions";
import { onCall } from "firebase-functions/v2/https";

export const hello = https.onCall((request) => {
  return `Hello ${request.data.text}`;
});

export const hello2 = onCall((request) => {
  return `Hello ${request.data.text}`;
});

hello 可以使用 firebase-functions-test SDK 包装,没有问题,但 hello2 抛出错误。firebase-functions-test 只支持 v1,不支持 v2 吗?我该如何处理 v2 函数?

import { hello, hello2 } from ".";
import { expect } from "chai";
import { wrap } from "firebase-functions-test/lib/main";

describe("hello function", () => {
  it("returns expected output", async () => {
    // Create a test request object.
    const request = {
      body: {
        text: "World",
      },
    };

    const wrapped = wrap(hello);
    // The following line fails with No overload matches this call.
    const wrapped2 = wrap(hello2);

    const response = await wrapped(request);
    // The following line fails with Argument of type '{ body: { text: string; }; }' is not assignable to parameter of type 'CallableRequest<any>'.
    const response2 = await wrapped2(request);

    expect(response).equal("Hello World");
    expect(response2).equal("Hello World");
  });
});
英文:

I have 2 Firebase functions, hello in v1 and hello2 in v2

import { https } from &quot;firebase-functions&quot;;
import { onCall } from &quot;firebase-functions/v2/https&quot;;

export const hello = https.onCall((request) =&gt; {
  return `Hello ${request.data.text}`;
});

export const hello2 = onCall((request) =&gt; {
  return `Hello ${request.data.text}`;
});

hello can be wrapped with firebase-functions-test SDK with no issue, but hello2 throws an error. Is firebase-functions-test supports only v1 but not v2? How can I do this for v2 functions?

import { hello, hello2 } from &quot;.&quot;;
import { expect } from &quot;chai&quot;;
import { wrap } from &quot;firebase-functions-test/lib/main&quot;;

describe(&quot;hello function&quot;, () =&gt; {
  it(&quot;returns expected output&quot;, async () =&gt; {
    // Create a test request object.
    const request = {
      body: {
        text: &quot;World&quot;,
      },
    };

    const wrapped = wrap(hello);
    // The following line fails with No overload matches this call.
    const wrapped2 = wrap(hello2);

    const response = await wrapped(request);
    // The following line fails with Argument of type &#39;{ body: { text: string; }; }&#39; is not assignable to parameter of type &#39;CallableRequest&lt;any&gt;&#39;.
    const response2 = await wrapped2(request);

    expect(response).equal(&quot;Hello World&quot;);
    expect(response2).equal(&quot;Hello World&quot;);
  });
});

答案1

得分: 1

根据@samthecodingman在评论中提到的,根据firebase/firebase-functions-test Issue #163,截至目前,v2 onCall函数尚不受支持。

英文:

Answering as a Community Wiki, so that it may help others too.

As @samthecodingman mentioned in the comment, According to firebase/firebase-functions-test Issue #163, as of now v2 onCall functions are not yet supported.

huangapple
  • 本文由 发表于 2023年6月6日 07:03:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/76410496.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定