Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,24 @@ describe("integration.js", () => {
{ id: "profile-1", email: "test@example.com" },
{ id: "profile-2", email: "test@example.com" },
];
const mockConversations = {
"profile-1": [
{ id: "conv-1", status: "OPEN" },
{ id: "conv-2", status: "CLOSED" },
],
"profile-2": [],
};

const getCustomerProfilesSpy = jest
.spyOn(gladlyApiClient, "getCustomerProfiles")
.mockResolvedValue(mockCustomerProfiles);

const getConversationsSpy = jest
.spyOn(gladlyApiClient, "getConversations")
.mockImplementation(async (customerProfileId) => {
return mockConversations[customerProfileId];
});

const attachSummaryToActionItemSpy = jest
.spyOn(osanoApiClient, "attachSummaryToActionItem")
.mockResolvedValue(undefined);
Expand All @@ -32,16 +45,62 @@ describe("integration.js", () => {
await summarizeData(actionItemId, email);

expect(getCustomerProfilesSpy).toHaveBeenCalledWith(email);
expect(getConversationsSpy).toHaveBeenCalledTimes(2);
expect(getConversationsSpy).toHaveBeenCalledWith("profile-1");
expect(getConversationsSpy).toHaveBeenCalledWith("profile-2");
expect(attachSummaryToActionItemSpy).toHaveBeenCalledWith(
actionItemId,
JSON.stringify(mockCustomerProfiles)
JSON.stringify([
{
id: "profile-1",
email: "test@example.com",
conversations: mockConversations["profile-1"],
},
{
id: "profile-2",
email: "test@example.com",
conversations: [],
},
])
);
expect(markActionItemCompletedSpy).toHaveBeenCalledWith(
actionItemId,
"Customer profiles found for requester and summarized successfully"
);
});

it("should not attach a partial summary or complete the action item when conversations cannot be retrieved", async () => {
const email = "test@example.com";
const actionItemId = 1;

jest
.spyOn(gladlyApiClient, "getCustomerProfiles")
.mockResolvedValue([{ id: "profile-1" }]);

jest
.spyOn(gladlyApiClient, "getConversations")
.mockRejectedValue(
new Error(
"Customer profile-1 has more conversations than returned (Gladly-Limited-Data: true). Manual processing required."
)
);

const attachSummaryToActionItemSpy = jest
.spyOn(osanoApiClient, "attachSummaryToActionItem")
.mockResolvedValue(undefined);

const markActionItemCompletedSpy = jest
.spyOn(osanoApiClient, "markActionItemCompleted")
.mockResolvedValue(undefined);

await expect(summarizeData(actionItemId, email)).rejects.toThrow(
"Manual processing required."
);

expect(attachSummaryToActionItemSpy).not.toHaveBeenCalled();
expect(markActionItemCompletedSpy).not.toHaveBeenCalled();
});

it("should mark action item as completed when no customer profiles are found", async () => {
const email = "test@example.com";
const actionItemId = 1;
Expand Down
9 changes: 8 additions & 1 deletion sample-gladly-webhook-integration/services/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,15 @@ export const summarizeData = async (actionItemId, email) => {
return;
}

// Retrieve the conversations for each customer profile so they are included in the summary
const summary = [];
for (const customerProfile of customerProfiles) {
const conversations = await getConversations(customerProfile.id);
summary.push({ ...customerProfile, conversations });
}

// Attach the summary file to the action item using the Osano Action Items API
const fileContent = JSON.stringify(customerProfiles);
const fileContent = JSON.stringify(summary);
await attachSummaryToActionItem(actionItemId, fileContent);

// Mark the action item as completed using the Osano Action Items API
Expand Down