Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
34 changes: 34 additions & 0 deletions packages/shared/common/__tests__/ContextFilter.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { LDContext } from '../dist';

Check failure on line 1 in packages/shared/common/__tests__/ContextFilter.test.ts

View workflow job for this annotation

GitHub Actions / build-test-common

'LDContext' is defined but never used. Allowed unused vars must match /^__/u
import { AttributeReference, Context } from '../src';
import ContextFilter from '../src/ContextFilter';

Expand Down Expand Up @@ -416,6 +417,23 @@
},
};

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 +448,20 @@
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