Skip to content

Commit

Permalink
[MOB-10091]: AUT Pre-Bash Updates (#475)
Browse files Browse the repository at this point in the history
* update var, some error cleanup in sample app

* remove endpoint from list

* fix spec
  • Loading branch information
mprew97 authored Oct 31, 2024
1 parent 2f3792e commit baa3f7c
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 41 deletions.
8 changes: 6 additions & 2 deletions react-example/src/components/LoginFormWithoutJWT.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { ChangeEvent, FC, FormEvent, useState } from 'react';
import styled from 'styled-components';

import { IdentityResolution } from '@iterable/web-sdk';
import { TextField as _TextField } from './TextField';
import { Button as _Button } from './Button';

Expand Down Expand Up @@ -39,7 +40,10 @@ const Error = styled.div`

interface Props {
setEmail: (email: string) => Promise<void>;
setUserId: (userId: string, merge?: boolean) => Promise<void>;
setUserId: (
userId: string,
identityResolution?: IdentityResolution
) => Promise<void>;
logout: () => void;
}

Expand All @@ -62,7 +66,7 @@ export const LoginFormWithoutJWT: FC<Props> = ({

const setUser = useEmail ? setEmail : setUserId;

setUser(user, true)
setUser(user)
.then(() => {
setEditingUser(false);
setLoggedInUser({ type: 'user_update', data: user });
Expand Down
2 changes: 1 addition & 1 deletion react-example/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const HomeLink = styled(Link)`
configOptions: {
isEuIterableService: false,
dangerouslyAllowJsPopups: true,
enableAnonTracking: true
enableAnonActivation: true
},
generateJWT: ({ email, userID }) =>
axios
Expand Down
2 changes: 1 addition & 1 deletion react-example/src/indexWithoutJWT.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const HomeLink = styled(Link)`
configOptions: {
isEuIterableService: false,
dangerouslyAllowJsPopups: true,
enableAnonTracking: true,
enableAnonActivation: true,
onAnonUserCreated: (userId: string) => {
console.log('onAnonUserCreated', userId);
}
Expand Down
47 changes: 26 additions & 21 deletions src/anonymousUserTracking/tests/userMergeScenarios.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { track } from '../../events';
import { getInAppMessages } from '../../inapp';
import { baseAxiosRequest } from '../../request';
import { USER_MERGE_SCENARIO_CRITERIA } from './constants';
import { setTypeOfAuth } from '../../utils/typeOfAuth';

jest.setTimeout(20000); // Set the timeout to 10 seconds

Expand Down Expand Up @@ -108,7 +109,7 @@ describe('UserMergeScenariosTests', () => {
const { setUserID, logout } = initializeWithConfig({
authToken: '123',
configOptions: {
enableAnonTracking: true,
enableAnonActivation: true,
identityResolution: {
replayOnVisitorToKnown: false,
mergeOnAnonymousToKnown: false
Expand Down Expand Up @@ -147,7 +148,7 @@ describe('UserMergeScenariosTests', () => {
const { setUserID, logout } = initializeWithConfig({
authToken: '123',
configOptions: {
enableAnonTracking: true,
enableAnonActivation: true,
identityResolution: {
replayOnVisitorToKnown: true,
mergeOnAnonymousToKnown: true
Expand Down Expand Up @@ -188,7 +189,7 @@ describe('UserMergeScenariosTests', () => {
const { setUserID, logout } = initializeWithConfig({
authToken: '123',
configOptions: {
enableAnonTracking: true,
enableAnonActivation: true,
identityResolution: {
replayOnVisitorToKnown: true,
mergeOnAnonymousToKnown: false
Expand Down Expand Up @@ -241,7 +242,7 @@ describe('UserMergeScenariosTests', () => {
const { setUserID, logout } = initializeWithConfig({
authToken: '123',
configOptions: {
enableAnonTracking: true,
enableAnonActivation: true,
identityResolution: {
replayOnVisitorToKnown: true,
mergeOnAnonymousToKnown: false
Expand Down Expand Up @@ -288,7 +289,7 @@ describe('UserMergeScenariosTests', () => {
const { setUserID, logout } = initializeWithConfig({
authToken: '123',
configOptions: {
enableAnonTracking: true,
enableAnonActivation: true,
identityResolution: {
replayOnVisitorToKnown: true,
mergeOnAnonymousToKnown: true
Expand Down Expand Up @@ -325,6 +326,7 @@ describe('UserMergeScenariosTests', () => {
});

it('criteria is met with merge default with setUserId', async () => {
const anonId = '123e4567-e89b-12d3-a456-426614174000';
(localStorage.getItem as jest.Mock).mockImplementation((key) => {
if (key === SHARED_PREFS_EVENT_LIST_KEY) {
return JSON.stringify([eventDataMatched]);
Expand All @@ -336,14 +338,14 @@ describe('UserMergeScenariosTests', () => {
return JSON.stringify(initialAnonSessionInfo);
}
if (key === SHARED_PREF_ANON_USER_ID) {
return '123e4567-e89b-12d3-a456-426614174000';
return anonId;
}
return null;
});
const { setUserID, logout } = initializeWithConfig({
authToken: '123',
configOptions: {
enableAnonTracking: true
enableAnonActivation: true
}
});
logout(); // logout to remove logged in users before this test
Expand All @@ -360,6 +362,7 @@ describe('UserMergeScenariosTests', () => {
} catch (e) {
console.log(e);
}
setTypeOfAuth('userID');
await setUserID('testuser123');
expect(localStorageMock.removeItem).toHaveBeenCalledWith(
SHARED_PREF_ANON_USER_ID
Expand All @@ -378,7 +381,7 @@ describe('UserMergeScenariosTests', () => {
const { setUserID, logout } = initializeWithConfig({
authToken: '123',
configOptions: {
enableAnonTracking: true,
enableAnonActivation: true,
identityResolution: {
replayOnVisitorToKnown: true,
mergeOnAnonymousToKnown: false
Expand Down Expand Up @@ -416,7 +419,7 @@ describe('UserMergeScenariosTests', () => {
const { setUserID, logout } = initializeWithConfig({
authToken: '123',
configOptions: {
enableAnonTracking: true,
enableAnonActivation: true,
identityResolution: {
replayOnVisitorToKnown: true,
mergeOnAnonymousToKnown: true
Expand Down Expand Up @@ -449,7 +452,7 @@ describe('UserMergeScenariosTests', () => {
const { setUserID, logout } = initializeWithConfig({
authToken: '123',
configOptions: {
enableAnonTracking: true,
enableAnonActivation: true,
identityResolution: {
replayOnVisitorToKnown: true,
mergeOnAnonymousToKnown: true
Expand Down Expand Up @@ -510,7 +513,7 @@ describe('UserMergeScenariosTests', () => {
const { setUserID, logout } = initializeWithConfig({
authToken: '123',
configOptions: {
enableAnonTracking: true,
enableAnonActivation: true,
identityResolution: {
replayOnVisitorToKnown: true,
mergeOnAnonymousToKnown: false
Expand Down Expand Up @@ -545,7 +548,7 @@ describe('UserMergeScenariosTests', () => {
const { setEmail, logout } = initializeWithConfig({
authToken: '123',
configOptions: {
enableAnonTracking: true,
enableAnonActivation: true,
identityResolution: {
replayOnVisitorToKnown: false,
mergeOnAnonymousToKnown: false
Expand Down Expand Up @@ -584,7 +587,7 @@ describe('UserMergeScenariosTests', () => {
const { setEmail, logout } = initializeWithConfig({
authToken: '123',
configOptions: {
enableAnonTracking: true,
enableAnonActivation: true,
identityResolution: {
replayOnVisitorToKnown: true,
mergeOnAnonymousToKnown: true
Expand Down Expand Up @@ -625,7 +628,7 @@ describe('UserMergeScenariosTests', () => {
const { setEmail, logout } = initializeWithConfig({
authToken: '123',
configOptions: {
enableAnonTracking: true
enableAnonActivation: true
}
});
logout(); // logout to remove logged in users before this test
Expand Down Expand Up @@ -677,7 +680,7 @@ describe('UserMergeScenariosTests', () => {
const { setEmail } = initializeWithConfig({
authToken: '123',
configOptions: {
enableAnonTracking: true,
enableAnonActivation: true,
identityResolution: {
replayOnVisitorToKnown: true,
mergeOnAnonymousToKnown: true
Expand Down Expand Up @@ -712,6 +715,7 @@ describe('UserMergeScenariosTests', () => {
});

it('criteria is met with merge default with setEmail', async () => {
const anonId = '123e4567-e89b-12d3-a456-426614174000';
(localStorage.getItem as jest.Mock).mockImplementation((key) => {
if (key === SHARED_PREFS_EVENT_LIST_KEY) {
return JSON.stringify([eventDataMatched]);
Expand All @@ -723,14 +727,14 @@ describe('UserMergeScenariosTests', () => {
return JSON.stringify(initialAnonSessionInfo);
}
if (key === SHARED_PREF_ANON_USER_ID) {
return '123e4567-e89b-12d3-a456-426614174000';
return anonId;
}
return null;
});
const { setEmail, logout } = initializeWithConfig({
authToken: '123',
configOptions: {
enableAnonTracking: true
enableAnonActivation: true
}
});
logout(); // logout to remove logged in users before this test
Expand All @@ -747,6 +751,7 @@ describe('UserMergeScenariosTests', () => {
} catch (e) {
console.log(e);
}
setTypeOfAuth('userID');
await setEmail('[email protected]');
expect(localStorageMock.removeItem).toHaveBeenCalledWith(
SHARED_PREF_ANON_USER_ID
Expand All @@ -765,7 +770,7 @@ describe('UserMergeScenariosTests', () => {
const { setEmail, logout } = initializeWithConfig({
authToken: '123',
configOptions: {
enableAnonTracking: true,
enableAnonActivation: true,
identityResolution: {
replayOnVisitorToKnown: true,
mergeOnAnonymousToKnown: false
Expand Down Expand Up @@ -805,7 +810,7 @@ describe('UserMergeScenariosTests', () => {
const { setEmail, logout } = initializeWithConfig({
authToken: '123',
configOptions: {
enableAnonTracking: true,
enableAnonActivation: true,
identityResolution: {
replayOnVisitorToKnown: true,
mergeOnAnonymousToKnown: true
Expand Down Expand Up @@ -845,7 +850,7 @@ describe('UserMergeScenariosTests', () => {
const { setEmail, logout } = initializeWithConfig({
authToken: '123',
configOptions: {
enableAnonTracking: true,
enableAnonActivation: true,
identityResolution: {
replayOnVisitorToKnown: true,
mergeOnAnonymousToKnown: false
Expand Down Expand Up @@ -885,7 +890,7 @@ describe('UserMergeScenariosTests', () => {
const { setEmail, logout } = initializeWithConfig({
authToken: '123',
configOptions: {
enableAnonTracking: true,
enableAnonActivation: true,
identityResolution: {
replayOnVisitorToKnown: true,
mergeOnAnonymousToKnown: true
Expand Down
2 changes: 1 addition & 1 deletion src/anonymousUserTracking/tests/userUpdate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ describe('UserUpdate', () => {

const { logout } = initializeWithConfig({
authToken: '123',
configOptions: { enableAnonTracking: true }
configOptions: { enableAnonActivation: true }
});
logout(); // logout to remove logged in users before this test

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ describe('validateCustomEventUserUpdateAPI', () => {

const { setUserID, logout } = initializeWithConfig({
authToken: '123',
configOptions: { enableAnonTracking: true }
configOptions: { enableAnonActivation: true }
});
logout(); // logout to remove logged in users before this test

Expand Down Expand Up @@ -246,7 +246,7 @@ describe('validateCustomEventUserUpdateAPI', () => {

const { setUserID, logout } = initializeWithConfig({
authToken: '123',
configOptions: { enableAnonTracking: true }
configOptions: { enableAnonActivation: true }
});
logout(); // logout to remove logged in users before this test

Expand Down Expand Up @@ -316,7 +316,7 @@ describe('validateCustomEventUserUpdateAPI', () => {

const { setUserID, logout } = initializeWithConfig({
authToken: '123',
configOptions: { enableAnonTracking: true }
configOptions: { enableAnonActivation: true }
});
logout(); // logout to remove logged in users before this test

Expand Down Expand Up @@ -390,7 +390,7 @@ describe('validateCustomEventUserUpdateAPI', () => {

const { setUserID, logout } = initializeWithConfig({
authToken: '123',
configOptions: { enableAnonTracking: true }
configOptions: { enableAnonActivation: true }
});
logout(); // logout to remove logged in users before this test

Expand Down
10 changes: 5 additions & 5 deletions src/authorization/authorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const clearAnonymousUser = () => {
};

const getAnonUserId = () => {
if (config.getConfig('enableAnonTracking')) {
if (config.getConfig('enableAnonActivation')) {
const anonUser = localStorage.getItem(SHARED_PREF_ANON_USER_ID);
return anonUser === undefined ? null : anonUser;
} else {
Expand Down Expand Up @@ -213,7 +213,7 @@ const initializeEmailUser = (email: string) => {
};

const syncEvents = () => {
if (config.getConfig('enableAnonTracking')) {
if (config.getConfig('enableAnonActivation')) {
anonUserManager.syncEvents();
}
};
Expand Down Expand Up @@ -396,7 +396,7 @@ export function initialize(

const enableAnonymousTracking = () => {
try {
if (config.getConfig('enableAnonTracking')) {
if (config.getConfig('enableAnonActivation')) {
anonUserManager.getAnonCriteria();
anonUserManager.updateAnonSession();
const anonymousUserId = getAnonUserId();
Expand All @@ -416,7 +416,7 @@ export function initialize(
merge?: boolean
): Promise<boolean> => {
const typeOfAuth = getTypeOfAuth();
const enableAnonTracking = config.getConfig('enableAnonTracking');
const enableAnonActivation = config.getConfig('enableAnonActivation');
const sourceUserIdOrEmail =
authIdentifier === null ? getAnonUserId() : authIdentifier;
const sourceUserId = typeOfAuth === 'email' ? null : sourceUserIdOrEmail;
Expand All @@ -427,7 +427,7 @@ export function initialize(
if (
(getAnonUserId() !== null || authIdentifier !== null) &&
merge &&
enableAnonTracking
enableAnonActivation
) {
const anonymousUserMerge = new AnonymousUserMerge();
try {
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export * from './embedded';
export * from './components/card';
export * from './components/banner';
export * from './components/notification';
export { config } from './utils/config';
export { config, IdentityResolution } from './utils/config';
export { IterableConfig } from './utils/IterableConfig';

export interface TextParentStyles {
Expand Down
2 changes: 0 additions & 2 deletions src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
EU_ITERABLE_API,
GET_CRITERIA_PATH,
INITIALIZE_ERROR,
ENDPOINT_MERGE_USER,
ENDPOINT_TRACK_ANON_SESSION
} from './constants';
import { IterablePromise, IterableResponse } from './types';
Expand All @@ -32,7 +31,6 @@ interface ClientError extends IterableResponse {

const ENDPOINTS_NOT_REQUIRING_TYPE_OF_AUTH = [
GET_CRITERIA_PATH,
ENDPOINT_MERGE_USER,
ENDPOINT_TRACK_ANON_SESSION
];

Expand Down
2 changes: 1 addition & 1 deletion src/utils/commonFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import config from './config';
import { getTypeOfAuth } from './typeOfAuth';

export const canTrackAnonUser = (): boolean =>
config.getConfig('enableAnonTracking') && getTypeOfAuth() === null;
config.getConfig('enableAnonActivation') && getTypeOfAuth() === null;
Loading

0 comments on commit baa3f7c

Please sign in to comment.