( session: ResolvedAuthSession, fn: () => T, )
| 136 | } |
| 137 | |
| 138 | function withMockCurrentSession<T>( |
| 139 | session: ResolvedAuthSession, |
| 140 | fn: () => T, |
| 141 | ): T { |
| 142 | const runtime = getAuthRuntime() |
| 143 | const originalGetCurrentSession = runtime.getCurrentSession.bind(runtime) |
| 144 | ;( |
| 145 | runtime as { |
| 146 | getCurrentSession: typeof runtime.getCurrentSession |
| 147 | } |
| 148 | ).getCurrentSession = () => session |
| 149 | |
| 150 | try { |
| 151 | return fn() |
| 152 | } finally { |
| 153 | ;( |
| 154 | runtime as { |
| 155 | getCurrentSession: typeof runtime.getCurrentSession |
| 156 | } |
| 157 | ).getCurrentSession = originalGetCurrentSession |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | afterEach(() => { |
| 162 | restoreEnv() |
no test coverage detected