-
Notifications
You must be signed in to change notification settings - Fork 38
[MOB-11649] updated embedded message class #670
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: evan/feature/embedded
Are you sure you want to change the base?
Changes from all commits
1c56ff1
4578c01
57f48a3
a3397a4
79e7225
27af816
12ac9b6
80d7981
aa2be62
d6b0a0a
a292556
58fe64e
2b2899c
3a486d6
84e6a68
8df97eb
cad9c3e
5f51526
7c2c8aa
3c0e01d
56b33b0
1db3333
2b627f3
6701a64
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
import { IterableEmbeddedMessage } from '../embedded/classes/IterableEmbeddedMessage'; | ||
import { Iterable } from '../core/classes/Iterable'; | ||
|
||
describe('IterableEmbeddedMessage', () => { | ||
it('should create an instance with all properties', () => { | ||
Iterable.logger.log('iterableEmbeddedMessage_fromDict_all_properties'); | ||
|
||
const dict = { | ||
metadata: { | ||
messageId: 'msg-123', | ||
placementId: 1, | ||
campaignId: 456, | ||
isProof: false, | ||
}, | ||
elements: { | ||
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', | ||
}, | ||
}, | ||
], | ||
text: [ | ||
{ | ||
id: 'text-1', | ||
text: 'Some cool text', | ||
type: 'body', | ||
}, | ||
], | ||
}, | ||
payload: { | ||
customKey: 'customValue', | ||
anotherKey: 123, | ||
}, | ||
}; | ||
|
||
const message = new IterableEmbeddedMessage(dict); | ||
|
||
expect(message).toBeInstanceOf(IterableEmbeddedMessage); | ||
|
||
// Check metadata | ||
expect(message.metadata).toBeInstanceOf(Object); | ||
expect(message.metadata.messageId).toBe('msg-123'); | ||
expect(message.metadata.placementId).toBe(1); | ||
expect(message.metadata.campaignId).toBe(456); | ||
expect(message.metadata.isProof).toBe(false); | ||
|
||
// Check elements | ||
expect(message.elements).toBeInstanceOf(Object); | ||
expect(message.elements?.title).toBe('Awesome Title'); | ||
expect(message.elements?.body).toBe('Radical Body Text'); | ||
expect(message.elements?.mediaUrl).toBe('https://example.com/image.jpg'); | ||
expect(message.elements?.mediaUrlCaption).toBe( | ||
'Check out this sick image!' | ||
); | ||
|
||
// Check payload | ||
expect(message.payload).toEqual({ | ||
customKey: 'customValue', | ||
anotherKey: 123, | ||
}); | ||
}); | ||
|
||
it('should create an instance with only required metadata', () => { | ||
Iterable.logger.log('iterableEmbeddedMessage_fromDict_required_only'); | ||
|
||
const dict = { | ||
metadata: { | ||
messageId: 'msg-123', | ||
placementId: 1, | ||
isProof: false, | ||
}, | ||
}; | ||
|
||
const message = new IterableEmbeddedMessage(dict); | ||
|
||
expect(message).toBeInstanceOf(IterableEmbeddedMessage); | ||
expect(message.metadata).toBeInstanceOf(Object); | ||
expect(message.metadata.messageId).toBe('msg-123'); | ||
expect(message.metadata.placementId).toBe(1); | ||
expect(message.metadata.campaignId).toBeUndefined(); | ||
expect(message.metadata.isProof).toBe(false); | ||
expect(message.elements).toBeUndefined(); | ||
expect(message.payload).toBeUndefined(); | ||
}); | ||
|
||
it('should throw an error if metadata is missing', () => { | ||
Iterable.logger.log('iterableEmbeddedMessage_fromDict_missing_metadata'); | ||
|
||
const dict = { | ||
elements: { | ||
title: 'Some Title', | ||
body: 'Some Body', | ||
}, | ||
}; | ||
|
||
// @ts-expect-error - metadata is purposely missing | ||
expect(() => new IterableEmbeddedMessage(dict)).toThrow( | ||
'metadata is required' | ||
); | ||
}); | ||
|
||
it('should create an instance with elements but no payload', () => { | ||
Iterable.logger.log('iterableEmbeddedMessage_fromDict_elements_only'); | ||
|
||
const dict = { | ||
metadata: { | ||
messageId: 'msg-123', | ||
placementId: 1, | ||
isProof: false, | ||
}, | ||
elements: { | ||
title: 'Elements Only', | ||
body: 'No payload here', | ||
}, | ||
}; | ||
|
||
const message = new IterableEmbeddedMessage(dict); | ||
|
||
expect(message).toBeInstanceOf(IterableEmbeddedMessage); | ||
expect(message.metadata).toBeInstanceOf(Object); | ||
expect(message.elements).toBeInstanceOf(Object); | ||
expect(message.elements?.title).toBe('Elements Only'); | ||
expect(message.elements?.body).toBe('No payload here'); | ||
expect(message.payload).toBeUndefined(); | ||
}); | ||
|
||
it('should create an instance with payload but no elements', () => { | ||
Iterable.logger.log('iterableEmbeddedMessage_fromDict_payload_only'); | ||
|
||
const dict = { | ||
metadata: { | ||
messageId: 'msg-123', | ||
placementId: 1, | ||
isProof: false, | ||
}, | ||
payload: { | ||
someData: 'someValue', | ||
}, | ||
}; | ||
|
||
const message = new IterableEmbeddedMessage(dict); | ||
|
||
expect(message).toBeInstanceOf(IterableEmbeddedMessage); | ||
expect(message.metadata).toBeInstanceOf(Object); | ||
expect(message.elements).toBeUndefined(); | ||
expect(message.payload).toEqual({ | ||
someData: 'someValue', | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { IterableEmbeddedMessageButton } from '../embedded/classes/IterableEmbeddedMessageButton'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
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 = new IterableEmbeddedMessageButton(dict); | ||
|
||
expect(button).toBeInstanceOf(IterableEmbeddedMessageButton); | ||
expect(button.id).toBe('button-123'); | ||
expect(button.title).toBe('Click Me!'); | ||
expect(button.action).toBeInstanceOf(Object); | ||
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 = new IterableEmbeddedMessageButton(dict); | ||
|
||
expect(button).toBeInstanceOf(IterableEmbeddedMessageButton); | ||
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 = new IterableEmbeddedMessageButton(dict); | ||
|
||
expect(button).toBeInstanceOf(IterableEmbeddedMessageButton); | ||
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', () => { | ||
Iterable.logger.log('iterableEmbeddedMessageButton_fromDict_missing_id'); | ||
|
||
const dict = { | ||
title: 'Click Me!', | ||
action: { type: 'openUrl', data: 'https://example.com' }, | ||
}; | ||
// @ts-expect-error - id is purposely missing | ||
expect(() => new IterableEmbeddedMessageButton(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 = new IterableEmbeddedMessageButton(dict); | ||
|
||
expect(button).toBeInstanceOf(IterableEmbeddedMessageButton); | ||
expect(button.id).toBe('button-123'); | ||
expect(button.action).toBeInstanceOf(Object); | ||
expect(button.action?.type).toBe('close'); | ||
expect(button.action?.data).toBeUndefined(); | ||
}); | ||
}); |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { IterableEmbeddedMessageText } from '../embedded/classes/IterableEmbeddedMessageText'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
import { Iterable } from '../core/classes/Iterable'; | ||
|
||
describe('IterableEmbeddedMessageText', () => { | ||
it('should create an instance from a dictionary with all properties', () => { | ||
Iterable.logger.log('iterableEmbeddedMessageText_fromDict_all_properties'); | ||
|
||
const dict = { id: 'text-123', text: 'Hello World!', type: 'heading' }; | ||
const text = new IterableEmbeddedMessageText(dict); | ||
|
||
expect(text).toBeInstanceOf(IterableEmbeddedMessageText); | ||
expect(text.id).toBe('text-123'); | ||
expect(text.text).toBe('Hello World!'); | ||
expect(text.type).toBe('heading'); | ||
}); | ||
|
||
it('should create an instance from a dictionary with only required properties', () => { | ||
Iterable.logger.log('iterableEmbeddedMessageText_fromDict_required_only'); | ||
|
||
const dict = { id: 'text-123' }; | ||
const text = new IterableEmbeddedMessageText(dict); | ||
|
||
expect(text).toBeInstanceOf(IterableEmbeddedMessageText); | ||
expect(text.id).toBe('text-123'); | ||
expect(text.text).toBeUndefined(); | ||
expect(text.type).toBeUndefined(); | ||
}); | ||
|
||
it('should throw an error if id is missing in fromDict', () => { | ||
Iterable.logger.log('iterableEmbeddedMessageText_fromDict_missing_id'); | ||
|
||
const dict = { text: 'Hello World!', type: 'heading' }; | ||
|
||
// @ts-expect-error - id is purposely missing | ||
expect(() => new IterableEmbeddedMessageText(dict)).toThrow( | ||
'id is required' | ||
); | ||
}); | ||
}); |
There was a problem hiding this comment.
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]