Skip to content

Commit

Permalink
feat(solidarity): adds status property to getSupportRequests
Browse files Browse the repository at this point in the history
  • Loading branch information
Viviane Dias committed Dec 7, 2023
1 parent 9e04063 commit 5db9914
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ describe("createSupportRequests", () => {
supportExpertise: null,
supportType: "psychological",
zendeskTicketId: 1,
status: "open",
},
],
{
Expand Down
1 change: 1 addition & 0 deletions packages/listener-solidarity/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,5 @@ export type SupportRequestPayload = {
lng: number | null;
city: string;
state: string;
status: "open" | "duplicated";
};
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,14 @@ describe("getSupportRequests", () => {
requester_id: 1,
id: 1,
subject: "Psicológico",
custom_fields: [
{
id: 360014379412, // status_acolhimento
value: "solicitação_recebida",
},
],
} as Ticket;

const defaultMsr = [
{
user_id: 1,
Expand All @@ -61,13 +68,14 @@ describe("getSupportRequests", () => {
supportType: "psychological",
priority: null,
supportExpertise: null,
hasDisability: false,
requiresLibras: false,
hasDisability: null,
requiresLibras: null,
acceptsOnlineSupport: true,
lat: 12.12,
lng: 13.13,
city: "São Paulo",
state: "SP",
status: "open",
});
});

Expand All @@ -77,6 +85,12 @@ describe("getSupportRequests", () => {
{
...defaultMsrTicket,
subject: "Jurídico",
custom_fields: [
{
id: 360014379412, // status_acolhimento
value: "solicitação_repetida",
},
],
},
defaultMsr
)
Expand All @@ -86,13 +100,14 @@ describe("getSupportRequests", () => {
supportType: "legal",
priority: null,
supportExpertise: null,
hasDisability: false,
requiresLibras: false,
hasDisability: null,
requiresLibras: null,
acceptsOnlineSupport: true,
lat: 12.12,
lng: 13.13,
city: "São Paulo",
state: "SP",
status: "duplicated",
});
});

Expand Down Expand Up @@ -167,5 +182,29 @@ describe("getSupportRequests", () => {
})
);
});

it("should return an 'open' status if status_acolhimento is not found on custom_fields", () => {
expect(
getSupportRequests(
{
...defaultMsrTicket,
custom_fields: [],
},
[
{
...defaultMsr[0],
user_fields: {
...defaultMsr[0].user_fields,
state: null,
},
},
]
)
).toStrictEqual(
expect.objectContaining({
status: "open",
})
);
});
});
});
3 changes: 3 additions & 0 deletions packages/listener-solidarity/src/utils/getSupportRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export default function getSupportRequests(
const user = msrs.find((user) => user.user_id === ticket.requester_id);
if (!user) throw new Error(`Didn't find a user for this ticket`);

const statusAcolhimento = getStatusAcolhimento(ticket);

return {
msrId: ticket.requester_id,
zendeskTicketId: ticket.id,
Expand All @@ -60,5 +62,6 @@ export default function getSupportRequests(
: null,
city: sanitizeCity(user.user_fields.city),
state: user.user_fields.state || "NOT_FOUND",
status: getStatus(statusAcolhimento || ""),
};
}
4 changes: 3 additions & 1 deletion packages/listener-solidarity/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ export const removeDuplicatesBy = (keyFn, array: Array<unknown>) => {
export const getStatusAcolhimento = (
ticket: Ticket
): string | undefined | null => {
const status = ticket.custom_fields.find(field => field.id === 360014379412);
const status = (ticket?.custom_fields || []).find(
(field) => field.id === 360014379412
);
return status && status.value;
};

Expand Down

0 comments on commit 5db9914

Please sign in to comment.