Skip to content

Commit aacfeae

Browse files
author
Evan Greer
committed
feat: adds IterableEmbeddedMessageDefaultAction and associated tests
1 parent 626a256 commit aacfeae

3 files changed

Lines changed: 66 additions & 5 deletions

File tree

src/__tests__/IterableEmbeddedMesageMetadata.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { IterableEmbeddedMessageMetadata } from '../embedded/classes/IterableEmbeddedMessageMetadata';
2-
import type { EmbeddedMessageMetadataDict } from '../embedded/classes/IterableEmbeddedMessageMetadata';
32
import { Iterable } from '../core';
43

54
describe('IterableEmbeddedMessage', () => {
@@ -53,9 +52,7 @@ describe('IterableEmbeddedMessage', () => {
5352
};
5453

5554
expect(() => {
56-
IterableEmbeddedMessageMetadata.fromDict(
57-
dict as Partial<EmbeddedMessageMetadataDict>
58-
);
55+
IterableEmbeddedMessageMetadata.fromDict(dict);
5956
}).toThrow('messageId and placementId are required');
6057
});
6158
});
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { IterableEmbeddedMessageDefaultAction } from '../embedded/classes/IterableEmbeddedMessageDefaultAction';
2+
import { Iterable } from '../core/classes/Iterable';
3+
4+
describe('IterableEmbeddedMessageDefaultAction', () => {
5+
it('should create an instance with the correct properties', () => {
6+
Iterable.logger.log(
7+
'iterableEmbeddedMessageDefaultAction_fromDict_valid_dictionary'
8+
);
9+
10+
const action = new IterableEmbeddedMessageDefaultAction(
11+
'openUrl',
12+
'https://example.com'
13+
);
14+
expect(action).toBeInstanceOf(IterableEmbeddedMessageDefaultAction);
15+
expect(action.type).toBe('openUrl');
16+
expect(action.data).toBe('https://example.com');
17+
});
18+
19+
it('should create an instance from a dictionary with data omitted', () => {
20+
Iterable.logger.log(
21+
'iterableEmbeddedMessageDefaultAction_fromDict_valid_dictionary_with_data_omitted'
22+
);
23+
24+
const dict = { type: 'action://join', data: '' };
25+
const action = IterableEmbeddedMessageDefaultAction.fromDict(dict);
26+
expect(action).toBeInstanceOf(IterableEmbeddedMessageDefaultAction);
27+
expect(action.type).toBe('action://join');
28+
expect(action.data).toBe('');
29+
});
30+
31+
it('should throw an error if type is missing in fromDict', () => {
32+
Iterable.logger.log(
33+
'iterableEmbeddedMessageDefaultAction_fromDict_invalid_dictionary_missing_type'
34+
);
35+
36+
const dict = { data: 'foo' };
37+
38+
expect(() => IterableEmbeddedMessageDefaultAction.fromDict(dict)).toThrow(
39+
'type is required'
40+
);
41+
});
42+
});
Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,23 @@
1-
export class IterableEmbeddedMessageDefaultAction {}
1+
export class IterableEmbeddedMessageDefaultAction {
2+
readonly type: string;
3+
readonly data?: string;
4+
5+
constructor(type: string, data?: string) {
6+
this.type = type;
7+
this.data = data;
8+
}
9+
10+
static fromDict(
11+
dict: Partial<EmbeddedMessageDefaultActionDict>
12+
): IterableEmbeddedMessageDefaultAction {
13+
if (!dict.type) {
14+
throw new Error('type is required');
15+
}
16+
return new IterableEmbeddedMessageDefaultAction(dict.type, dict.data);
17+
}
18+
}
19+
20+
export interface EmbeddedMessageDefaultActionDict {
21+
type: string;
22+
data?: string;
23+
}

0 commit comments

Comments
 (0)