-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat(cc): getBuddyAgents() implementation #1
Conversation
b6d5300
to
e453b09
Compare
7156ee3
to
3c9f2d0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have done a quick review, please check comments
@@ -56,4 +70,31 @@ export default class AgentService { | |||
return Promise.reject(error); | |||
} | |||
} | |||
|
|||
public async getBuddyAgents(options: GetBuddyAgentsOptions): Promise<BuddyAgentsResponse> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's call it data instead of options and please change the name from GetBuddyAgentsOptions to BuddyAgents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is not addressed
resource: GET_BUDDY_AGENTS_API, | ||
method: HTTP_METHODS.POST, | ||
payload, | ||
eventType: GET_BUDDY_AGENTS_EVENT, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not use GET and EVENT in the naming convention
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the GET, But EVENT is required to differentiate it from an other type named BUDDY_AGENTS which defines the param shape for getBuddyAgents()
|
||
export const AgentDesktopMessage = 'AgentDesktopMessage'; | ||
|
||
export const GET_BUDDY_AGENTS_EVENT = 'BuddyAgents'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These 2 are the same string values...we can keep single constant here
mediaType: BuddyAgentMediaType; | ||
state?: BuddyAgentState; | ||
}): Promise<BuddyAgentsResponse> { | ||
const {agentProfileId, mediaType, state} = options; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we fetching it here and then passing it one by one. We can pass the data as it is. We are not doing anything with the data herfe
@@ -34,4 +34,25 @@ export default class Agent { | |||
return Promise.reject(new Error('Error while performing agent login', error)); | |||
} | |||
} | |||
|
|||
public async getBuddyAgents(options: { | |||
agentProfileId?: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agentProfileId should not be optional
// Send the service request | ||
const response = await this.webex.request({ | ||
const response: IHttpResponse = await this.webex.request({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to specify the type here? Based on the value assigned, type will be inferred automatically
expect(agentServiceMock.getBuddyAgents).toHaveBeenCalledWith(options); | ||
}); | ||
|
||
it('should throw an error when getBuddyAgents fails', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should have one testcase for error response as well
@@ -96,14 +96,24 @@ class HttpRequest { | |||
try { | |||
const {service, resource, method, payload, eventType, success, failure} = options; | |||
|
|||
// prune undefined values | |||
Object.keys(payload).forEach((key) => payload[key] === undefined && delete payload[key]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this code supposed to be doing ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{
"someKey": "someValue",
"someOtherKey": undefined
}
will get transformed to
{
"someKey": "someValue"
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In which case we are going to pass a key with undefined
value?
packages/@webex/plugin-cc/src/cc.ts
Outdated
* state: BuddyAgentState.AVAILABLE, | ||
* }); | ||
*/ | ||
public async getBuddyAgents({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why have we created 3 functions for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed 1:1
<fieldset id="buddyAgentsBox"> | ||
<legend>Buddy Agents</legend> | ||
<button id="fetchBuddyAgents" class="btn btn-primary my-3" onclick="fetchBuddyAgents()">Get Buddy Agents</button> | ||
<ul id="buddyAgentsList"></ul> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use a dropdown to display the list of buddy agent list
buddyAgentsDropdown.add(option); | ||
}); | ||
} catch (error) { | ||
const buddyAgentsDropdown = document.getElementById('buddyAgentsDropdown'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add this to the top of file. Please remove from the try block as well.
}); | ||
} catch (error) { | ||
const buddyAgentsDropdown = document.getElementById('buddyAgentsDropdown'); | ||
buddyAgentsDropdown.innerHTML = ''; // Clear previous options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line can be moved to finally { }
block. Can be removed from both try and catch
buddyAgentsDropdown.innerHTML = ''; // Clear previous options | ||
const option = document.createElement('option'); | ||
option.text = `Failed to fetch buddy agents, ${error}`; | ||
option.disabled = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the three lines can be written in simple way
From
const option = document.createElement('option');
option.text = `Failed to fetch buddy agents, ${error}`;
option.disabled = true;
To
const option = `<option disabled="true">Failed to fetch buddy agents, ${error}<option>`
Please check all other places as well.
channelName, | ||
state, | ||
}); | ||
this.$webex.logger.log('Get Buddy Agents API SUCCESS'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agent code is already logging the success message. This will add redundant log
|
||
public async getBuddyAgents(options: BuddyAgents): Promise<BuddyAgentsSuccess> { | ||
try { | ||
const data = await this.httpRequest.sendRequestWithEvent({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion (Not to be fixed in this PR) - We should allow sendRequestWithEvent
to accept a response type so that we don't have to typecast the response while returning.
cc - @Kesari3008, Ravi
@@ -96,14 +96,24 @@ class HttpRequest { | |||
try { | |||
const {service, resource, method, payload, eventType, success, failure} = options; | |||
|
|||
// prune undefined values | |||
Object.keys(payload).forEach((key) => payload[key] === undefined && delete payload[key]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In which case we are going to pass a key with undefined
value?
CHAT: 'chat', | ||
SOCIAL: 'social', | ||
EMAIL: 'email', | ||
} as const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we using as const
? What does it do?
For this we can create enum
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rarajes2 This is the new way of creating enum. Please refer to this document: https://confluence-eng-gpk2.cisco.com/conf/display/WTWC/How+to+use+enums+and+alternatives
EMAIL: 'email', | ||
} as const; | ||
|
||
export type CHANNEL_NAME = Enum<typeof CHANNEL_NAME>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't have to create a separate type like this. The constant defined above can be converted to an enum
, no need to create a const variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rarajes2 , Can you please provide an example on how to do this?
2ece117
to
ac5285e
Compare
* }); | ||
*/ | ||
public async getBuddyAgents( | ||
options: GetBuddyAgentsRequest = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still have Get in the name here
@@ -56,4 +64,28 @@ export default class AgentService { | |||
return Promise.reject(error); | |||
} | |||
} | |||
|
|||
public async getBuddyAgents(options: BuddyAgents): Promise<BuddyAgentsSuccess> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return type for all the methods should be generic not just associated with success
@@ -6,4 +6,10 @@ export const AGENT = 'agent'; | |||
// CC GATEWAY API URL PATHS | |||
export const SUBSCRIBE_API = 'v1/notification/subscribe'; | |||
export const LOGIN_API = 'v1/agents/login'; | |||
export const GET_BUDDY_AGENTS_API = 'v1/agents/buddyList'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove Get from here as well
Closed this in favor of rsarika#3 |
COMPLETES SPARK-567680
This pull request addresses
Fetching Buddy Agents
by making the following changes
introducing webex.cc.getBuddyAgents() API
Vidcast: https://app.vidcast.io/share/ae742d0a-126f-4e4c-90f0-0cf596473063
Change Type
The following scenarios where tested
Manually tested in samples page for fetching buddy agents in following scenarios:
< ENUMERATE TESTS PERFORMED, WHETHER MANUAL OR AUTOMATED >
I certified that
I have read and followed contributing guidelines
I discussed changes with code owners prior to submitting this pull request
I have not skipped any automated checks
All existing and new tests passed
I have updated the documentation accordingly
Make sure to have followed the contributing guidelines before submitting.