From b65e22a8af5798da915e3cf71c878f9986eefc12 Mon Sep 17 00:00:00 2001 From: "Alex Kwan (IC3)" Date: Mon, 2 Dec 2024 11:32:16 -0800 Subject: [PATCH] adding in additional unit tests --- ...-e4791dc2-7f02-4b0d-9147-ca8b52f51701.json | 9 +++++ packages/acs-ui-common/src/identifier.test.ts | 38 ++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 change/@azure-communication-react-e4791dc2-7f02-4b0d-9147-ca8b52f51701.json diff --git a/change/@azure-communication-react-e4791dc2-7f02-4b0d-9147-ca8b52f51701.json b/change/@azure-communication-react-e4791dc2-7f02-4b0d-9147-ca8b52f51701.json new file mode 100644 index 00000000000..3d1f37618bd --- /dev/null +++ b/change/@azure-communication-react-e4791dc2-7f02-4b0d-9147-ca8b52f51701.json @@ -0,0 +1,9 @@ +{ + "type": "none", + "area": "improvement", + "workstream": "[Test Coverage] Adding additional unit tests for _isValidIdentifier and _toCommunicationIdentifier", + "comment": "Added on several unit tests to the acs-ui-common packlet", + "packageName": "@azure/communication-react", + "email": "alkwa@microsoft.com", + "dependentChangeType": "none" +} diff --git a/packages/acs-ui-common/src/identifier.test.ts b/packages/acs-ui-common/src/identifier.test.ts index fb87e4034ac..7da0451f86e 100644 --- a/packages/acs-ui-common/src/identifier.test.ts +++ b/packages/acs-ui-common/src/identifier.test.ts @@ -7,7 +7,12 @@ import { isPhoneNumberIdentifier, isUnknownIdentifier } from '@azure/communication-common'; -import { fromFlatCommunicationIdentifier, toFlatCommunicationIdentifier } from './identifier'; +import { + fromFlatCommunicationIdentifier, + toFlatCommunicationIdentifier, + _toCommunicationIdentifier, + _isValidIdentifier +} from './identifier'; test('Communication user conversions', () => { const parsed = fromFlatCommunicationIdentifier('8:acs:OPAQUE'); @@ -94,3 +99,34 @@ test('Unknown user conversions', () => { }); expect(toFlatCommunicationIdentifier(parsed)).toEqual('OPAQUE'); }); + +test('toCommunicationIdentifier with communication identifier', () => { + const userId = { kind: 'communicationUser', communicationUserId: '8:acs:OPAQUE' }; + const identifierResponse = _toCommunicationIdentifier(userId); + expect(userId).toEqual(identifierResponse); + expect(identifierResponse).toEqual({ + kind: 'communicationUser', + communicationUserId: '8:acs:OPAQUE' + }); +}); + +test('toCommunicationIdentifier with communication identifier as string', () => { + const identifierResponse = _toCommunicationIdentifier('8:acs:OPAQUE'); + expect(isCommunicationUserIdentifier(identifierResponse)).toBeTruthy(); + expect(identifierResponse).toEqual({ + kind: 'communicationUser', + communicationUserId: '8:acs:OPAQUE' + }); +}); + +test('isValidIdentifier with communication identifier', () => { + const userId = { kind: 'communicationUser', communicationUserId: '8:acs:OPAQUE' }; + const isValid = _isValidIdentifier(userId); + expect(isValid).toBeTruthy(); +}); + +test('isValidIdentifier with unknown identifier', () => { + const userId = { kind: 'unknown', id: 'OPAQUE' }; + const isValid = _isValidIdentifier(userId); + expect(isValid).toBeTruthy(); +});