1import { describe, expect, it, vi } from "@effect/vitest";
2import type { SharePayload } from "expo-sharing";
3
4import { createIncomingSharePayloadReader } from "./incoming-share-native";
5
6const PAYLOAD: SharePayload = {
7 shareType: "text",
8 mimeType: "text/plain",
9 value: "Fix this",
10};
11
12describe("createIncomingSharePayloadReader", () => {
13 it("treats a missing iOS App Group as an unavailable inbox", () => {
14 const readPayloads = vi.fn((): ReadonlyArray<SharePayload> => {
15 throw Object.assign(new Error("Expo-sharing has failed to fetch the app group id"), {
16 code: "ERR_FAILED_TO_RESOLVE_APP_GROUP_ID",
17 });
18 });
19 const read = createIncomingSharePayloadReader({ platform: "ios", readPayloads });
20
21 expect(read()).toEqual([]);
22 expect(read()).toEqual([]);
23 expect(readPayloads).toHaveBeenCalledTimes(1);
24 });
25
26 it("returns native payloads when receiving is available", () => {
27 const read = createIncomingSharePayloadReader({
28 platform: "ios",
29 readPayloads: () => [PAYLOAD],
30 });
31
32 expect(read()).toEqual([PAYLOAD]);
33 });
34
35 it("preserves other native errors", () => {
36 const error = new Error("native failure");
37 const read = createIncomingSharePayloadReader({
38 platform: "ios",
39 readPayloads: () => {
40 throw error;
41 },
42 });
43
44 expect(read).toThrow(error);
45 });
46});