Add tests

This commit is contained in:
Adria Navarro 2023-12-01 10:23:47 +01:00
parent f62dd56dd6
commit 14fc91d58a
2 changed files with 18 additions and 6 deletions

View File

@ -190,15 +190,9 @@ export async function doInAppMigrationContext<T>(
appId: string,
task: () => T
): Promise<T> {
try {
return _doInAppContext(appId, task, {
isMigrating: true,
})
} finally {
updateContext({
isMigrating: undefined,
})
}
}
export function getIdentity(): IdentityContext | undefined {

View File

@ -179,5 +179,23 @@ describe("context", () => {
expect(context).toEqual(expected)
})
})
it("the context is not modified outside the delegate", async () => {
const appId = db.generateAppID()
expect(Context.get()).toBeUndefined()
await context.doInAppMigrationContext(appId, () => {
const context = Context.get()
const expected: ContextMap = {
appId,
isMigrating: true,
}
expect(context).toEqual(expected)
})
expect(Context.get()).toBeUndefined()
})
})
})