Skip to content

Commit

Permalink
Merge pull request #599 from Iterable/2.0.0-alpha/MOB-9995-reorganize…
Browse files Browse the repository at this point in the history
…-source-code

[MOB-9995] reorganize source code
  • Loading branch information
lposen authored Dec 3, 2024
2 parents 7cae386 + a7dccb5 commit d7256fd
Show file tree
Hide file tree
Showing 58 changed files with 525 additions and 443 deletions.
53 changes: 0 additions & 53 deletions src/IterableAction.ts

This file was deleted.

132 changes: 0 additions & 132 deletions src/IterableInAppClasses.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/__mocks__/MockRNIterableAPI.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IterableAttributionInfo } from '../Iterable';
import { IterableInAppMessage } from '../IterableInAppMessage';
import { IterableAttributionInfo } from '../core';
import { IterableInAppMessage } from '../inApp';

export class MockRNIterableAPI {
static email?: string;
Expand Down
2 changes: 2 additions & 0 deletions src/__mocks__/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './MockLinking';
export * from './MockRNIterableAPI';
35 changes: 17 additions & 18 deletions src/__tests__/Iterable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,21 @@ import { NativeEventEmitter } from 'react-native';

import { MockLinking } from '../__mocks__/MockLinking';
import { MockRNIterableAPI } from '../__mocks__/MockRNIterableAPI';
import { TestHelper } from './TestHelper';

import { IterableLogger } from '../core';
// import from the same location that consumers import from
import {
Iterable,
IterableAction,
IterableActionContext,
IterableActionSource,
IterableConfig,
IterableLogLevel,
} from '../index';
import {
EventName,
IterableAttributionInfo,
IterableCommerceItem,
} from '../Iterable';
import { IterableDataRegion } from '../IterableDataRegion';
import { IterableLogger } from '../IterableLogger';
IterableConfig,
IterableDataRegion,
IterableEventName,
IterableLogLevel,
} from '..';
import { TestHelper } from './TestHelper';

describe('Iterable', () => {
beforeEach(() => {
Expand Down Expand Up @@ -253,7 +250,7 @@ describe('Iterable', () => {
);
// sets up event emitter
const nativeEmitter = new NativeEventEmitter();
nativeEmitter.removeAllListeners(EventName.handleUrlCalled);
nativeEmitter.removeAllListeners(IterableEventName.handleUrlCalled);
// sets up config file and urlHandler function
// urlHandler set to return false
const config = new IterableConfig();
Expand All @@ -276,7 +273,7 @@ describe('Iterable', () => {
context: { action: actionDict, source: 'inApp' },
};
// WHEN handleUrlCalled event is emitted
nativeEmitter.emit(EventName.handleUrlCalled, dict);
nativeEmitter.emit(IterableEventName.handleUrlCalled, dict);
// THEN urlHandler and MockLinking is called with expected url
return await TestHelper.delayed(0, () => {
expect(config.urlHandler).toBeCalledWith(expectedUrl, dict.context);
Expand All @@ -289,7 +286,7 @@ describe('Iterable', () => {
);
// sets up event emitter
const nativeEmitter = new NativeEventEmitter();
nativeEmitter.removeAllListeners(EventName.handleUrlCalled);
nativeEmitter.removeAllListeners(IterableEventName.handleUrlCalled);
// sets up config file and urlHandler function
// urlHandler set to return false
const config = new IterableConfig();
Expand All @@ -312,7 +309,7 @@ describe('Iterable', () => {
context: { action: actionDict, source: 'inApp' },
};
// WHEN handleUrlCalled event is emitted
nativeEmitter.emit(EventName.handleUrlCalled, dict);
nativeEmitter.emit(IterableEventName.handleUrlCalled, dict);
// THEN urlHandler is called and MockLinking.openURL is not called
return await TestHelper.delayed(0, () => {
expect(config.urlHandler).toBeCalledWith(expectedUrl, dict.context);
Expand All @@ -325,7 +322,7 @@ describe('Iterable', () => {
);
// sets up event emitter
const nativeEmitter = new NativeEventEmitter();
nativeEmitter.removeAllListeners(EventName.handleUrlCalled);
nativeEmitter.removeAllListeners(IterableEventName.handleUrlCalled);
// sets up config file and urlHandler function
// urlHandler set to return true
const config = new IterableConfig();
Expand All @@ -348,7 +345,7 @@ describe('Iterable', () => {
context: { action: actionDict, source: 'inApp' },
};
// WHEN handleUrlCalled event is emitted
nativeEmitter.emit(EventName.handleUrlCalled, dict);
nativeEmitter.emit(IterableEventName.handleUrlCalled, dict);
// THEN urlHandler is called and MockLinking.openURL is not called
return await TestHelper.delayed(0, () => {
expect(config.urlHandler).toBeCalledWith(expectedUrl, dict.context);
Expand All @@ -361,7 +358,9 @@ describe('Iterable', () => {
);
// sets up event emitter
const nativeEmitter = new NativeEventEmitter();
nativeEmitter.removeAllListeners(EventName.handleCustomActionCalled);
nativeEmitter.removeAllListeners(
IterableEventName.handleCustomActionCalled
);
// sets up config file and customActionHandler function
// customActionHandler set to return true
const config = new IterableConfig();
Expand All @@ -382,7 +381,7 @@ describe('Iterable', () => {
context: { action: actionDict, source: IterableActionSource.inApp },
};
// WHEN handleCustomActionCalled event is emitted
nativeEmitter.emit(EventName.handleCustomActionCalled, dict);
nativeEmitter.emit(IterableEventName.handleCustomActionCalled, dict);
// THEN customActionHandler is called with expected action and expected context
const expectedAction = new IterableAction(actionName, actionData);
const expectedContext = new IterableActionContext(
Expand Down
21 changes: 11 additions & 10 deletions src/__tests__/IterableInApp.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import { NativeEventEmitter } from 'react-native';

import { IterableLogger } from '../core';
import { MockRNIterableAPI } from '../__mocks__/MockRNIterableAPI';

import { Iterable, EventName } from '../Iterable';
import { IterableConfig } from '../IterableConfig';
import { IterableInAppMessage } from '../IterableInAppMessage';
import {
Iterable,
IterableConfig,
IterableEventName,
IterableInAppCloseSource,
IterableInAppDeleteSource,
IterableInAppLocation,
IterableInAppMessage,
IterableInAppShowResponse,
IterableInAppTrigger,
IterableInAppTriggerType,
IterableInboxMetadata,
IterableInAppCloseSource,
IterableInAppShowResponse,
IterableInAppDeleteSource,
} from '../IterableInAppClasses';
import { IterableLogger } from '../IterableLogger';
} from '..';

describe('Iterable In App', () => {
beforeEach(() => {
Expand Down Expand Up @@ -137,7 +138,7 @@ describe('Iterable In App', () => {
test('inAppHandler_messageAndEventEmitted_methodCalledWithMessage', () => {
// sets up event emitter
const nativeEmitter = new NativeEventEmitter();
nativeEmitter.removeAllListeners(EventName.handleInAppCalled);
nativeEmitter.removeAllListeners(IterableEventName.handleInAppCalled);

// sets up config file and inAppHandler function
const config = new IterableConfig();
Expand Down Expand Up @@ -170,7 +171,7 @@ describe('Iterable In App', () => {
);

// WHEN handleInAppCalled event is emitted
nativeEmitter.emit(EventName.handleInAppCalled, messageDict);
nativeEmitter.emit(IterableEventName.handleInAppCalled, messageDict);

// THEN inAppHandler and MockRNIterableAPI.setInAppShowResponse is called with message
expect(config.inAppHandler).toBeCalledWith(expectedMessage);
Expand Down
Loading

0 comments on commit d7256fd

Please sign in to comment.