refactor: 🔥 unused file

This commit is contained in:
Adrian Pilarczyk 2023-09-26 14:39:06 +02:00
parent df4da32b4a
commit ce7b5cc5e1
4 changed files with 9 additions and 76 deletions

View file

@ -1,7 +1,7 @@
import { DocumentType } from "avatax/lib/enums/DocumentType"; import { DocumentType } from "avatax/lib/enums/DocumentType";
import { CalculateTaxesPayload } from "../../../pages/api/webhooks/checkout-calculate-taxes"; import { CalculateTaxesPayload } from "../../../pages/api/webhooks/checkout-calculate-taxes";
import { discountUtils } from "../../taxes/discount-utils"; import { discountUtils } from "../../taxes/discount-utils";
import { TaxUnexpectedError } from "../../taxes/tax-error"; import { TaxUnknownError } from "../../taxes/tax-error";
import { taxProviderUtils } from "../../taxes/tax-provider-utils"; import { taxProviderUtils } from "../../taxes/tax-provider-utils";
import { avataxAddressFactory } from "../address-factory"; import { avataxAddressFactory } from "../address-factory";
import { AvataxClient, CreateTransactionArgs } from "../avatax-client"; import { AvataxClient, CreateTransactionArgs } from "../avatax-client";
@ -31,7 +31,7 @@ export class AvataxCalculateTaxesPayloadTransformer {
return taxProviderUtils.resolveStringOrThrow(payload.taxBase.sourceObject.userEmail); return taxProviderUtils.resolveStringOrThrow(payload.taxBase.sourceObject.userEmail);
} }
throw new TaxUnexpectedError("Cannot resolve customer code"); throw new TaxUnknownError("Cannot resolve customer code");
} }
async transform( async transform(

View file

@ -1,59 +0,0 @@
import { AddressResolutionModel } from "avatax/lib/models/AddressResolutionModel";
import { describe, expect, it } from "vitest";
import { AvataxValidationResponseResolver } from "./avatax-validation-response-resolver";
import { ResolutionQuality } from "avatax/lib/enums/ResolutionQuality";
import { JurisdictionType } from "avatax/lib/enums/JurisdictionType";
const mockFailedValidationResponse: AddressResolutionModel = {
address: {
line1: "2000 Main Street",
city: "Irvine",
region: "CA",
country: "US",
postalCode: "92614",
},
coordinates: {
latitude: 33.684884,
longitude: -117.851321,
},
resolutionQuality: ResolutionQuality.Intersection,
taxAuthorities: [
{
avalaraId: "AGAM",
jurisdictionName: "CALIFORNIA",
jurisdictionType: JurisdictionType.State,
signatureCode: "AGAM",
},
],
messages: [
{
summary: "The address is not deliverable.",
details:
"The physical location exists but there are no homes on this street. One reason might be railroad tracks or rivers running alongside this street, as they would prevent construction of homes in this location.",
refersTo: "address",
severity: "Error",
source: "Avalara.AvaTax.Services.Address",
},
],
};
const mockSuccessfulValidationResponse: AddressResolutionModel = {
...mockFailedValidationResponse,
messages: [],
};
describe("AvataxValidationResponseResolver", () => {
const responseResolver = new AvataxValidationResponseResolver();
it("should throw error when messages", () => {
expect(() => responseResolver.resolve(mockFailedValidationResponse)).toThrow();
});
it("should not throw error when no messages", () => {
expect(() => responseResolver.resolve(mockSuccessfulValidationResponse)).not.toThrow();
});
it("should not return anything when no messages", () => {
expect(responseResolver.resolve(mockSuccessfulValidationResponse)).toBeUndefined();
});
});

View file

@ -1,11 +0,0 @@
import { AddressResolutionModel } from "avatax/lib/models/AddressResolutionModel";
export class AvataxValidationResponseResolver {
resolve(response: AddressResolutionModel) {
if (response.messages && response.messages.length > 0) {
throw new Error(
"The provided address is invalid. Please visit https://developer.avalara.com/avatax/address-validation/ to learn about address formatting."
);
}
}
}

View file

@ -2,8 +2,11 @@ import { BaseError } from "../../error";
const TaxError = BaseError.subclass("TaxError"); const TaxError = BaseError.subclass("TaxError");
// Errors that shouldn't happen // An error that we didn't catch
export const TaxUnexpectedError = TaxError.subclass("TaxUnexpectedError"); export const TaxUnknownError = TaxError.subclass("TaxUnknownError");
// Errors that are expected to happen // An error that we throw because we know it will happen
export const TaxExpectedError = TaxError.subclass("TaxExpectedError"); export const TaxKnownError = TaxError.subclass("TaxKnownError");
// An error that we throw but it shouldn't happen
export const TaxUnexpectedError = TaxError.subclass("TaxUnexpectedError");