MCPcopy Create free account
hub / github.com/Noumena-Network/code / withMockCurrentSession

Function withMockCurrentSession

src/services/api/errors.auth.test.ts:192–213  ·  view source on GitHub ↗
(
  session: ResolvedAuthSession,
  fn: () => T,
)

Source from the content-addressed store, hash-verified

190}
191
192function withMockCurrentSession<T>(
193 session: ResolvedAuthSession,
194 fn: () => T,
195): T {
196 const runtime = getAuthRuntime()
197 const originalGetCurrentSession = runtime.getCurrentSession.bind(runtime)
198 ;(
199 runtime as {
200 getCurrentSession: typeof runtime.getCurrentSession
201 }
202 ).getCurrentSession = () => session
203
204 try {
205 return fn()
206 } finally {
207 ;(
208 runtime as {
209 getCurrentSession: typeof runtime.getCurrentSession
210 }
211 ).getCurrentSession = originalGetCurrentSession
212 }
213}
214
215beforeEach(async () => {
216 tempConfigDir = await mkdtemp(join(tmpdir(), 'ncode-errors-auth-test-'))

Callers 1

Calls 1

getAuthRuntimeFunction · 0.85

Tested by

no test coverage detected