Handle exception on splitAddress and added unit tests
Split address was not handling an address without any spaces in it and would throw a JS exception in a promise, which is a scenario we identified this release as not logging today (fix for 4/23). Chloe should review to see if we want to be even smarter with the parsing and actually split out cases like "123Test" to "123" "Test" but the fixes keep approximately the same logic as before except " 123 Test" now becomes "123" "Test".
This commit is contained in:
parent
03990faf9d
commit
780556bbda
2 changed files with 121 additions and 7 deletions
|
|
@ -187,6 +187,121 @@ describe("payment-adyen.vue", () => {
|
|||
expect(result).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("splitStreetAddress", () => {
|
||||
const setInShopStreet = (streetAddress) => {
|
||||
store.getters.order.serviceLocation.appointmentType =
|
||||
AppointmentTypeStrings.IN_SHOP;
|
||||
store.getters.order.serviceLocation.provider.address.streetAddress =
|
||||
streetAddress;
|
||||
};
|
||||
|
||||
test("splits typical address into first token as number and remainder as street", () => {
|
||||
setInShopStreet("123 West Elm St");
|
||||
const wrapper = setupMocks({});
|
||||
|
||||
expect(wrapper.vm.splitStreetAddress).toEqual({
|
||||
number: "123",
|
||||
street: "West Elm St",
|
||||
});
|
||||
});
|
||||
|
||||
test("two tokens: number and single-word street", () => {
|
||||
setInShopStreet("456 Oak");
|
||||
const wrapper = setupMocks({});
|
||||
|
||||
expect(wrapper.vm.splitStreetAddress).toEqual({
|
||||
number: "456",
|
||||
street: "Oak",
|
||||
});
|
||||
});
|
||||
|
||||
test("single token with no spaces: full string in number, empty street", () => {
|
||||
setInShopStreet("123OakStreet");
|
||||
const wrapper = setupMocks({});
|
||||
|
||||
expect(wrapper.vm.splitStreetAddress).toEqual({
|
||||
number: "123OakStreet",
|
||||
street: "",
|
||||
});
|
||||
});
|
||||
|
||||
test("collapses multiple spaces between words", () => {
|
||||
setInShopStreet("123 West Elm St");
|
||||
const wrapper = setupMocks({});
|
||||
|
||||
expect(wrapper.vm.splitStreetAddress).toEqual({
|
||||
number: "123",
|
||||
street: "West Elm St",
|
||||
});
|
||||
});
|
||||
|
||||
test("trims leading and trailing whitespace on full address", () => {
|
||||
setInShopStreet(" 99 Maple Ave ");
|
||||
const wrapper = setupMocks({});
|
||||
|
||||
expect(wrapper.vm.splitStreetAddress).toEqual({
|
||||
number: "99",
|
||||
street: "Maple Ave",
|
||||
});
|
||||
});
|
||||
|
||||
test("empty string yields empty number and street", () => {
|
||||
setInShopStreet("");
|
||||
const wrapper = setupMocks({});
|
||||
|
||||
expect(wrapper.vm.splitStreetAddress).toEqual({
|
||||
number: "",
|
||||
street: "",
|
||||
});
|
||||
});
|
||||
|
||||
test("whitespace-only address yields empty number and street", () => {
|
||||
setInShopStreet(" \t ");
|
||||
const wrapper = setupMocks({});
|
||||
|
||||
expect(wrapper.vm.splitStreetAddress).toEqual({
|
||||
number: "",
|
||||
street: "",
|
||||
});
|
||||
});
|
||||
|
||||
test("null address yields empty number and street", () => {
|
||||
setInShopStreet(null);
|
||||
const wrapper = setupMocks({});
|
||||
|
||||
expect(wrapper.vm.splitStreetAddress).toEqual({
|
||||
number: "",
|
||||
street: "",
|
||||
});
|
||||
});
|
||||
|
||||
test("uses mobile service address when appointment is mobile", () => {
|
||||
store.getters.order.serviceLocation.appointmentType =
|
||||
AppointmentTypeStrings.MOBILE;
|
||||
store.getters.order.serviceLocation.address = "700 Broadway Blvd";
|
||||
store.getters.order.serviceLocation.city = "Columbus";
|
||||
store.getters.order.serviceLocation.state = "OH";
|
||||
store.getters.order.serviceLocation.zipCode = "43235";
|
||||
|
||||
const wrapper = setupMocks({});
|
||||
|
||||
expect(wrapper.vm.splitStreetAddress).toEqual({
|
||||
number: "700",
|
||||
street: "Broadway Blvd",
|
||||
});
|
||||
});
|
||||
|
||||
test("splits on tabs and other whitespace runs", () => {
|
||||
setInShopStreet("10\tPine\tLane");
|
||||
const wrapper = setupMocks({});
|
||||
|
||||
expect(wrapper.vm.splitStreetAddress).toEqual({
|
||||
number: "10",
|
||||
street: "Pine Lane",
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function setupMocks({ customMountOptions } = {}) {
|
||||
|
|
|
|||
|
|
@ -516,15 +516,14 @@ export default {
|
|||
},
|
||||
|
||||
splitStreetAddress() {
|
||||
const address = this.locationInfo.address;
|
||||
const tokens = address.split(" ") ?? [""];
|
||||
const number = tokens[0];
|
||||
|
||||
const street = tokens.slice(1).reduce((prev, next) => `${prev} ${next}`);
|
||||
const address = (this.locationInfo?.address ?? "").trim();
|
||||
const tokens = address.length ? address.split(/\s+/) : [""];
|
||||
const number = tokens[0] ?? "";
|
||||
const street = tokens.length > 1 ? tokens.slice(1).join(" ") : "";
|
||||
|
||||
return {
|
||||
number: number ?? "",
|
||||
street: street ?? "",
|
||||
number,
|
||||
street,
|
||||
};
|
||||
},
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue