( session: ResolvedAuthSession, fn: () => T, )
| 115 | } |
| 116 | |
| 117 | function withMockCurrentSession<T>( |
| 118 | session: ResolvedAuthSession, |
| 119 | fn: () => T, |
| 120 | ): T { |
| 121 | const runtime = getAuthRuntime() |
| 122 | const originalGetCurrentSession = runtime.getCurrentSession.bind(runtime) |
| 123 | ;( |
| 124 | runtime as { |
| 125 | getCurrentSession: typeof runtime.getCurrentSession |
| 126 | } |
| 127 | ).getCurrentSession = () => session |
| 128 | |
| 129 | try { |
| 130 | return fn() |
| 131 | } finally { |
| 132 | ;( |
| 133 | runtime as { |
| 134 | getCurrentSession: typeof runtime.getCurrentSession |
| 135 | } |
| 136 | ).getCurrentSession = originalGetCurrentSession |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | afterEach(() => { |
| 141 | restoreEnv() |
no test coverage detected