Skip to content

Commit 6c3f468

Browse files
committed
Additional tests.
1 parent 5d75446 commit 6c3f468

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed

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

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ describe('given a multi context', () => {
330330
describe('given mock crypto', () => {
331331
const crypto = setupCrypto();
332332

333-
it('two equal contexts hash the same', async () => {
333+
it('hashes two equal contexts the same', async () => {
334334
const a = Context.fromLDContext({
335335
kind: 'multi',
336336
org: {
@@ -373,7 +373,7 @@ describe('given mock crypto', () => {
373373
expect(await a.hash(crypto)).toEqual(await b.hash(crypto));
374374
});
375375

376-
it('legacy and non-legacy equivalent contexts hash the same', async () => {
376+
it('hashes legacy and non-legacy equivalent contexts the same', async () => {
377377
const legacy = Context.fromLDContext({
378378
key: 'testKey',
379379
name: 'testName',
@@ -397,7 +397,7 @@ describe('given mock crypto', () => {
397397
expect(await legacy.hash(crypto)).toEqual(await nonLegacy.hash(crypto));
398398
});
399399

400-
it('single context and multi-context with one kind hash the same', async () => {
400+
it('hashes single context and multi-context with one kind the same', async () => {
401401
const single = Context.fromLDContext({
402402
kind: 'org',
403403
key: 'testKey',
@@ -625,6 +625,36 @@ describe('given mock crypto', () => {
625625
expect(hashA).not.toBe(hashB);
626626
});
627627

628+
it('hashes _meta in attributes', async () => {
629+
const a = Context.fromLDContext({
630+
kind: 'user',
631+
key: 'testKey',
632+
nested: {
633+
level1: {
634+
level2: {
635+
_meta: { test: 'a' },
636+
},
637+
},
638+
},
639+
});
640+
641+
const b = Context.fromLDContext({
642+
kind: 'user',
643+
key: 'testKey',
644+
nested: {
645+
level1: {
646+
level2: {
647+
_meta: { test: 'b' },
648+
},
649+
},
650+
},
651+
});
652+
653+
const hashA = await a.hash(crypto);
654+
const hashB = await b.hash(crypto);
655+
expect(hashA).not.toBe(hashB);
656+
});
657+
628658
it('produces the same value for the given context', async () => {
629659
// This isn't so much a test as it is a detection of change.
630660
// If this test failed, and you didn't expect it, then you probably need to make sure your
@@ -654,13 +684,14 @@ describe('given mock crypto', () => {
654684
level1: {
655685
level2: {
656686
value: 'deep',
687+
_meta: { thisShouldBeInTheHash: true },
657688
},
658689
},
659690
},
660691
},
661692
});
662693
expect(await complexContext.hash(crypto)).toBe(
663-
'customerbirdchickenkeynamenestedorganonymouscatdogkeynamenestedArraya/b/ccatcustom/dog01length201length24301length221testNametestKeylabcalicotruelevel1level2valuedeeptestNametestKeyhenparty parrot',
694+
'customerbirdchickenkeynamenestedorganonymouscatdogkeynamenestedArraya/b/ccatcustom/dog01length201length24301length221testNametestKeylabcalicotruelevel1level2_metavaluedeepthisShouldBeInTheHashtruetestNametestKeyhenparty parrot',
664695
);
665696
});
666697
});

packages/shared/common/src/Context.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -514,10 +514,6 @@ export default class Context {
514514
Object.getOwnPropertyNames(target)
515515
.sort()
516516
.forEach((key) => {
517-
// Handled using private attributes.
518-
if (key === '_meta') {
519-
return;
520-
}
521517
hasher.update(key);
522518
stack.push({
523519
target: target[key],

0 commit comments

Comments
 (0)