Skip to content

Commit c0146ea

Browse files
committed
fix: Multi-kind context containing only 1 kind conveted incorrectly.
1 parent 53f5bb8 commit c0146ea

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

packages/shared/common/__tests__/ContextFilter.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { LDContext } from '../dist';
12
import { AttributeReference, Context } from '../src';
23
import ContextFilter from '../src/ContextFilter';
34

@@ -416,6 +417,23 @@ describe('when handling mult-kind contexts', () => {
416417
},
417418
};
418419

420+
const multiWithSingleContext = Context.fromLDContext({
421+
kind: 'multi',
422+
user: {
423+
key: 'abc',
424+
name: 'alphabet',
425+
letters: ['a', 'b', 'c'],
426+
order: 3,
427+
object: {
428+
a: 'a',
429+
b: 'b',
430+
},
431+
_meta: {
432+
privateAttributes: ['letters', '/object/b'],
433+
},
434+
},
435+
});
436+
419437
it('it should remove attributes from all contexts when all attributes are private.', () => {
420438
const uf = new ContextFilter(true, []);
421439
expect(uf.filter(orgAndUserContext)).toEqual(orgAndUserContextAllPrivate);
@@ -430,4 +448,20 @@ describe('when handling mult-kind contexts', () => {
430448
const uf = new ContextFilter(false, [new AttributeReference('name', true)]);
431449
expect(uf.filter(orgAndUserContext)).toEqual(orgAndUserGlobalNamePrivate);
432450
});
451+
452+
it('should produce event with valid single context', () => {
453+
const uf = new ContextFilter(false, []);
454+
expect(uf.filter(multiWithSingleContext)).toEqual({
455+
kind: 'user',
456+
_meta: {
457+
redactedAttributes: ['/object/b', 'letters'],
458+
},
459+
key: 'abc',
460+
name: 'alphabet',
461+
object: {
462+
a: 'a',
463+
},
464+
order: 3,
465+
});
466+
});
433467
});

packages/shared/common/src/Context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ export default class Context {
265265
if (kinds.length === 1) {
266266
const kind = kinds[0];
267267
const created = new Context(true, kind);
268-
created.context = contexts[kind];
268+
created.context = { ...contexts[kind], kind };
269269
created.privateAttributeReferences = privateAttributes;
270270
created.isUser = kind === 'user';
271271
return created;

0 commit comments

Comments
 (0)