( session: ResolvedAuthSession, fn: () => Promise<T> | T, )
| 185 | } |
| 186 | |
| 187 | async function withMockCurrentSession<T>( |
| 188 | session: ResolvedAuthSession, |
| 189 | fn: () => Promise<T> | T, |
| 190 | ): Promise<T> { |
| 191 | const runtime = getAuthRuntime() |
| 192 | const originalGetCurrentSession = runtime.getCurrentSession.bind(runtime) |
| 193 | ;( |
| 194 | runtime as { |
| 195 | getCurrentSession: typeof runtime.getCurrentSession |
| 196 | } |
| 197 | ).getCurrentSession = () => session |
| 198 | |
| 199 | try { |
| 200 | return await fn() |
| 201 | } finally { |
| 202 | ;( |
| 203 | runtime as { |
| 204 | getCurrentSession: typeof runtime.getCurrentSession |
| 205 | } |
| 206 | ).getCurrentSession = originalGetCurrentSession |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | async function waitUntil( |
| 211 | predicate: () => boolean, |
no test coverage detected