diff --git a/packages/shared/common/__tests__/ContextFilter.test.ts b/packages/shared/common/__tests__/ContextFilter.test.ts index 3f1d7c0b1..17cd827cf 100644 --- a/packages/shared/common/__tests__/ContextFilter.test.ts +++ b/packages/shared/common/__tests__/ContextFilter.test.ts @@ -416,6 +416,23 @@ describe('when handling mult-kind contexts', () => { }, }; + const multiWithSingleContext = Context.fromLDContext({ + kind: 'multi', + user: { + key: 'abc', + name: 'alphabet', + letters: ['a', 'b', 'c'], + order: 3, + object: { + a: 'a', + b: 'b', + }, + _meta: { + privateAttributes: ['letters', '/object/b'], + }, + }, + }); + it('it should remove attributes from all contexts when all attributes are private.', () => { const uf = new ContextFilter(true, []); expect(uf.filter(orgAndUserContext)).toEqual(orgAndUserContextAllPrivate); @@ -430,4 +447,20 @@ describe('when handling mult-kind contexts', () => { const uf = new ContextFilter(false, [new AttributeReference('name', true)]); expect(uf.filter(orgAndUserContext)).toEqual(orgAndUserGlobalNamePrivate); }); + + it('should produce event with valid single context', () => { + const uf = new ContextFilter(false, []); + expect(uf.filter(multiWithSingleContext)).toEqual({ + kind: 'user', + _meta: { + redactedAttributes: ['/object/b', 'letters'], + }, + key: 'abc', + name: 'alphabet', + object: { + a: 'a', + }, + order: 3, + }); + }); }); diff --git a/packages/shared/common/src/Context.ts b/packages/shared/common/src/Context.ts index 6bf677ac4..9220afcdf 100644 --- a/packages/shared/common/src/Context.ts +++ b/packages/shared/common/src/Context.ts @@ -265,7 +265,7 @@ export default class Context { if (kinds.length === 1) { const kind = kinds[0]; const created = new Context(true, kind); - created.context = contexts[kind]; + created.context = { ...contexts[kind], kind }; created.privateAttributeReferences = privateAttributes; created.isUser = kind === 'user'; return created;