-
Notifications
You must be signed in to change notification settings - Fork 37
[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
Open
evantk91
wants to merge
24
commits into
evan/feature/embedded
Choose a base branch
from
evan/MOB-11649
base: evan/feature/embedded
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 18 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
1c56ff1
feat: adds button class and associated classes
4578c01
feat: adds unit tests
57f48a3
feat: adds elements class and associated classes
a3397a4
feat: adds unit tests
79e7225
feat: adds message class and unit tests
27af816
Merge branch 'evan/embedded-message-class' into evan/MOB-11550-iterab…
evantk91 12ac9b6
Merge pull request #655 from Iterable/evan/MOB-11550-iterable-embedde…
evantk91 80d7981
feat: adds labels for dict
aa2be62
Merge branch 'evan/embedded-message-class' into evan/MOB-11550-iterab…
evantk91 d6b0a0a
Merge pull request #667 from Iterable/evan/MOB-11550-iterable-embedde…
evantk91 a292556
Merge branch 'evan/embedded-message-class' into evan/MOB-11551-iterab…
evantk91 58fe64e
chore: adds comments to props
2b2899c
Merge pull request #656 from Iterable/evan/MOB-11551-iterable-embedde…
evantk91 3a486d6
Merge branch 'evan/embedded-message-class' into evan/MOB-7936-iterabl…
evantk91 84e6a68
chore: adds comments to props
8df97eb
Merge pull request #657 from Iterable/evan/MOB-7936-iterable-embedded…
evantk91 cad9c3e
feat: merges action into button
5f51526
feat: updates IterableEmbeddedMessageText class
7c2c8aa
feat: converts IterableEmbeddedMessageElements constructor
3c0e01d
feat: removes default action class
56b33b0
feat: converts IterableEmbeddedMessage constructor
1db3333
feat: converts IterableEmbeddedMessage constructor
2b627f3
feat: removes embedded metadata class
6701a64
feat: combines message and elements in one class
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
import { IterableEmbeddedMessage } from '../embedded/classes/IterableEmbeddedMessage'; | ||
import { IterableEmbeddedMessageMetadata } from '../embedded/classes/IterableEmbeddedMessageMetadata'; | ||
import { IterableEmbeddedMessageElements } from '../embedded/classes/IterableEmbeddedMessageElements'; | ||
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 = IterableEmbeddedMessage.fromDict(dict); | ||
|
||
expect(message).toBeInstanceOf(IterableEmbeddedMessage); | ||
|
||
// Check metadata | ||
expect(message.metadata).toBeInstanceOf(IterableEmbeddedMessageMetadata); | ||
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(IterableEmbeddedMessageElements); | ||
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 = IterableEmbeddedMessage.fromDict(dict); | ||
|
||
expect(message).toBeInstanceOf(IterableEmbeddedMessage); | ||
expect(message.metadata).toBeInstanceOf(IterableEmbeddedMessageMetadata); | ||
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', | ||
}, | ||
}; | ||
|
||
expect(() => IterableEmbeddedMessage.fromDict(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 = IterableEmbeddedMessage.fromDict(dict); | ||
|
||
expect(message).toBeInstanceOf(IterableEmbeddedMessage); | ||
expect(message.metadata).toBeInstanceOf(IterableEmbeddedMessageMetadata); | ||
expect(message.elements).toBeInstanceOf(IterableEmbeddedMessageElements); | ||
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 = IterableEmbeddedMessage.fromDict(dict); | ||
|
||
expect(message).toBeInstanceOf(IterableEmbeddedMessage); | ||
expect(message.metadata).toBeInstanceOf(IterableEmbeddedMessageMetadata); | ||
expect(message.elements).toBeUndefined(); | ||
expect(message.payload).toEqual({ | ||
someData: 'someValue', | ||
}); | ||
}); | ||
}); |
40 changes: 40 additions & 0 deletions
40
src/__tests__/IterableEmbeddedMessageDefaultAction.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { IterableEmbeddedMessageDefaultAction } from '../embedded/classes/IterableEmbeddedMessageDefaultAction'; | ||
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' | ||
); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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]