Skip to content

Commit b6ff2a6

Browse files
authored
fix: Multi-kind context containing only 1 kind conveted incorrectly. (#594)
1 parent 53f5bb8 commit b6ff2a6

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,23 @@ describe('when handling mult-kind contexts', () => {
416416
},
417417
};
418418

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

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)