shareImportIntent.test.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { describe, expect, it } from "vitest";
  2. import {
  3. createShareImportIntent,
  4. isShareImportIntentSame,
  5. resolveShareImportFailurePresentation,
  6. type ShareImportIntent,
  7. } from "../src/root/shareImportIntent.js";
  8. describe("share import intent", () => {
  9. it.each(["network", "service_unavailable", "unknown", "rate_limited"])(
  10. "keeps transport failure %s retryable",
  11. (kind) => {
  12. expect(resolveShareImportFailurePresentation(kind).retryable).toBe(true);
  13. },
  14. );
  15. it("keeps actual contract corruption non-retryable", () => {
  16. expect(resolveShareImportFailurePresentation("invalid_contract")).toEqual({
  17. messageId: "conversationShare.import.integrityFailed",
  18. retryable: false,
  19. });
  20. });
  21. it.each([
  22. ["import_not_allowed", "conversationShare.import.notAllowed"],
  23. ["not_found", "conversationShare.import.notFound"],
  24. ["expired", "conversationShare.import.expired"],
  25. ["unsupported_schema_version", "conversationShare.import.unsupportedVersion"],
  26. ])("does not offer an ineffective retry for %s", (kind, messageId) => {
  27. expect(resolveShareImportFailurePresentation(kind)).toEqual({ messageId, retryable: false });
  28. });
  29. it("creates one stable request id for retries", () => {
  30. const intent = createShareImportIntent("share-1", () => "request-1");
  31. expect(intent).toEqual({
  32. shareCode: "share-1",
  33. clientRequestId: "request-1",
  34. status: "received",
  35. });
  36. });
  37. it("coalesces duplicate deep links by request identity", () => {
  38. const first: ShareImportIntent = {
  39. shareCode: "share-1",
  40. clientRequestId: "request-1",
  41. status: "importing",
  42. };
  43. expect(isShareImportIntentSame(first, { shareCode: "share-1" })).toBe(true);
  44. expect(isShareImportIntentSame(first, { shareCode: "share-2" })).toBe(false);
  45. });
  46. it("presents authentication failures as non-retryable anonymous import restrictions", () => {
  47. expect(resolveShareImportFailurePresentation("authentication_required")).toEqual({
  48. messageId: "conversationShare.import.loginRequired",
  49. retryable: false,
  50. });
  51. expect(resolveShareImportFailurePresentation("network")).toEqual({
  52. messageId: "conversationShare.error.network",
  53. retryable: true,
  54. });
  55. });
  56. });