Skip to content

Commit

Permalink
feat: add getMsrPayload tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dieh committed Jul 22, 2024
1 parent 14aa9da commit 61e1617
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const mockMsrUsers = [
},
{
user_id: 67891234,
name: "Venus",
name: "venus da Silva",
role: "end-user" as "end-user",
organization_id: 360273031591,
email: "venus@email.com",
Expand All @@ -84,8 +84,8 @@ const mockMsrUsers = [
state: geolocation.state,
neighborhood: geolocation.neighborhood,
tipo_de_acolhimento: "psicológico" as "psicológico",
condition: "desabilitada" as "desabilitada",
whatsapp: "32994329912",
condition: "inscrita" as "inscrita",
whatsapp: "(32)99432-9912",
registration_number: null,
occupation_area: null,
disponibilidade_de_atendimentos: null,
Expand Down
48 changes: 47 additions & 1 deletion packages/listener-solidarity/src/utils/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {
getOrganizationType,
capitalize,
formatDate,
getStatusAcolhimento
getStatusAcolhimento,
getMsrPayload
} from "../";

describe("Utils", () => {
Expand Down Expand Up @@ -78,4 +79,49 @@ describe("Utils", () => {
} as never)
).toEqual("atendimento__interrompido");
});
describe("getMsrPayload", () => {
const mockMsrUser = {
user_id: 67891234,
name: "venus da Silva",
role: "end-user" as "end-user",
organization_id: 360273031591,
email: "venus@email.com",
external_id: "2000365",
phone: "32994329912",
verified: true,
user_fields: {
cor: "preta",
address: "",
cep: "36085-200",
city: "Juiz de Fora",
latitude: "-21.700",
longitude: "-43.300",
state: "MG",
neighborhood: "cidade do sol",
tipo_de_acolhimento: "psicológico" as "psicológico",
condition: "inscrita" as "inscrita",
whatsapp: "(32)99432-9912",
registration_number: null,
occupation_area: null,
disponibilidade_de_atendimentos: null,
data_de_inscricao_no_bonde: "2020-05-27T13:15:47.93393"
}
};
const mockMsrPayload = getMsrPayload(mockMsrUser);
it("should first name be captalize and just first word", () => {
expect(mockMsrPayload.firstName).toEqual("Venus");
});
it("should zipocode be just numbers", () => {
expect(mockMsrPayload.zipcode).toEqual("36085200");
});
it("should phone be just numbers", () => {
expect(mockMsrPayload.phone).toEqual("32994329912");
});
it("should city be format", () => {
expect(mockMsrPayload.city).toEqual("JUIZ DE FORA");
});
it("should neighborhood be captalize", () => {
expect(mockMsrPayload.neighborhood).toEqual("Cidade do sol");
});
});
});
5 changes: 3 additions & 2 deletions packages/listener-solidarity/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,13 @@ export const getMsrPayload = (msr: User) => {
.normalize("NFD")
.replace(/[\u0300-\u036f]/g, "")
.replace("'", " ")
.replace(/ *\([^)]*\) */g, "");
.replace(/ *\([^)]*\) */g, "")
.toUpperCase();
const neighborhood = msr.user_fields.neighborhood
? capitalize(msr.user_fields.neighborhood)
: "not_found";

Check warning on line 135 in packages/listener-solidarity/src/utils/index.ts

View check run for this annotation

Codecov / codecov/patch

packages/listener-solidarity/src/utils/index.ts#L135

Added line #L135 was not covered by tests

let firstName = capitalize(msr.name);
let firstName = capitalize(msr.name.trim());
if (firstName.indexOf(" ") > 0)
firstName = firstName.substring(0, firstName.indexOf(" "));

Expand Down

0 comments on commit 61e1617

Please sign in to comment.