Skip to content

Commit 288e259

Browse files
committed
test: updated tests for DisabledVault
1 parent 2b2e795 commit 288e259

2 files changed

Lines changed: 16 additions & 42 deletions

File tree

test/src/tests-identity.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -650,20 +650,20 @@ describe('identity', function() {
650650
});
651651

652652
describe('#createIdentityCache', function() {
653-
it('should use LocalStorageVault when noFunctional is false by default', async () => {
653+
it('should save id cache to local storage when noFunctional is false by default', async () => {
654654
mParticle.init(apiKey, window.mParticle.config);
655655
await waitForCondition(hasIdentifyReturned);
656656
expect(localStorage.getItem('mprtcl-v4_abcdef-id-cache')).to.be.ok;
657657
});
658658

659-
it('should use DisabledVault when noFunctional is true', async () => {
659+
it('should NOT save id cache to local storage when noFunctional is true', async () => {
660660
mParticle.config.noFunctional = true;
661661
mParticle.init(apiKey, window.mParticle.config);
662662
await waitForCondition(hasIdentifyReturned);
663663
expect(localStorage.getItem('mprtcl-v4_abcdef-id-cache')).not.to.be.ok;
664664
});
665665

666-
it('should use LocalStorageVault when noFunctional is false', async () => {
666+
it('should save id cache to local storage when noFunctional is false', async () => {
667667
mParticle.config.noFunctional = false;
668668
mParticle.init(apiKey, window.mParticle.config);
669669
await waitForCondition(hasIdentifyReturned);

test/src/vault.spec.ts

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -428,75 +428,52 @@ describe('Vault', () => {
428428
describe('#store', () => {
429429
it('should NOT write to localStorage', () => {
430430
const storageKey = 'test-disabled-store-empty';
431-
const vault = new DisabledVault<Dictionary<Dictionary<string>>>(
432-
storageKey,
433-
);
431+
const vault = new DisabledVault<string>(storageKey);
434432

435-
vault.store(testObject);
433+
vault.store('testString');
436434

437435
expect(vault.contents).to.equal(null);
438436
expect(window.localStorage.getItem(storageKey)).to.equal(null);
439437
});
440438

441439
it('should NOT overwrite existing localStorage value and keep contents null', () => {
442440
const storageKey = 'test-disabled-store-existing';
443-
window.localStorage.setItem(
444-
storageKey,
445-
JSON.stringify(testObject),
446-
);
441+
window.localStorage.setItem(storageKey, 'existingItem');
447442

448-
const vault = new DisabledVault<Dictionary<Dictionary<string>>>(
449-
storageKey,
450-
);
443+
const vault = new DisabledVault<string>(storageKey);
451444

452-
vault.store({ pinky: { narf: 'poit' } });
445+
vault.store('newValue');
453446

454447
expect(vault.contents).to.equal(null);
455-
expect(window.localStorage.getItem(storageKey)).to.equal(
456-
JSON.stringify(testObject),
457-
);
448+
expect(window.localStorage.getItem(storageKey)).to.equal('existingItem');
458449
});
459450
});
460451

461452
describe('#retrieve', () => {
462453
it('should return null when nothing is stored', () => {
463454
const storageKey = 'test-disabled-retrieve-empty';
464-
const vault = new DisabledVault<Dictionary<Dictionary<string>>>(
465-
storageKey,
466-
);
455+
const vault = new DisabledVault<string>(storageKey);
467456
const retrievedItem = vault.retrieve();
468457
expect(retrievedItem).to.equal(null);
469458
});
470459

471460
it('should return null even if localStorage has a value', () => {
472461
const storageKey = 'test-disabled-retrieve-existing';
473-
window.localStorage.setItem(
474-
storageKey,
475-
JSON.stringify(testObject),
476-
);
462+
window.localStorage.setItem(storageKey, 'existingItem');
477463

478-
const vault = new DisabledVault<Dictionary<Dictionary<string>>>(
479-
storageKey,
480-
);
464+
const vault = new DisabledVault<string>(storageKey);
481465
const retrievedItem = vault.retrieve();
482466
expect(retrievedItem).to.equal(null);
483-
expect(window.localStorage.getItem(storageKey)).to.equal(
484-
JSON.stringify(testObject),
485-
);
467+
expect(window.localStorage.getItem(storageKey)).to.equal('existingItem');
486468
});
487469
});
488470

489471
describe('#purge', () => {
490472
it('should keep contents null when purging', () => {
491473
const storageKey = 'test-disabled-purge-existing';
492-
window.localStorage.setItem(
493-
storageKey,
494-
JSON.stringify(testObject),
495-
);
474+
window.localStorage.setItem(storageKey, 'existing');
496475

497-
const vault = new DisabledVault<Dictionary<Dictionary<string>>>(
498-
storageKey,
499-
);
476+
const vault = new DisabledVault<string>(storageKey);
500477

501478
vault.purge();
502479

@@ -506,12 +483,9 @@ describe('Vault', () => {
506483

507484
it('should keep contents null when purging an empty key', () => {
508485
const storageKey = 'test-disabled-purge-empty';
509-
const vault = new DisabledVault<Dictionary<Dictionary<string>>>(
510-
storageKey,
511-
);
486+
const vault = new DisabledVault<string>(storageKey);
512487

513488
vault.purge();
514-
console.log(window.localStorage.getItem(storageKey));
515489
expect(vault.contents).to.equal(null);
516490
expect(window.localStorage.getItem(storageKey)).to.equal(null);
517491
});

0 commit comments

Comments
 (0)