Skip to content
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

[TEST CAPABILITY] backwards compatible example #2624

Draft
wants to merge 1 commit into
base: alexneyman/fb-testing-presence
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions apps/teams-test-app/e2e-test-data/presence.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,25 @@
"status": "InvalidStatus"
},
"expectedTestAppValue": "Error: Error: Invalid status value"
},
{
"title": "setPresence API Call - Invalid Custom Message Type",
"type": "callResponse",
"boxSelector": "#box_setPresence",
"inputValue": {
"status": "Available",
"customMessage": 123
},
"expectedTestAppValue": "Error: Error: Error code: 4000, message: Custom message must be a string"
},
{
"title": "getPresence API Call - Whitespace UPN",
"type": "callResponse",
"boxSelector": "#box_getPresence",
"inputValue": {
"upn": " "
},
"expectedTestAppValue": "Error: Error: Error code: 4000, message: UPN cannot be null or empty"
}
]
}
Expand Down
15 changes: 14 additions & 1 deletion packages/teams-js/src/public/presence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ export function getPresence(params: GetPresenceParams): Promise<UserPresence> {
* - The presence capability is not supported
* - The library has not been initialized
* - The status parameter is invalid
* - The custom message parameter is invalid
*/
export function setPresence(params: SetPresenceParams): Promise<void> {
ensureInitialized(runtime, FrameContexts.content);
Expand All @@ -175,6 +176,7 @@ export function setPresence(params: SetPresenceParams): Promise<void> {
}

validateStatus(params.status);
validateCustomMessage(params.customMessage);

return callFunctionInHostAndHandleResponse(
'presence.setPresence',
Expand Down Expand Up @@ -207,7 +209,7 @@ export function isSupported(): boolean {
* @throws Error if UPN is invalid
*/
function validateUpn(upn: string): void {
if (!upn || upn.length === 0) {
if (!upn || upn.trim().length === 0) {
throw new Error(`Error code: ${ErrorCode.INVALID_ARGUMENTS}, message: UPN cannot be null or empty`);
}
}
Expand All @@ -222,3 +224,14 @@ function validateStatus(status: PresenceStatus): void {
throw new Error(`Error code: ${ErrorCode.INVALID_ARGUMENTS}, message: Invalid presence status`);
}
}

/**
* Validates that the custom message parameter is a string if provided
* @param customMessage The custom message to validate
* @throws Error if custom message is provided but not a string
*/
function validateCustomMessage(customMessage: unknown): void {
if (customMessage !== undefined && typeof customMessage !== 'string') {
throw new Error(`Error code: ${ErrorCode.INVALID_ARGUMENTS}, message: Custom message must be a string`);
}
}
Loading