Skip to content

Commit 5f51526

Browse files
author
Evan Greer
committed
feat: updates IterableEmbeddedMessageText class
1 parent cad9c3e commit 5f51526

3 files changed

Lines changed: 11 additions & 21 deletions

File tree

src/__tests__/IterableEmbeddedMessageText.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ describe('IterableEmbeddedMessageText', () => {
66
Iterable.logger.log('iterableEmbeddedMessageText_fromDict_all_properties');
77

88
const dict = { id: 'text-123', text: 'Hello World!', type: 'heading' };
9-
const text = IterableEmbeddedMessageText.fromDict(dict);
9+
const text = new IterableEmbeddedMessageText(dict);
1010

1111
expect(text).toBeInstanceOf(IterableEmbeddedMessageText);
1212
expect(text.id).toBe('text-123');
@@ -18,7 +18,7 @@ describe('IterableEmbeddedMessageText', () => {
1818
Iterable.logger.log('iterableEmbeddedMessageText_fromDict_required_only');
1919

2020
const dict = { id: 'text-123' };
21-
const text = IterableEmbeddedMessageText.fromDict(dict);
21+
const text = new IterableEmbeddedMessageText(dict);
2222

2323
expect(text).toBeInstanceOf(IterableEmbeddedMessageText);
2424
expect(text.id).toBe('text-123');
@@ -31,7 +31,8 @@ describe('IterableEmbeddedMessageText', () => {
3131

3232
const dict = { text: 'Hello World!', type: 'heading' };
3333

34-
expect(() => IterableEmbeddedMessageText.fromDict(dict)).toThrow(
34+
// @ts-expect-error - id is purposely missing
35+
expect(() => new IterableEmbeddedMessageText(dict)).toThrow(
3536
'id is required'
3637
);
3738
});

src/embedded/classes/IterableEmbeddedMessageElements.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ export class IterableEmbeddedMessageElements {
7171
(button) => new IterableEmbeddedMessageElementsButton(button)
7272
);
7373

74-
const text = dict.text?.map((text) =>
75-
IterableEmbeddedMessageText.fromDict(text)
74+
const text = dict.text?.map(
75+
(text) => new IterableEmbeddedMessageText(text)
7676
);
7777

7878
return new IterableEmbeddedMessageElements(

src/embedded/classes/IterableEmbeddedMessageText.ts

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,14 @@ export class IterableEmbeddedMessageText {
1616
* @param text - The text of the text element
1717
* @param type - The type of the text element
1818
*/
19-
constructor(id: string, text?: string, type?: string) {
20-
this.id = id;
21-
this.text = text;
22-
this.type = type;
23-
}
24-
25-
/**
26-
* Creates an instance of `IterableEmbeddedMessageText` from a dictionary object.
27-
*
28-
* @param dict - The dictionary object containing the properties to initialize the `IterableEmbeddedMessageText` instance.
29-
* @returns A new instance of `IterableEmbeddedMessageText` initialized with the provided dictionary properties.
30-
*/
31-
static fromDict(
32-
dict: Partial<EmbeddedMessageTextDict>
33-
): IterableEmbeddedMessageText {
19+
constructor(dict: EmbeddedMessageTextDict) {
3420
if (!dict.id) {
3521
throw new Error('id is required');
3622
}
37-
return new IterableEmbeddedMessageText(dict.id, dict.text, dict.type);
23+
24+
this.id = dict.id;
25+
this.text = dict.text;
26+
this.type = dict.type;
3827
}
3928
}
4029

0 commit comments

Comments
 (0)