-
Notifications
You must be signed in to change notification settings - Fork 36
[MOB-11549] creates IterableEmbeddedMessageMetadata class #654
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
Changes from all commits
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,58 @@ | ||
import { IterableEmbeddedMessageMetadata } from '../embedded/classes/IterableEmbeddedMessageMetadata'; | ||
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'; | ||
|
||
describe('IterableEmbeddedMessage', () => { | ||
test('should create an instance of IterableEmbeddedMessageMetadata from a dictionary', () => { | ||
Iterable.logger.log( | ||
'iterableEmbeddedMessageMetadata_fromDict_valid_dictionary' | ||
); | ||
|
||
const dict = { | ||
messageId: '123', | ||
placementId: 456, | ||
campaignId: 789, | ||
isProof: false, | ||
}; | ||
|
||
const result = IterableEmbeddedMessageMetadata.fromDict(dict); | ||
|
||
expect(result).toBeInstanceOf(IterableEmbeddedMessageMetadata); | ||
expect(result.messageId).toBe('123'); | ||
expect(result.placementId).toBe(456); | ||
expect(result.campaignId).toBe(789); | ||
expect(result.isProof).toBe(false); | ||
}); | ||
|
||
test('should handle optional fields', () => { | ||
Iterable.logger.log( | ||
'iterableEmbeddedMessageMetadata_fromDict_optional_fields_omitted' | ||
); | ||
|
||
const dict = { | ||
messageId: '123', | ||
placementId: 456, | ||
}; | ||
|
||
const result = IterableEmbeddedMessageMetadata.fromDict(dict); | ||
|
||
expect(result).toBeInstanceOf(IterableEmbeddedMessageMetadata); | ||
expect(result.messageId).toBe('123'); | ||
expect(result.placementId).toBe(456); | ||
expect(result.campaignId).toBeUndefined(); | ||
expect(result.isProof).toBe(false); | ||
}); | ||
|
||
test('should throw an error if messageId is not provided', () => { | ||
Iterable.logger.log( | ||
'iterableEmbeddedMessageMetadata_fromDict_missing_messageId' | ||
); | ||
|
||
const dict = { | ||
placementId: 456, | ||
}; | ||
|
||
expect(() => { | ||
IterableEmbeddedMessageMetadata.fromDict(dict); | ||
}).toThrow('messageId and placementId are required'); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** | ||
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. 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. |
||
* Metadata for an embedded message. | ||
*/ | ||
export class IterableEmbeddedMessageMetadata { | ||
/** The ID for the embedded message */ | ||
readonly messageId: string; | ||
/** The placement ID for the embedded message */ | ||
readonly placementId: number; | ||
/** The campaign ID for the embedded message */ | ||
readonly campaignId?: number; | ||
/** Whether the embedded message is a proof */ | ||
readonly isProof: boolean; | ||
|
||
/** | ||
* Constructs an instance of IterableEmbeddedMessageMetadata. | ||
* | ||
* @param messageId - The ID for the embedded message. | ||
* @param placementId - The placement ID for the embedded message. | ||
* @param campaignId - The campaign ID for the embedded message. | ||
* @param isProof - Whether the embedded message is a proof. | ||
*/ | ||
constructor( | ||
messageId: string, | ||
placementId: number, | ||
campaignId: number | undefined, | ||
isProof: boolean = false | ||
Comment on lines
+22
to
+26
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.
Comment on lines
+22
to
+26
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.
Comment on lines
+22
to
+26
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. |
||
) { | ||
this.messageId = messageId; | ||
this.placementId = placementId; | ||
this.campaignId = campaignId; | ||
this.isProof = isProof; | ||
} | ||
|
||
/** | ||
* Creates an instance of `IterableEmbeddedMessageMetadata` from a dictionary object. | ||
* | ||
* @param dict - The dictionary objectcontaining the metadata properties. | ||
* This corresponds to the properties in {@link IterableEmbeddedMessageMetadata} | ||
* | ||
* @returns A new instance of `IterableEmbeddedMessageMetadata` with the provided properties. | ||
*/ | ||
static fromDict( | ||
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. Side rant: Personally, I really don't like the That being said, we use 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. Hm yeah maybe that can be a future improvement. 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.
|
||
dict: Partial<EmbeddedMessageMetadataDict> | ||
): IterableEmbeddedMessageMetadata { | ||
if (!dict.messageId || !dict.placementId) { | ||
throw new Error('messageId and placementId are required'); | ||
} | ||
return new IterableEmbeddedMessageMetadata( | ||
dict.messageId, | ||
dict.placementId, | ||
dict.campaignId, | ||
dict.isProof | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* An interface defining the dictionary object containing the metadata properties for an embedded message. | ||
*/ | ||
export interface EmbeddedMessageMetadataDict { | ||
messageId: string; | ||
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. Please comment what each of the props are |
||
placementId: number; | ||
campaignId?: number; | ||
isProof?: boolean; | ||
} |
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]