|
8 | 8 | persistResolvedAccountSelection, |
9 | 9 | resolveAccountSelection, |
10 | 10 | resolveAndPersistAccountSelection, |
| 11 | + type AccountSelectionResult, |
11 | 12 | type TokenSuccessWithAccount, |
12 | 13 | } from "../lib/auth/login-runner.js"; |
13 | 14 | import { loadAccounts, setStoragePathDirect } from "../lib/storage.js"; |
@@ -125,6 +126,34 @@ describe("login-runner selection finalization", () => { |
125 | 126 | expect(updated.variantsForPersistence).toHaveLength(selection.variantsForPersistence.length); |
126 | 127 | }); |
127 | 128 |
|
| 129 | + it("updates cloned primary variants without relying on object identity", () => { |
| 130 | + const primary: TokenSuccessWithAccount = { |
| 131 | + type: "success", |
| 132 | + access: "access-token", |
| 133 | + refresh: "refresh-token", |
| 134 | + expires: Date.now() + 60_000, |
| 135 | + idToken: "id-token", |
| 136 | + accountIdOverride: "resolved-account", |
| 137 | + accountIdSource: "token", |
| 138 | + }; |
| 139 | + const selection: AccountSelectionResult = { |
| 140 | + primary, |
| 141 | + variantsForPersistence: [{ ...primary }], |
| 142 | + }; |
| 143 | + |
| 144 | + const updated = applyAccountSelectionFallbacks(selection, { |
| 145 | + organizationIdOverride: "resolved-org", |
| 146 | + accountLabel: "Resolved label", |
| 147 | + }); |
| 148 | + |
| 149 | + expect(updated.primary.organizationIdOverride).toBe("resolved-org"); |
| 150 | + expect(updated.primary.accountLabel).toBe("Resolved label"); |
| 151 | + expect(updated.variantsForPersistence).toHaveLength(1); |
| 152 | + expect(updated.variantsForPersistence[0]).toBe(updated.primary); |
| 153 | + expect(updated.variantsForPersistence[0]?.organizationIdOverride).toBe("resolved-org"); |
| 154 | + expect(updated.variantsForPersistence[0]?.accountLabel).toBe("Resolved label"); |
| 155 | + }); |
| 156 | + |
128 | 157 | it("resolves and persists the selected variants through the shared callback", async () => { |
129 | 158 | const persistSelections = vi.fn(async () => {}); |
130 | 159 | const result = await resolveAndPersistAccountSelection( |
|
0 commit comments