app-launch-coordinator.test.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import { describe, expect, it } from "vitest";
  2. describe("app launch coordinator", () => {
  3. it("sends app_launch immediately when no OAuth callback is pending", async () => {
  4. const { createAppLaunchCoordinator } = await import("../src/main/appLaunchCoordinator.js");
  5. const gate = {
  6. consumeCalls: 0,
  7. consume() {
  8. this.consumeCalls += 1;
  9. return true;
  10. },
  11. };
  12. const coordinator = createAppLaunchCoordinator(gate);
  13. expect(
  14. coordinator.onRendererReady({
  15. hasPendingOAuthCallback: false,
  16. rendererId: 1,
  17. }),
  18. ).toBe(true);
  19. expect(coordinator.onOAuthCallbackHandled({ rendererId: 1 })).toBe(false);
  20. expect(gate.consumeCalls).toBe(1);
  21. });
  22. it("waits for OAuth callback handling before sending delayed app_launch", async () => {
  23. const { createAppLaunchCoordinator } = await import("../src/main/appLaunchCoordinator.js");
  24. const gate = {
  25. consumed: false,
  26. consume() {
  27. if (this.consumed) {
  28. return false;
  29. }
  30. this.consumed = true;
  31. return true;
  32. },
  33. };
  34. const coordinator = createAppLaunchCoordinator(gate);
  35. expect(
  36. coordinator.onRendererReady({
  37. hasPendingOAuthCallback: true,
  38. rendererId: 1,
  39. }),
  40. ).toBe(false);
  41. expect(coordinator.onOAuthCallbackHandled({ rendererId: 1 })).toBe(true);
  42. expect(coordinator.onOAuthCallbackHandled({ rendererId: 1 })).toBe(false);
  43. expect(
  44. coordinator.onRendererReady({
  45. hasPendingOAuthCallback: false,
  46. rendererId: 1,
  47. }),
  48. ).toBe(false);
  49. });
  50. it("does not let another renderer consume app_launch while waiting for OAuth callback", async () => {
  51. const { createAppLaunchCoordinator } = await import("../src/main/appLaunchCoordinator.js");
  52. const gate = {
  53. consumed: false,
  54. consume() {
  55. if (this.consumed) {
  56. return false;
  57. }
  58. this.consumed = true;
  59. return true;
  60. },
  61. };
  62. const coordinator = createAppLaunchCoordinator(gate);
  63. expect(
  64. coordinator.onRendererReady({
  65. hasPendingOAuthCallback: true,
  66. rendererId: 1,
  67. }),
  68. ).toBe(false);
  69. expect(
  70. coordinator.onRendererReady({
  71. hasPendingOAuthCallback: false,
  72. rendererId: 2,
  73. }),
  74. ).toBe(false);
  75. expect(coordinator.onOAuthCallbackHandled({ rendererId: 2 })).toBe(false);
  76. expect(coordinator.onOAuthCallbackHandled({ rendererId: 1 })).toBe(true);
  77. });
  78. });