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

Function withMockCurrentSession

src/utils/user.test.ts:127–148  ·  view source on GitHub ↗
(
  session: ResolvedAuthSession,
  fn: () => T,
)

Source from the content-addressed store, hash-verified

125}
126
127function withMockCurrentSession<T>(
128 session: ResolvedAuthSession,
129 fn: () => T,
130): T {
131 const runtime = getAuthRuntime()
132 const originalGetCurrentSession = runtime.getCurrentSession.bind(runtime)
133 ;(
134 runtime as {
135 getCurrentSession: typeof runtime.getCurrentSession
136 }
137 ).getCurrentSession = () => session
138
139 try {
140 return fn()
141 } finally {
142 ;(
143 runtime as {
144 getCurrentSession: typeof runtime.getCurrentSession
145 }
146 ).getCurrentSession = originalGetCurrentSession
147 }
148}
149
150beforeAll(async () => {
151 tempConfigDir = await mkdtemp(join(tmpdir(), 'ncode-user-test-'))

Callers 1

user.test.tsFile · 0.70

Calls 1

getAuthRuntimeFunction · 0.85

Tested by

no test coverage detected