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

Function withMockCurrentSession

src/utils/model/model.auth.test.ts:138–159  ·  view source on GitHub ↗
(
  session: ResolvedAuthSession,
  fn: () => T,
)

Source from the content-addressed store, hash-verified

136}
137
138function 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
161afterEach(() => {
162 restoreEnv()

Callers 1

model.auth.test.tsFile · 0.70

Calls 1

getAuthRuntimeFunction · 0.85

Tested by

no test coverage detected