Skip to content

Commit 7aa9c23

Browse files
organizing tests
1 parent b991a98 commit 7aa9c23

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

src/integrationTests/options.test.ts

+10-18
Original file line numberDiff line numberDiff line change
@@ -571,28 +571,29 @@ describe('calls the NoIdentityAvailable event', () => {
571571

572572
test('when init is called for the first time with no identity', () => {
573573
uid2.init({});
574+
574575
expect(handler).toHaveBeenLastCalledWith(EventType.NoIdentityAvailable, { identity: null });
575576
});
576577
test('when init is already complete and called again with no identity', () => {
577578
uid2.init({});
578579
uid2.init({});
580+
579581
expect(handler).toHaveBeenLastCalledWith(EventType.NoIdentityAvailable, { identity: null });
580582
});
581583
test('when init is already complete and called again with an expired identity', () => {
582584
uid2.init({});
583-
expect(handler).toHaveBeenLastCalledWith(EventType.NoIdentityAvailable, { identity: null });
584-
585585
uid2.init({
586586
identity: expiredIdentity,
587587
});
588+
588589
expect(handler).toHaveBeenLastCalledWith(EventType.NoIdentityAvailable, { identity: null });
589590
});
590591
test('when init is already complete but the existing identity is expired', () => {
591592
uid2.init({
592593
identity: expiredIdentity,
593594
});
594-
expect(handler).toHaveBeenLastCalledWith(EventType.NoIdentityAvailable, { identity: null });
595595
uid2.init({});
596+
596597
expect(handler).toHaveBeenLastCalledWith(EventType.NoIdentityAvailable, { identity: null });
597598
});
598599
test('when identity is expired but refreshable', () => {
@@ -611,9 +612,8 @@ describe('calls the NoIdentityAvailable event', () => {
611612
expect(handler).toHaveBeenLastCalledWith(EventType.NoIdentityAvailable, { identity: null });
612613
});
613614
test('when get identity returns null or get advertising token returns undefined', () => {
614-
const nullIdentity = uid2.getIdentity();
615+
uid2.getIdentity();
615616

616-
expect(nullIdentity).toBeNull();
617617
expect(handler).toHaveBeenLastCalledWith(EventType.NoIdentityAvailable, { identity: null });
618618
});
619619
test('when there is no advertising token', () => {
@@ -624,29 +624,19 @@ describe('calls the NoIdentityAvailable event', () => {
624624
});
625625
test('when cstg does not succeed', () => {
626626
uid2.init({});
627-
expect(uid2.setIdentityFromEmail('a', mocks.makeUid2CstgOption())).rejects.toThrow(
628-
'Invalid email address'
629-
);
630627

631-
expect(handler).toHaveBeenLastCalledWith(EventType.NoIdentityAvailable, { identity: null });
632-
});
633-
test('when an identity was valid but has since expired', () => {
634-
uid2.init({});
635628
expect(uid2.setIdentityFromEmail('a', mocks.makeUid2CstgOption())).rejects.toThrow(
636629
'Invalid email address'
637630
);
638-
639631
expect(handler).toHaveBeenLastCalledWith(EventType.NoIdentityAvailable, { identity: null });
640632
});
641633
test('when identity was valid on init but has since expired', () => {
642-
const refreshFrom = Date.now() + 100;
643634
const originalIdentity = makeIdentity({
644635
advertising_token: 'original_advertising_token',
645-
identity_expires: refreshFrom,
646-
//refresh_from: refreshFrom,
636+
identity_expires: Date.now() + 100,
647637
});
648-
649638
uid2.init({ identity: originalIdentity });
639+
650640
expect(handler).not.toHaveBeenLastCalledWith(EventType.NoIdentityAvailable, { identity: null });
651641

652642
// set time to an expired date for this identity
@@ -669,6 +659,7 @@ describe('does not call NoIdentityAvailable event', () => {
669659
test('when setIdentity is run with a valid identity, should not call NoIdentityAvailable on set or get', () => {
670660
uid2.init({});
671661
handler = jest.fn();
662+
672663
uid2.setIdentity(validIdentity);
673664
expect(handler).not.toHaveBeenLastCalledWith(EventType.NoIdentityAvailable, { identity: null });
674665

@@ -682,15 +673,16 @@ describe('does not call NoIdentityAvailable event', () => {
682673
uid2.init({});
683674
let optedOutIdentity = makeIdentity({ status: 'optout' });
684675
uid2.setIdentity(optedOutIdentity);
676+
685677
expect(handler).not.toHaveBeenLastCalledWith(EventType.NoIdentityAvailable, { identity: null });
686678
});
687679
test('when cstg is successful', async () => {
688680
uid2.init({});
689681
handler = jest.fn();
682+
690683
expect(async () => {
691684
await uid2.setIdentityFromEmail('test@test.com', mocks.makeUid2CstgOption());
692685
}).not.toThrow();
693-
694686
expect(handler).not.toHaveBeenLastCalledWith(EventType.NoIdentityAvailable, { identity: null });
695687
});
696688
test('when identity is set with local storage and init has never been', () => {

0 commit comments

Comments
 (0)