( session: ResolvedAuthSession, fn: () => T, )
| 59 | } |
| 60 | |
| 61 | function withMockCurrentSession<T>( |
| 62 | session: ResolvedAuthSession, |
| 63 | fn: () => T, |
| 64 | ): T { |
| 65 | const runtime = getAuthRuntime() |
| 66 | const originalGetCurrentSession = runtime.getCurrentSession.bind(runtime) |
| 67 | ;( |
| 68 | runtime as { |
| 69 | getCurrentSession: typeof runtime.getCurrentSession |
| 70 | } |
| 71 | ).getCurrentSession = () => session |
| 72 | |
| 73 | try { |
| 74 | return fn() |
| 75 | } finally { |
| 76 | ;( |
| 77 | runtime as { |
| 78 | getCurrentSession: typeof runtime.getCurrentSession |
| 79 | } |
| 80 | ).getCurrentSession = originalGetCurrentSession |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | const originalBuildMode = process.env.NCODE_BUILD_MODE |
| 85 | const originalUserType = process.env.USER_TYPE |
no test coverage detected