Skip to content

Commit

Permalink
map the create thread result (Azure#14178)
Browse files Browse the repository at this point in the history
  • Loading branch information
LuChen-Microsoft authored Mar 8, 2021
1 parent 3f1d0e7 commit bbd9e2a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
8 changes: 6 additions & 2 deletions sdk/communication/communication-chat/src/chatClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ import {
ListChatThreadsOptions,
DeleteChatThreadOptions
} from "./models/options";
import { mapToChatThreadSdkModel, mapToChatParticipantRestModel } from "./models/mappers";
import {
mapToChatThreadSdkModel,
mapToChatParticipantRestModel,
mapToCreateChatThreadResultSdkModel
} from "./models/mappers";
import {
ChatThreadInfo,
CreateChatThreadResult,
Expand Down Expand Up @@ -140,7 +144,7 @@ export class ChatClient {
},
operationOptionsToRequestOptionsBase(updatedOptions)
);
return result;
return mapToCreateChatThreadResultSdkModel(result);
} catch (e) {
span.setStatus({
code: CanonicalCode.UNKNOWN,
Expand Down
21 changes: 20 additions & 1 deletion sdk/communication/communication-chat/src/models/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {
ChatThread,
ChatParticipant,
ChatMessageReadReceipt,
ChatMessageContent
ChatMessageContent,
CreateChatThreadResult
} from "./models";

/**
Expand Down Expand Up @@ -126,6 +127,24 @@ export const mapToChatThreadSdkModel = (chatThread: RestModel.ChatThread): ChatT
}
};

/**
* @internal
* Mapping chat thread REST model to chat thread SDK model
*/
export const mapToCreateChatThreadResultSdkModel = (
result: RestModel.CreateChatThreadResult
): CreateChatThreadResult => {
const { chatThread, ...rest } = result;
if (chatThread)
return {
...rest,
chatThread: mapToChatThreadSdkModel(chatThread)
};
else {
return { ...rest };
}
};

/**
* @internal
* Mapping read receipt REST model to read receipt SDK model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ describe("[Mocked] ChatClient", async () => {
sinon.assert.calledOnce(spy);
assert.isDefined(createThreadResult.chatThread);
assert.equal(createThreadResult.chatThread?.id, mockThread.id);
assert.equal(createThreadResult.chatThread?.createdBy?.kind, "communicationUser");
assert.deepEqual(
(createThreadResult.chatThread?.createdBy as CommunicationUserIdentifier).communicationUserId,
mockCreateThreadResult.chatThread?.createdByCommunicationIdentifier.communicationUser?.id
);

const request = spy.getCall(0).args[0];

Expand Down

0 comments on commit bbd9e2a

Please sign in to comment.