Skip to content
Closed
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/__tests__/IterableEmbeddedMessageDefaultAction.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { IterableEmbeddedMessageDefaultAction } from '../embedded/classes/IterableEmbeddedMessageDefaultAction';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error loading TSDoc config file:
Error encountered for /home/runner/work/react-native-sdk/tsdoc.json:
Unable to resolve "extends" reference to "typedoc/tsdoc.json": Cannot find module 'typedoc/tsdoc.json' from '/home/runner/work/react-native-sdk'
[eslint:tsdoc/syntax]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error loading TSDoc config file:
Error encountered for /home/runner/work/react-native-sdk/tsdoc.json:
Unable to resolve "extends" reference to "typedoc/tsdoc.json": Cannot find module 'typedoc/tsdoc.json' from '/home/runner/work/react-native-sdk'
[eslint:tsdoc/syntax]

import { Iterable } from '../core/classes/Iterable';

describe('IterableEmbeddedMessageDefaultAction', () => {
it('should create an instance with the correct properties', () => {
Iterable.logger.log(
'iterableEmbeddedMessageDefaultAction_fromDict_valid_dictionary'
);

const dict = { type: 'openUrl', data: 'https://example.com' };
const action = IterableEmbeddedMessageDefaultAction.fromDict(dict);
expect(action).toBeInstanceOf(IterableEmbeddedMessageDefaultAction);
expect(action.type).toBe('openUrl');
expect(action.data).toBe('https://example.com');
});

it('should create an instance from a dictionary with data omitted', () => {
Iterable.logger.log(
'iterableEmbeddedMessageDefaultAction_fromDict_valid_dictionary_with_data_omitted'
);

const dict = { type: 'action://join', data: '' };
const action = IterableEmbeddedMessageDefaultAction.fromDict(dict);
expect(action).toBeInstanceOf(IterableEmbeddedMessageDefaultAction);
expect(action.type).toBe('action://join');
expect(action.data).toBe('');
});

it('should throw an error if type is missing in fromDict', () => {
Iterable.logger.log(
'iterableEmbeddedMessageDefaultAction_fromDict_invalid_dictionary_missing_type'
);

const dict = { data: 'foo' };

expect(() => IterableEmbeddedMessageDefaultAction.fromDict(dict)).toThrow(
'type is required'
);
});
});
214 changes: 214 additions & 0 deletions src/__tests__/IterableEmbeddedMessageElements.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
import { IterableEmbeddedMessageElements } from '../embedded/classes/IterableEmbeddedMessageElements';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error loading TSDoc config file:
Error encountered for /home/runner/work/react-native-sdk/tsdoc.json:
Unable to resolve "extends" reference to "typedoc/tsdoc.json": Cannot find module 'typedoc/tsdoc.json' from '/home/runner/work/react-native-sdk'
[eslint:tsdoc/syntax]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error loading TSDoc config file:
Error encountered for /home/runner/work/react-native-sdk/tsdoc.json:
Unable to resolve "extends" reference to "typedoc/tsdoc.json": Cannot find module 'typedoc/tsdoc.json' from '/home/runner/work/react-native-sdk'
[eslint:tsdoc/syntax]

import { IterableEmbeddedMessageDefaultAction } from '../embedded/classes/IterableEmbeddedMessageDefaultAction';
import { IterableEmbeddedMessageElementsButton } from '../embedded/classes/IterableEmbeddedMessageElementsButton';
import { IterableEmbeddedMessageText } from '../embedded/classes/IterableEmbeddedMessageText';
import { Iterable } from '../core/classes/Iterable';

describe('IterableEmbeddedMessageElements', () => {
it('should create an instance with all properties', () => {
Iterable.logger.log(
'iterableEmbeddedMessageElements_fromDict_all_properties'
);

const dict = {
title: 'Awesome Title',
body: 'Radical Body Text',
mediaUrl: 'https://example.com/image.jpg',
mediaUrlCaption: 'Check out this sick image!',
defaultAction: {
type: 'openUrl',
data: 'https://example.com',
},
buttons: [
{
id: 'button-1',
title: 'Click Me!',
action: {
type: 'openUrl',
data: 'https://example.com/button1',
},
},
{
id: 'button-2',
title: 'Close',
action: {
type: 'action://dismiss',
},
},
],
text: [
{
id: 'text-1',
text: 'Some cool text',
type: 'body',
},
{
id: 'text-2',
text: 'More radical text',
type: 'subtitle',
},
],
};

const elements = IterableEmbeddedMessageElements.fromDict(dict);

expect(elements).toBeInstanceOf(IterableEmbeddedMessageElements);
expect(elements.title).toBe('Awesome Title');
expect(elements.body).toBe('Radical Body Text');
expect(elements.mediaUrl).toBe('https://example.com/image.jpg');
expect(elements.mediaUrlCaption).toBe('Check out this sick image!');

// Check defaultAction
expect(elements.defaultAction).toBeInstanceOf(
IterableEmbeddedMessageDefaultAction
);
expect(elements.defaultAction?.type).toBe('openUrl');
expect(elements.defaultAction?.data).toBe('https://example.com');

// Check buttons
expect(elements.buttons).toHaveLength(2);
const firstButton = elements
.buttons![0] as IterableEmbeddedMessageElementsButton;
expect(firstButton).toBeInstanceOf(IterableEmbeddedMessageElementsButton);
expect(firstButton.id).toBe('button-1');
expect(firstButton.title).toBe('Click Me!');
expect(firstButton.action?.type).toBe('openUrl');
expect(firstButton.action?.data).toBe('https://example.com/button1');

const secondButton = elements
.buttons![1] as IterableEmbeddedMessageElementsButton;
expect(secondButton).toBeInstanceOf(IterableEmbeddedMessageElementsButton);
expect(secondButton.id).toBe('button-2');
expect(secondButton.title).toBe('Close');
expect(secondButton.action?.type).toBe('action://dismiss');
expect(secondButton.action?.data).toBeUndefined();

// Check text elements
expect(elements.text).toHaveLength(2);
const firstText = elements.text![0] as IterableEmbeddedMessageText;
expect(firstText).toBeInstanceOf(IterableEmbeddedMessageText);
expect(firstText.id).toBe('text-1');
expect(firstText.text).toBe('Some cool text');
expect(firstText.type).toBe('body');

const secondText = elements.text![1] as IterableEmbeddedMessageText;
expect(secondText).toBeInstanceOf(IterableEmbeddedMessageText);
expect(secondText.id).toBe('text-2');
expect(secondText.text).toBe('More radical text');
expect(secondText.type).toBe('subtitle');
});

it('should create an instance with title and body', () => {
Iterable.logger.log(
'iterableEmbeddedMessageElements_fromDict_title_and_body'
);

const dict = {
title: 'Simple Title',
body: 'Simple Body',
};

const elements = IterableEmbeddedMessageElements.fromDict(dict);

expect(elements).toBeInstanceOf(IterableEmbeddedMessageElements);
expect(elements.title).toBe('Simple Title');
expect(elements.body).toBe('Simple Body');
expect(elements.mediaUrl).toBeUndefined();
expect(elements.mediaUrlCaption).toBeUndefined();
expect(elements.defaultAction).toBeUndefined();
expect(elements.buttons).toBeUndefined();
expect(elements.text).toBeUndefined();
});

it('should create an instance with no title or body', () => {
Iterable.logger.log(
'iterableEmbeddedMessageElements_fromDict_no_title_or_body'
);

const dict = {};

const elements = IterableEmbeddedMessageElements.fromDict(dict);

expect(elements).toBeInstanceOf(IterableEmbeddedMessageElements);
expect(elements.title).toBeUndefined();
expect(elements.body).toBeUndefined();
expect(elements.mediaUrl).toBeUndefined();
expect(elements.mediaUrlCaption).toBeUndefined();
expect(elements.defaultAction).toBeUndefined();
expect(elements.buttons).toBeUndefined();
expect(elements.text).toBeUndefined();
});

it('should create an instance with media properties', () => {
Iterable.logger.log(
'iterableEmbeddedMessageElements_fromDict_media_properties'
);

const dict = {
title: 'Media Title',
body: 'Media Body',
mediaUrl: 'https://example.com/media.jpg',
mediaUrlCaption: 'Check this out!',
};

const elements = IterableEmbeddedMessageElements.fromDict(dict);

expect(elements).toBeInstanceOf(IterableEmbeddedMessageElements);
expect(elements.title).toBe('Media Title');
expect(elements.body).toBe('Media Body');
expect(elements.mediaUrl).toBe('https://example.com/media.jpg');
expect(elements.mediaUrlCaption).toBe('Check this out!');
expect(elements.defaultAction).toBeUndefined();
expect(elements.buttons).toBeUndefined();
expect(elements.text).toBeUndefined();
});

it('should create an instance with defaultAction only', () => {
Iterable.logger.log(
'iterableEmbeddedMessageElements_fromDict_defaultAction_only'
);

const dict = {
title: 'Action Title',
body: 'Action Body',
defaultAction: {
type: 'openUrl',
data: 'https://example.com',
},
};

const elements = IterableEmbeddedMessageElements.fromDict(dict);

expect(elements).toBeInstanceOf(IterableEmbeddedMessageElements);
expect(elements.title).toBe('Action Title');
expect(elements.body).toBe('Action Body');
expect(elements.defaultAction).toBeInstanceOf(
IterableEmbeddedMessageDefaultAction
);
expect(elements.defaultAction?.type).toBe('openUrl');
expect(elements.defaultAction?.data).toBe('https://example.com');
expect(elements.buttons).toBeUndefined();
expect(elements.text).toBeUndefined();
});

it('should create an instance with empty arrays for buttons and text', () => {
Iterable.logger.log(
'iterableEmbeddedMessageElements_fromDict_empty_arrays'
);

const dict = {
title: 'Empty Arrays Title',
body: 'Empty Arrays Body',
buttons: [],
text: [],
};

const elements = IterableEmbeddedMessageElements.fromDict(dict);

expect(elements).toBeInstanceOf(IterableEmbeddedMessageElements);
expect(elements.title).toBe('Empty Arrays Title');
expect(elements.body).toBe('Empty Arrays Body');
expect(elements.buttons).toHaveLength(0);
expect(elements.text).toHaveLength(0);
});
});
91 changes: 91 additions & 0 deletions src/__tests__/IterableEmbeddedMessageElementsButton.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { IterableEmbeddedMessageElementsButton } from '../embedded/classes/IterableEmbeddedMessageElementsButton';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error loading TSDoc config file:
Error encountered for /home/runner/work/react-native-sdk/tsdoc.json:
Unable to resolve "extends" reference to "typedoc/tsdoc.json": Cannot find module 'typedoc/tsdoc.json' from '/home/runner/work/react-native-sdk'
[eslint:tsdoc/syntax]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error loading TSDoc config file:
Error encountered for /home/runner/work/react-native-sdk/tsdoc.json:
Unable to resolve "extends" reference to "typedoc/tsdoc.json": Cannot find module 'typedoc/tsdoc.json' from '/home/runner/work/react-native-sdk'
[eslint:tsdoc/syntax]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error loading TSDoc config file:
Error encountered for /home/runner/work/react-native-sdk/tsdoc.json:
Unable to resolve "extends" reference to "typedoc/tsdoc.json": Cannot find module 'typedoc/tsdoc.json' from '/home/runner/work/react-native-sdk'
[eslint:tsdoc/syntax]

import { IterableEmbeddedMessageElementsButtonAction } from '../embedded/classes/IterableEmbeddedMessageElementsButtonAction';
import { Iterable } from '../core/classes/Iterable';

describe('IterableEmbeddedMessageButton', () => {
it('should create an instance with all properties including button action', () => {
Iterable.logger.log(
'iterableEmbeddedMessageButton_fromDict_all_properties'
);

const dict = {
id: 'button-123',
title: 'Click Me!',
action: { type: 'openUrl', data: 'https://example.com' },
};

const button = IterableEmbeddedMessageElementsButton.fromDict(dict);

expect(button).toBeInstanceOf(IterableEmbeddedMessageElementsButton);
expect(button.id).toBe('button-123');
expect(button.title).toBe('Click Me!');
expect(button.action).toBeInstanceOf(
IterableEmbeddedMessageElementsButtonAction
);
expect(button.action?.type).toBe('openUrl');
expect(button.action?.data).toBe('https://example.com');
});

it('should create an instance with only required properties', () => {
Iterable.logger.log('iterableEmbeddedMessageButton_fromDict_required_only');

const dict = { id: 'button-123' };

const button = IterableEmbeddedMessageElementsButton.fromDict(dict);

expect(button).toBeInstanceOf(IterableEmbeddedMessageElementsButton);
expect(button.id).toBe('button-123');
expect(button.title).toBeUndefined();
expect(button.action).toBeUndefined();
});

it('should create an instance with title but no action', () => {
Iterable.logger.log('iterableEmbeddedMessageButton_fromDict_title_only');

const dict = {
id: 'button-123',
title: 'Click Me!',
};

const button = IterableEmbeddedMessageElementsButton.fromDict(dict);

expect(button).toBeInstanceOf(IterableEmbeddedMessageElementsButton);
expect(button.id).toBe('button-123');
expect(button.title).toBe('Click Me!');
expect(button.action).toBeUndefined();
});

it('should throw an error if id is missing in fromDict', () => {
Iterable.logger.log('iterableEmbeddedMessageButton_fromDict_missing_id');

const dict = {
title: 'Click Me!',
action: { type: 'openUrl', data: 'https://example.com' },
};

expect(() => IterableEmbeddedMessageElementsButton.fromDict(dict)).toThrow(
'id is required'
);
});

it('should handle button action with only type', () => {
Iterable.logger.log(
'iterableEmbeddedMessageButton_fromDict_action_type_only'
);

const dict = {
id: 'button-123',
action: { type: 'close' },
};

const button = IterableEmbeddedMessageElementsButton.fromDict(dict);

expect(button).toBeInstanceOf(IterableEmbeddedMessageElementsButton);
expect(button.id).toBe('button-123');
expect(button.action).toBeInstanceOf(
IterableEmbeddedMessageElementsButtonAction
);
expect(button.action?.type).toBe('close');
expect(button.action?.data).toBeUndefined();
});
});
40 changes: 40 additions & 0 deletions src/__tests__/IterableEmbeddedMessageElementsButtonAction.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { IterableEmbeddedMessageElementsButtonAction } from '../embedded/classes/IterableEmbeddedMessageElementsButtonAction';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error loading TSDoc config file:
Error encountered for /home/runner/work/react-native-sdk/tsdoc.json:
Unable to resolve "extends" reference to "typedoc/tsdoc.json": Cannot find module 'typedoc/tsdoc.json' from '/home/runner/work/react-native-sdk'
[eslint:tsdoc/syntax]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error loading TSDoc config file:
Error encountered for /home/runner/work/react-native-sdk/tsdoc.json:
Unable to resolve "extends" reference to "typedoc/tsdoc.json": Cannot find module 'typedoc/tsdoc.json' from '/home/runner/work/react-native-sdk'
[eslint:tsdoc/syntax]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error loading TSDoc config file:
Error encountered for /home/runner/work/react-native-sdk/tsdoc.json:
Unable to resolve "extends" reference to "typedoc/tsdoc.json": Cannot find module 'typedoc/tsdoc.json' from '/home/runner/work/react-native-sdk'
[eslint:tsdoc/syntax]

import { Iterable } from '../core/classes/Iterable';

describe('IterableEmbeddedMessageDefaultAction', () => {
it('should create an instance with the correct properties', () => {
Iterable.logger.log(
'iterableEmbeddedMessageElementsButtonAction_fromDict_valid_dictionary'
);

const dict = { type: 'openUrl', data: 'https://example.com' };
const action = IterableEmbeddedMessageElementsButtonAction.fromDict(dict);
expect(action).toBeInstanceOf(IterableEmbeddedMessageElementsButtonAction);
expect(action.type).toBe('openUrl');
expect(action.data).toBe('https://example.com');
});

it('should create an instance from a dictionary with data omitted', () => {
Iterable.logger.log(
'iterableEmbeddedMessageElementsButtonAction_fromDict_valid_dictionary_with_data_omitted'
);

const dict = { type: 'action://join', data: '' };
const action = IterableEmbeddedMessageElementsButtonAction.fromDict(dict);
expect(action).toBeInstanceOf(IterableEmbeddedMessageElementsButtonAction);
expect(action.type).toBe('action://join');
expect(action.data).toBe('');
});

it('should throw an error if type is missing in fromDict', () => {
Iterable.logger.log(
'iterableEmbeddedMessageElementsButtonAction_fromDict_invalid_dictionary_missing_type'
);

const dict = { data: 'foo' };

expect(() =>
IterableEmbeddedMessageElementsButtonAction.fromDict(dict)
).toThrow('type is required');
});
});
Loading