Skip to content

Commit e8cbd36

Browse files
committed
DEVX-10006: addig tests and implementation for RCS Create Calendar Event suggestion action
1 parent 352b43d commit e8cbd36

File tree

4 files changed

+161
-5
lines changed

4 files changed

+161
-5
lines changed

messages/src/vonage_messages/models/__init__.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,22 @@
1010
MessengerVideo,
1111
)
1212
from .mms import MmsAudio, MmsImage, MmsResource, MmsVcard, MmsVideo
13-
from .rcs import RcsCustom, RcsFile, RcsImage, RcsResource, RcsText, RcsVideo, RcsSuggestionBase, RcsSuggestionReply, RcsSuggestionActionDial, RcsSuggestionActionViewLocation, RcsSuggestionActionShareLocation, RcsSuggestionActionOpenUrl, RcsSuggestionActionOpenUrlWebview
13+
from .rcs import (
14+
RcsCustom,
15+
RcsFile,
16+
RcsImage,
17+
RcsResource,
18+
RcsText,
19+
RcsVideo,
20+
RcsSuggestionBase,
21+
RcsSuggestionReply,
22+
RcsSuggestionActionDial,
23+
RcsSuggestionActionViewLocation,
24+
RcsSuggestionActionShareLocation,
25+
RcsSuggestionActionOpenUrl,
26+
RcsSuggestionActionOpenUrlWebview,
27+
RcsSuggestionActionCreateCalendarEvent,
28+
)
1429
from .sms import Sms, SmsOptions
1530
from .viber import (
1631
ViberAction,

messages/src/vonage_messages/models/enums.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class SuggestionType(str, Enum):
4848
SHARE_LOCATION = 'share_location'
4949
OPEN_URL = 'open_url'
5050
OPEN_URL_IN_WEBVIEW = 'open_url_in_webview'
51+
CREATE_CALENDAR_EVENT = 'create_calendar_event'
5152

5253

5354
class UrlWebviewViewMode(str, Enum):

messages/src/vonage_messages/models/rcs.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,26 @@ class RcsSuggestionActionOpenUrlWebview(RcsSuggestionActionOpenUrl):
110110
type_: SuggestionType = Field(SuggestionType.OPEN_URL_IN_WEBVIEW, serialization_alias='type')
111111
view_mode: Optional[UrlWebviewViewMode] = None
112112

113+
class RcsSuggestionActionCreateCalendarEvent(RcsSuggestionBase):
114+
"""Model for a create calendar event action suggestion in an RCS message.
115+
116+
Args:
117+
text (str): The text to display on the suggestion chip.
118+
postback_data (str): The data that will be sent via the Inbound Message webhook when the suggestion is selected.
119+
start_time (str): The start time of the calendar event in ISO 8601 format.
120+
end_time (str): The end time of the calendar event in ISO 8601 format
121+
title (str): The title of the calendar event.
122+
description (str): The description of the calendar event.
123+
fallback_url (str, Optional): The URL to open if the device doesn't support the create calendar event action.
124+
"""
125+
126+
type_: SuggestionType = Field(SuggestionType.CREATE_CALENDAR_EVENT, serialization_alias='type')
127+
start_time: str
128+
end_time: str
129+
title: str = Field(..., min_length=1, max_length=100)
130+
description: str = Field(..., min_length=1, max_length=500)
131+
fallback_url: Optional[str] = None
132+
113133

114134
class BaseRcs(BaseMessage):
115135
"""Model for a base RCS message.

messages/tests/test_rcs_models.py

Lines changed: 124 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
RcsSuggestionActionShareLocation,
1515
RcsSuggestionActionOpenUrl,
1616
RcsSuggestionActionOpenUrlWebview,
17+
RcsSuggestionActionCreateCalendarEvent,
1718
)
1819

1920

@@ -391,7 +392,6 @@ def test_rcs_suggestion_action_open_url_in_webview():
391392
assert suggestion.model_dump(by_alias=True, exclude_none=True) == suggestion_dict
392393

393394

394-
# @pytest.mark.skip(reason="Not yet implemented")
395395
def test_rcs_suggestion_action_open_url_in_webview_without_url():
396396
with pytest.raises(ValidationError) as err:
397397
suggestion = RcsSuggestionActionOpenUrlWebview(
@@ -402,7 +402,6 @@ def test_rcs_suggestion_action_open_url_in_webview_without_url():
402402
assert "Field required" in str(err.value)
403403

404404

405-
# @pytest.mark.skip(reason="Not yet implemented")
406405
def test_rcs_suggestion_action_open_url_in_webview_without_description():
407406
with pytest.raises(ValidationError) as err:
408407
suggestion = RcsSuggestionActionOpenUrlWebview(
@@ -413,7 +412,6 @@ def test_rcs_suggestion_action_open_url_in_webview_without_description():
413412
assert "Field required" in str(err.value)
414413

415414

416-
# @pytest.mark.skip(reason="Not yet implemented")
417415
def test_rcs_suggestion_action_open_url_in_webview_with_description_too_short():
418416
with pytest.raises(ValidationError) as err:
419417
suggestion = RcsSuggestionActionOpenUrlWebview(
@@ -425,7 +423,6 @@ def test_rcs_suggestion_action_open_url_in_webview_with_description_too_short():
425423
assert "String should have at least 1 character" in str(err.value)
426424

427425

428-
# @pytest.mark.skip(reason="Not yet implemented")
429426
def test_rcs_suggestion_action_open_url_in_webview_with_description_too_long():
430427
with pytest.raises(ValidationError) as err:
431428
suggestion = RcsSuggestionActionOpenUrlWebview(
@@ -447,3 +444,126 @@ def test_rcs_suggestion_action_open_url_in_webview_with_invalid_view_mode():
447444
view_mode='INVALID_VIEW_MODE',
448445
)
449446
assert "Input should be 'FULL', 'TALL' or 'HALF'" in str(err.value)
447+
448+
449+
def test_rcs_suggestion_action_create_calendar_event():
450+
suggestion = RcsSuggestionActionCreateCalendarEvent(
451+
text='Add to calendar',
452+
postback_data='postback-data',
453+
start_time='2024-01-01T12:00:00Z',
454+
end_time='2024-01-01T13:00:00Z',
455+
title='Meeting with Bob',
456+
description='Discuss project updates',
457+
fallback_url='https://example.com/calendar-event',
458+
)
459+
suggestion_dict = {
460+
'type': 'create_calendar_event',
461+
'text': 'Add to calendar',
462+
'postback_data': 'postback-data',
463+
'start_time': '2024-01-01T12:00:00Z',
464+
'end_time': '2024-01-01T13:00:00Z',
465+
'title': 'Meeting with Bob',
466+
'description': 'Discuss project updates',
467+
'fallback_url': 'https://example.com/calendar-event',
468+
}
469+
assert suggestion.model_dump(by_alias=True, exclude_none=True) == suggestion_dict
470+
471+
472+
def test_rcs_suggestion_action_create_calendar_event_without_start_time():
473+
with pytest.raises(ValidationError) as err:
474+
suggestion = RcsSuggestionActionCreateCalendarEvent(
475+
text='Add to calendar',
476+
postback_data='postback-data',
477+
end_time='2024-01-01T13:00:00Z',
478+
title='Meeting with Bob',
479+
description='Discuss project updates',
480+
)
481+
assert "Field required" in str(err.value)
482+
483+
484+
def test_rcs_suggestion_action_create_calendar_event_without_end_time():
485+
with pytest.raises(ValidationError) as err:
486+
suggestion = RcsSuggestionActionCreateCalendarEvent(
487+
text='Add to calendar',
488+
postback_data='postback-data',
489+
start_time='2024-01-01T12:00:00Z',
490+
title='Meeting with Bob',
491+
description='Discuss project updates',
492+
)
493+
assert "Field required" in str(err.value)
494+
495+
496+
def test_rcs_suggestion_action_create_calendar_event_without_title():
497+
with pytest.raises(ValidationError) as err:
498+
suggestion = RcsSuggestionActionCreateCalendarEvent(
499+
text='Add to calendar',
500+
postback_data='postback-data',
501+
start_time='2024-01-01T12:00:00Z',
502+
end_time='2024-01-01T13:00:00Z',
503+
description='Discuss project updates',
504+
)
505+
assert "Field required" in str(err.value)
506+
507+
508+
def test_rcs_suggestion_action_create_calendar_event_without_description():
509+
with pytest.raises(ValidationError) as err:
510+
suggestion = RcsSuggestionActionCreateCalendarEvent(
511+
text='Add to calendar',
512+
postback_data='postback-data',
513+
start_time='2024-01-01T12:00:00Z',
514+
end_time='2024-01-01T13:00:00Z',
515+
title='Meeting with Bob',
516+
)
517+
assert "Field required" in str(err.value)
518+
519+
520+
def test_rcs_suggestion_action_create_calendar_event_with_title_too_short():
521+
with pytest.raises(ValidationError) as err:
522+
suggestion = RcsSuggestionActionCreateCalendarEvent(
523+
text='Add to calendar',
524+
postback_data='postback-data',
525+
start_time='2024-01-01T12:00:00Z',
526+
end_time='2024-01-01T13:00:00Z',
527+
title='',
528+
description='Discuss project updates',
529+
)
530+
assert "String should have at least 1 character" in str(err.value)
531+
532+
533+
def test_rcs_suggestion_action_create_calendar_event_with_title_too_long():
534+
with pytest.raises(ValidationError) as err:
535+
suggestion = RcsSuggestionActionCreateCalendarEvent(
536+
text='Add to calendar',
537+
postback_data='postback-data',
538+
start_time='2024-01-01T12:00:00Z',
539+
end_time='2024-01-01T13:00:00Z',
540+
title='A' * 100 + 'B',
541+
description='Discuss project updates',
542+
)
543+
assert "String should have at most 100 characters" in str(err.value)
544+
545+
546+
def test_rcs_suggestion_action_create_calendar_event_with_description_too_short():
547+
with pytest.raises(ValidationError) as err:
548+
suggestion = RcsSuggestionActionCreateCalendarEvent(
549+
text='Add to calendar',
550+
postback_data='postback-data',
551+
start_time='2024-01-01T12:00:00Z',
552+
end_time='2024-01-01T13:00:00Z',
553+
title='Meeting with Bob',
554+
description='',
555+
)
556+
assert "String should have at least 1 character" in str(err.value)
557+
558+
559+
def test_rcs_suggestion_action_create_calendar_event_with_description_too_long():
560+
with pytest.raises(ValidationError) as err:
561+
suggestion = RcsSuggestionActionCreateCalendarEvent(
562+
text='Add to calendar',
563+
postback_data='postback-data',
564+
start_time='2024-01-01T12:00:00Z',
565+
end_time='2024-01-01T13:00:00Z',
566+
title='Meeting with Bob',
567+
description='A' * 500 + 'B',
568+
)
569+
assert "String should have at most 500 characters" in str(err.value)

0 commit comments

Comments
 (0)