Skip to content

Commit

Permalink
fix: Multi-kind context containing only 1 kind conveted incorrectly. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
kinyoklion authored Sep 26, 2024
1 parent 53f5bb8 commit b6ff2a6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
33 changes: 33 additions & 0 deletions packages/shared/common/__tests__/ContextFilter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
});
});
});
2 changes: 1 addition & 1 deletion packages/shared/common/src/Context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit b6ff2a6

Please sign in to comment.