From 14fc91d58a5a8880be025c570fa0170a8f336162 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 1 Dec 2023 10:23:47 +0100 Subject: [PATCH] Add tests --- .../backend-core/src/context/mainContext.ts | 6 ------ .../src/context/tests/index.spec.ts | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/packages/backend-core/src/context/mainContext.ts b/packages/backend-core/src/context/mainContext.ts index 1cbf1de1c3..1a4d6db454 100644 --- a/packages/backend-core/src/context/mainContext.ts +++ b/packages/backend-core/src/context/mainContext.ts @@ -190,15 +190,9 @@ export async function doInAppMigrationContext( appId: string, task: () => T ): Promise { - try { return _doInAppContext(appId, task, { isMigrating: true, }) - } finally { - updateContext({ - isMigrating: undefined, - }) - } } export function getIdentity(): IdentityContext | undefined { diff --git a/packages/backend-core/src/context/tests/index.spec.ts b/packages/backend-core/src/context/tests/index.spec.ts index ef7cf17e0c..4bfbea74ce 100644 --- a/packages/backend-core/src/context/tests/index.spec.ts +++ b/packages/backend-core/src/context/tests/index.spec.ts @@ -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() + }) }) })