Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Multi-kind context containing only 1 kind conveted incorrectly. #594

Merged
merged 2 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This attribute would have been missing.

_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
Loading