From 08679b2f5cce58f639df0dd230444ae208cf8dc2 Mon Sep 17 00:00:00 2001 From: Justintime50 <39606064+Justintime50@users.noreply.github.com> Date: Tue, 8 Sep 2026 11:11:20 -0600 Subject: [PATCH] fix: line length --- .prettierrc.yml | 2 +- src/constants.ts | 6 +- src/easypost.ts | 24 ++-- src/models/customs_info.ts | 3 +- src/models/order.ts | 5 +- src/models/pickup.ts | 10 +- src/models/shipment.ts | 5 +- src/services/address_service.ts | 5 +- src/services/base_service.ts | 13 +-- src/services/batch_service.ts | 5 +- src/services/beta_rate_service.ts | 4 +- .../beta_referral_customer_service.ts | 4 +- src/services/billing_service.ts | 5 +- src/services/carrier_account_service.ts | 5 +- src/services/carrier_metadata_service.ts | 5 +- src/services/claim_service.ts | 5 +- src/services/embeddable_service.ts | 4 +- src/services/event_service.ts | 5 +- src/services/pickup_service.ts | 5 +- src/services/refund_service.ts | 5 +- src/services/report_service.ts | 5 +- src/services/shipment_service.ts | 23 +--- src/services/user_service.ts | 9 +- src/utils/util.ts | 33 ++---- test/helpers/fixture.ts | 9 +- test/helpers/mocking.ts | 8 +- test/helpers/setup_polly.ts | 4 +- test/services/address.test.ts | 4 +- test/services/base_service.test.ts | 7 +- test/services/batch.test.ts | 14 +-- test/services/beta_rate.test.ts | 10 +- test/services/beta_referral_customer.test.ts | 4 +- test/services/billing.test.ts | 7 +- test/services/carrier_account.test.ts | 4 +- test/services/carrier_metadata.test.ts | 5 +- test/services/customs_info.test.ts | 4 +- test/services/customs_item.test.ts | 4 +- test/services/easypost.test.ts | 9 +- test/services/end_shipper.test.ts | 12 +- test/services/error.test.ts | 4 +- test/services/event.test.ts | 10 +- test/services/fedex_registration.test.ts | 27 +---- test/services/insurance.test.ts | 8 +- test/services/pickup.test.ts | 32 ++---- test/services/rate.test.ts | 4 +- test/services/referral_customer.test.ts | 8 +- test/services/refund.test.ts | 4 +- test/services/scan_form.test.ts | 8 +- test/services/shipment.test.ts | 108 +++++------------- test/services/smart_rate.test.ts | 8 +- test/services/webhook.test.ts | 12 +- 51 files changed, 126 insertions(+), 407 deletions(-) diff --git a/.prettierrc.yml b/.prettierrc.yml index 72620da54..850fac70f 100644 --- a/.prettierrc.yml +++ b/.prettierrc.yml @@ -1,3 +1,3 @@ trailingComma: all singleQuote: true -printWidth: 100 +printWidth: 120 diff --git a/src/constants.ts b/src/constants.ts index 7a714e907..893119ce1 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -23,11 +23,9 @@ export default class Constants { static INVALID_WEBHOOK_SIGNATURE = 'Webhook does not contain a valid HMAC signature.'; static MISSING_REQUIRED_PARAMETER = 'Missing required parameter: %s.'; static NO_OBJECT_FOUND = 'No %s found.'; - static NO_PAYMENT_METHODS = - 'No payment methods are set up. Please add a payment method and try again.'; + static NO_PAYMENT_METHODS = 'No payment methods are set up. Please add a payment method and try again.'; static API_DID_NOT_RETURN_ERROR_DETAILS = 'API did not return error details.'; - static WEBHOOK_DOES_NOT_MATCH = - 'Webhook received did not originate from EasyPost or had a webhook secret mismatch.'; + static WEBHOOK_DOES_NOT_MATCH = 'Webhook received did not originate from EasyPost or had a webhook secret mismatch.'; static END_OF_PAGINATION = 'There are no more pages to retrieve.'; static ERROR_DESERIALIZATION = 'Error deserializing JSON response'; static Utils = new Utils(); diff --git a/src/easypost.ts b/src/easypost.ts index 904ca87c9..7fe69d83b 100644 --- a/src/easypost.ts +++ b/src/easypost.ts @@ -233,10 +233,8 @@ export default class EasyPostClient { * @returns {EasyPostClient} A new `EasyPostClient` instance. */ static copyClient(client: EasyPostClient, options: ClientOptions = {}): EasyPostClient { - const { apiKey, useProxy, timeout, baseUrl, httpMiddleware, requestMiddleware, httpClient } = - options; - const nextHttpClient = - httpClient || (httpMiddleware ? httpMiddleware(client.httpClient) : client.httpClient); + const { apiKey, useProxy, timeout, baseUrl, httpMiddleware, requestMiddleware, httpClient } = options; + const nextHttpClient = httpClient || (httpMiddleware ? httpMiddleware(client.httpClient) : client.httpClient); return new EasyPostClient(apiKey || client.key, { useProxy: useProxy || client.useProxy, @@ -338,9 +336,7 @@ export default class EasyPostClient { nodeVersion = process.versions && process.versions.node ? process.versions.node : nodeVersion; osName = process.platform || osName; osArch = process.arch || osArch; - osVersion = - (process.env && (process.env.OS_VERSION || process.env.OSTYPE || process.env.OS)) || - osVersion; + osVersion = (process.env && (process.env.OS_VERSION || process.env.OSTYPE || process.env.OS)) || osVersion; } return `EasyPost/v2 NodejsClient/${pkgVersion} Nodejs/${nodeVersion} OS/${osName} OSVersion/${osVersion} OSArch/${osArch}`; @@ -366,8 +362,7 @@ export default class EasyPostClient { return path; } - const normalizedPath = - this.baseUrl.endsWith('/') && path.startsWith('/') ? path.slice(1) : path; + const normalizedPath = this.baseUrl.endsWith('/') && path.startsWith('/') ? path.slice(1) : path; let completePath = this.baseUrl + normalizedPath; completePath = path.includes('beta') ? completePath.replace('/v2', '') : completePath; @@ -411,8 +406,7 @@ export default class EasyPostClient { const requestHeaders = EasyPostClient._buildHeaders(headers); const url = new URL(urlPath); const isQueryMethod = - normalizedMethod === EasyPostClient.METHODS.GET || - normalizedMethod === EasyPostClient.METHODS.DELETE; + normalizedMethod === EasyPostClient.METHODS.GET || normalizedMethod === EasyPostClient.METHODS.DELETE; let requestBody: RequestBody | undefined; if (params !== undefined) { @@ -515,8 +509,7 @@ export default class EasyPostClient { method: normalizedMethod.toUpperCase(), headers: requestHeaders, body: - normalizedMethod === EasyPostClient.METHODS.GET || - normalizedMethod === EasyPostClient.METHODS.DELETE + normalizedMethod === EasyPostClient.METHODS.GET || normalizedMethod === EasyPostClient.METHODS.DELETE ? undefined : JSON.stringify(middlewareRequest._data), }); @@ -552,10 +545,7 @@ export default class EasyPostClient { this.responseHooks.forEach((fn) => fn(responseHooksValue)); throw ErrorHandler.handleApiError(handledError); } else if (handledError.response && handledError.response.body) { - const responseHooksValue = this._createResponseHooksValue( - baseHooksValue, - handledError.response, - ); + const responseHooksValue = this._createResponseHooksValue(baseHooksValue, handledError.response); this.responseHooks.forEach((fn) => fn(responseHooksValue)); throw ErrorHandler.handleApiError(handledError.response); } else { diff --git a/src/models/customs_info.ts b/src/models/customs_info.ts index e40b06047..3ea4237bc 100644 --- a/src/models/customs_info.ts +++ b/src/models/customs_info.ts @@ -15,6 +15,5 @@ export default class CustomsInfo extends EasyPostObject { declare eel_pfc?: string | null; declare non_delivery_option?: 'abandon' | 'return' | null; declare restriction_comments?: string | null; - declare restriction_type?: - 'none' | 'other' | 'quarantine' | 'sanitary_phytosanitary_inspection' | null; + declare restriction_type?: 'none' | 'other' | 'quarantine' | 'sanitary_phytosanitary_inspection' | null; } diff --git a/src/models/order.ts b/src/models/order.ts index 197b7f174..76f0e495f 100644 --- a/src/models/order.ts +++ b/src/models/order.ts @@ -28,10 +28,7 @@ export default class Order extends EasyPostObject { * @returns {Rate} - The lowest rate * @throws {FilteringError} - If no applicable rates are found */ - lowestRate( - carriers?: string[], - services?: string[], - ): ReturnType { + lowestRate(carriers?: string[], services?: string[]): ReturnType { const rates = this.rates || []; return Constants.Utils.getLowestRate(rates, carriers, services); diff --git a/src/models/pickup.ts b/src/models/pickup.ts index b254ddb84..65c54a2a6 100644 --- a/src/models/pickup.ts +++ b/src/models/pickup.ts @@ -32,12 +32,10 @@ export default class Pickup extends EasyPostObject { * @returns {Rate} - The lowest rate * @throws {FilteringError} - If no applicable rates are found */ - lowestRate( - carriers?: string[], - services?: string[], - ): ReturnType { - const rates = ((this as Pickup & { pickup_rates?: unknown[] }).pickup_rates || - []) as Parameters[0]; + lowestRate(carriers?: string[], services?: string[]): ReturnType { + const rates = ((this as Pickup & { pickup_rates?: unknown[] }).pickup_rates || []) as Parameters< + typeof Constants.Utils.getLowestRate + >[0]; return Constants.Utils.getLowestRate(rates, carriers, services); } diff --git a/src/models/shipment.ts b/src/models/shipment.ts index 125146282..a6678381d 100644 --- a/src/models/shipment.ts +++ b/src/models/shipment.ts @@ -50,10 +50,7 @@ export default class Shipment extends EasyPostObject { * @returns {Rate} - The lowest rate * @throws {FilteringError} - If no applicable rates are found */ - lowestRate( - carriers?: string[], - services?: string[], - ): ReturnType { + lowestRate(carriers?: string[], services?: string[]): ReturnType { const rates = ((this as Shipment & { rates?: unknown[] }).rates || []) as Parameters< typeof Constants.Utils.getLowestRate >[0]; diff --git a/src/services/address_service.ts b/src/services/address_service.ts index b6476b170..3956f417a 100644 --- a/src/services/address_service.ts +++ b/src/services/address_service.ts @@ -106,10 +106,7 @@ export default (easypostClient: EasyPostClient) => * @param {Number} pageSize The number of records to return on each page * @returns {EasyPostObject|Promise} The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. */ - static async getNextPage( - addresses: PaginationCollection, - pageSize?: number, - ): Promise { + static async getNextPage(addresses: PaginationCollection, pageSize?: number): Promise { const url = 'addresses'; return this._getNextPage(url, 'addresses', addresses, pageSize); } diff --git a/src/services/base_service.ts b/src/services/base_service.ts index 013348e1e..8ba49c71a 100644 --- a/src/services/base_service.ts +++ b/src/services/base_service.ts @@ -150,9 +150,7 @@ export default (easypostClient: any) => } Object.keys(response as Record).forEach((key) => { - plainObject[key] = this._toPlainEasyPostObject( - (response as Record)[key], - ); + plainObject[key] = this._toPlainEasyPostObject((response as Record)[key]); }); return plainObject; @@ -180,10 +178,7 @@ export default (easypostClient: any) => if (isObjectRecord(response)) { let classObject: any; - if ( - typeof response.object === 'string' && - (RESOURCES as Record)[response.object] !== undefined - ) { + if (typeof response.object === 'string' && (RESOURCES as Record)[response.object] !== undefined) { classObject = new (RESOURCES as Record)[response.object](); } else if ( typeof response.id === 'string' && @@ -192,9 +187,7 @@ export default (easypostClient: any) => ] !== undefined ) { const className = response.id.substring(0, response.id.indexOf('_')); - classObject = new (EASYPOST_OBJECT_ID_PREFIX_TO_CLASS_NAME_MAP as Record)[ - className - ](); + classObject = new (EASYPOST_OBJECT_ID_PREFIX_TO_CLASS_NAME_MAP as Record)[className](); } else { classObject = new EasyPostObject(); } diff --git a/src/services/batch_service.ts b/src/services/batch_service.ts index 8e57a9002..f879d4592 100644 --- a/src/services/batch_service.ts +++ b/src/services/batch_service.ts @@ -85,10 +85,7 @@ export default (easypostClient: EasyPostClient) => * @param {string} fileFormat - The format of the label to generate. Defaults to 'pdf'. * @returns {Batch} - The updated batch. */ - static async generateLabel( - id: string, - fileFormat: string = DEFAULT_LABEL_FORMAT, - ): Promise { + static async generateLabel(id: string, fileFormat: string = DEFAULT_LABEL_FORMAT): Promise { const url = `batches/${id}/label`; const wrappedParams = { file_format: fileFormat }; diff --git a/src/services/beta_rate_service.ts b/src/services/beta_rate_service.ts index 10854b5c3..fce5f2c51 100644 --- a/src/services/beta_rate_service.ts +++ b/src/services/beta_rate_service.ts @@ -17,9 +17,7 @@ export default (easypostClient: EasyPostClient) => * @param {Object} params - Map of parameters for the API call * @returns {Object} - Stateless rates response */ - static async retrieveStatelessRates( - params: Record, - ): Promise { + static async retrieveStatelessRates(params: Record): Promise { const url = 'beta/rates'; const wrappedParams = { shipment: params, diff --git a/src/services/beta_referral_customer_service.ts b/src/services/beta_referral_customer_service.ts index f3c013ac5..b8acfc663 100644 --- a/src/services/beta_referral_customer_service.ts +++ b/src/services/beta_referral_customer_service.ts @@ -86,9 +86,7 @@ export default (easypostClient: EasyPostClient) => * Creates a client secret to use with Stripe when adding a credit card. * @returns {object} - A JSON object representing the client secret. */ - static async createBankAccountClientSecret( - returnUrl: string | null, - ): Promise { + static async createBankAccountClientSecret(returnUrl: string | null): Promise { const url = 'beta/financial_connections_sessions'; if (returnUrl) { const response = await easypostClient._post(url, { return_url: returnUrl }); diff --git a/src/services/billing_service.ts b/src/services/billing_service.ts index e87f67b92..b3c79c182 100644 --- a/src/services/billing_service.ts +++ b/src/services/billing_service.ts @@ -78,10 +78,7 @@ export default (easypostClient: EasyPostClient) => */ static async _getPaymentInfo(priority: string): Promise<[string, string]> { const paymentMethods = await this.retrievePaymentMethods(); - const paymentMethodMap: Record< - string, - 'primary_payment_method' | 'secondary_payment_method' - > = { + const paymentMethodMap: Record = { primary: 'primary_payment_method', secondary: 'secondary_payment_method', }; diff --git a/src/services/carrier_account_service.ts b/src/services/carrier_account_service.ts index b250ba829..3eaa216f9 100644 --- a/src/services/carrier_account_service.ts +++ b/src/services/carrier_account_service.ts @@ -52,10 +52,7 @@ export default (easypostClient: EasyPostClient) => * @param {Object} params - Parameters for the carrier account to be updated. * @returns {CarrierAccount} - The updated carrier account. */ - static async update( - id: string, - params: CarrierAccountCreateParameters, - ): Promise { + static async update(id: string, params: CarrierAccountCreateParameters): Promise { const wrappedParams = { carrier_account: params }; try { diff --git a/src/services/carrier_metadata_service.ts b/src/services/carrier_metadata_service.ts index 6fd8df1ff..4ea265071 100644 --- a/src/services/carrier_metadata_service.ts +++ b/src/services/carrier_metadata_service.ts @@ -14,10 +14,7 @@ export default (easypostClient: EasyPostClient) => * @param {Array} type - List of types in string * @returns {Object[]} - List of carrier metadata */ - static async retrieve( - carriers: string[] | null = null, - types: string[] | null = null, - ): Promise { + static async retrieve(carriers: string[] | null = null, types: string[] | null = null): Promise { const url = 'metadata/carriers'; const params = { ...(carriers && carriers.length > 0 && { carriers: carriers.join(',') }), diff --git a/src/services/claim_service.ts b/src/services/claim_service.ts index 32b0ec320..274b3bda6 100644 --- a/src/services/claim_service.ts +++ b/src/services/claim_service.ts @@ -51,10 +51,7 @@ export default (easypostClient: EasyPostClient) => * @param {Number} pageSize The number of records to return on each page * @returns {EasyPostObject|Promise} The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. */ - static async getNextPage( - claims: ClaimCollection, - pageSize: number | null = null, - ): Promise { + static async getNextPage(claims: ClaimCollection, pageSize: number | null = null): Promise { const url = 'claims'; return this._getNextPage(url, 'claims', claims, pageSize); } diff --git a/src/services/embeddable_service.ts b/src/services/embeddable_service.ts index 061d2e9fa..c20dafd28 100644 --- a/src/services/embeddable_service.ts +++ b/src/services/embeddable_service.ts @@ -18,9 +18,7 @@ export default (easypostClient: EasyPostClient) => * @param {Object} [params] - The parameters to create a session from. * @returns {Object} - An object containing the created session. */ - static async createSession( - params: EmbeddablesSessionCreateParameters = {}, - ): Promise { + static async createSession(params: EmbeddablesSessionCreateParameters = {}): Promise { const url = 'embeddables/session'; try { diff --git a/src/services/event_service.ts b/src/services/event_service.ts index 9ac46095c..aa8e2f127 100644 --- a/src/services/event_service.ts +++ b/src/services/event_service.ts @@ -67,10 +67,7 @@ export default (easypostClient: EasyPostClient) => * @param {Number} pageSize The number of records to return on each page * @returns {EasyPostObject|Promise} The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. */ - static async getNextPage( - events: EventCollection, - pageSize: number | null = null, - ): Promise { + static async getNextPage(events: EventCollection, pageSize: number | null = null): Promise { const url = 'events'; return this._getNextPage(url, 'events', events, pageSize); } diff --git a/src/services/pickup_service.ts b/src/services/pickup_service.ts index 69fecf490..a295445cd 100644 --- a/src/services/pickup_service.ts +++ b/src/services/pickup_service.ts @@ -101,10 +101,7 @@ export default (easypostClient: EasyPostClient) => * @param {Number} pageSize The number of records to return on each page * @returns {EasyPostObject|Promise} The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. */ - static async getNextPage( - pickups: PickupCollection, - pageSize: number | null = null, - ): Promise { + static async getNextPage(pickups: PickupCollection, pageSize: number | null = null): Promise { const url = 'pickups'; return this._getNextPage(url, 'pickups', pickups, pageSize); } diff --git a/src/services/refund_service.ts b/src/services/refund_service.ts index 804162342..d30d87410 100644 --- a/src/services/refund_service.ts +++ b/src/services/refund_service.ts @@ -49,10 +49,7 @@ export default (easypostClient: EasyPostClient) => * @param {Number} pageSize The number of records to return on each page * @returns {EasyPostObject|Promise} The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. */ - static async getNextPage( - refunds: RefundCollection, - pageSize: number | null = null, - ): Promise { + static async getNextPage(refunds: RefundCollection, pageSize: number | null = null): Promise { const url = 'refunds'; return this._getNextPage(url, 'refunds', refunds, pageSize); } diff --git a/src/services/report_service.ts b/src/services/report_service.ts index e3b3dac66..3d7267dda 100644 --- a/src/services/report_service.ts +++ b/src/services/report_service.ts @@ -64,10 +64,7 @@ export default (easypostClient: EasyPostClient) => * @param {Number} pageSize The number of records to return on each page * @returns {EasyPostObject|Promise} The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. */ - static async getNextPage( - reports: ReportCollection, - pageSize: number | null = null, - ): Promise { + static async getNextPage(reports: ReportCollection, pageSize: number | null = null): Promise { const firstReport = reports.reports?.[0] as { _params?: { type?: string } } | undefined; const url = `reports/${firstReport?._params?.type || ''}`; return this._getNextPage(url, 'reports', reports, pageSize); diff --git a/src/services/shipment_service.ts b/src/services/shipment_service.ts index fbd2ab25c..b34c92171 100644 --- a/src/services/shipment_service.ts +++ b/src/services/shipment_service.ts @@ -27,12 +27,7 @@ type ShipmentCreateParameters = Record & { from_address?: AddressCreateParameters | Address | string | null; parcel?: ParcelCreateParameters | Parcel | string | null; carrier_accounts?: string[] | null; - customs_info?: - | CustomsInfo - | CustomsInfo[] - | CustomsInfoCreateParameters - | CustomsInfoCreateParameters[] - | null; + customs_info?: CustomsInfo | CustomsInfo[] | CustomsInfoCreateParameters | CustomsInfoCreateParameters[] | null; tax_identifiers?: Array | null; options?: Record | null; line_items?: ShipmentLineItem[] | null; @@ -252,11 +247,7 @@ export default (easypostClient: EasyPostClient) => deliveryAccuracy: string, ): Promise> { const smartRates = (await this.getSmartRates(id)) as SmartRate[]; - return Constants.Utils.getLowestSmartRate( - smartRates, - deliveryDays, - deliveryAccuracy.toLowerCase(), - ); + return Constants.Utils.getLowestSmartRate(smartRates, deliveryDays, deliveryAccuracy.toLowerCase()); } /** @@ -277,10 +268,7 @@ export default (easypostClient: EasyPostClient) => * @param {Number} pageSize The number of records to return on each page * @returns {EasyPostObject|Promise} The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error. */ - static async getNextPage( - shipments: ShipmentCollection, - pageSize?: number, - ): Promise { + static async getNextPage(shipments: ShipmentCollection, pageSize?: number): Promise { const url = 'shipments'; return this._getNextPage(url, 'shipments', shipments, pageSize); @@ -329,10 +317,7 @@ export default (easypostClient: EasyPostClient) => * @param desiredDeliveryDate - The desired delivery date for the shipment. * @returns {Array} - An array of the recommended ship date and rates. */ - static async recommendShipDate( - id: string, - desiredDeliveryDate: string, - ): Promise { + static async recommendShipDate(id: string, desiredDeliveryDate: string): Promise { const url = `shipments/${id}/smartrate/precision_shipping`; const wrappedParams = { diff --git a/src/services/user_service.ts b/src/services/user_service.ts index c923496ad..3d59ef862 100644 --- a/src/services/user_service.ts +++ b/src/services/user_service.ts @@ -187,8 +187,7 @@ export default (easypostClient: EasyPostClient) => throw new EndOfPaginationError(); } - const firstObjectParams = - (collectionArray[0]?._params as Record | undefined) ?? {}; + const firstObjectParams = (collectionArray[0]?._params as Record | undefined) ?? {}; const defaultParams = collection._params ?? firstObjectParams; const params = { @@ -199,11 +198,7 @@ export default (easypostClient: EasyPostClient) => const response = (await this._all(url, params)) as Record; const responseCollection = response[key] as Array> | undefined; - if ( - response == undefined || - responseCollection == undefined || - responseCollection.length == 0 - ) { + if (response == undefined || responseCollection == undefined || responseCollection.length == 0) { throw new EndOfPaginationError(); } diff --git a/src/utils/util.ts b/src/utils/util.ts index c355313cc..b0927f9ff 100644 --- a/src/utils/util.ts +++ b/src/utils/util.ts @@ -33,11 +33,7 @@ export default class Utils { * @throws {FilteringError} - If no applicable rates are found * @throws {InvalidParameterError} - If the deliveryAccuracy value is invalid */ - getLowestSmartRate( - smartrates: SmartRate[], - deliveryDays: number | string, - deliveryAccuracy: string, - ): SmartRate { + getLowestSmartRate(smartrates: SmartRate[], deliveryDays: number | string, deliveryAccuracy: string): SmartRate { const validDeliveryAccuracyValues = new Set([ 'percentile_50', 'percentile_75', @@ -52,9 +48,9 @@ export default class Utils { if (!validDeliveryAccuracyValues.has(lowercaseDeliveryAccuracy)) { throw new InvalidParameterError({ - message: `Invalid deliveryAccuracy value, must be one of: ${Array.from( - validDeliveryAccuracyValues, - ).join(', ')}`, + message: `Invalid deliveryAccuracy value, must be one of: ${Array.from(validDeliveryAccuracyValues).join( + ', ', + )}`, }); } @@ -64,10 +60,7 @@ export default class Utils { if (rate.time_in_transit[lowercaseDeliveryAccuracy] > parseInt(String(deliveryDays), 10)) { // eslint-disable-next-line no-continue continue; - } else if ( - lowestSmartRate === null || - parseFloat(rate.rate) < parseFloat(lowestSmartRate.rate) - ) { + } else if (lowestSmartRate === null || parseFloat(rate.rate) < parseFloat(lowestSmartRate.rate)) { lowestSmartRate = rate; } } @@ -88,11 +81,7 @@ export default class Utils { * @returns {Rate} - The lowest rate * @throws {FilteringError} - If no applicable rates are found */ - getLowestRate( - rates: Rate[], - carriers: string[] | null = null, - services: string[] | null = null, - ): Rate { + getLowestRate(rates: Rate[], carriers: string[] | null = null, services: string[] | null = null): Rate { if (carriers) { const carriersLower = carriers.map((carrier) => carrier.toLowerCase()); // eslint-disable-next-line no-param-reassign @@ -136,8 +125,7 @@ export default class Utils { webhookSecret: string, ): Record { let webhook: Record = {}; - const easypostHmacSignature = - headers['X-Hmac-Signature'] ?? headers['x-hmac-signature'] ?? null; + const easypostHmacSignature = headers['X-Hmac-Signature'] ?? headers['x-hmac-signature'] ?? null; if (easypostHmacSignature != null) { const normalizedSecret = webhookSecret.normalize('NFKD'); @@ -156,12 +144,7 @@ export default class Utils { const digest = `hmac-sha256-hex=${expectedSignature}`; try { - if ( - crypto.timingSafeEqual( - Buffer.from(easypostHmacSignature, 'utf8'), - Buffer.from(digest, 'utf8'), - ) - ) { + if (crypto.timingSafeEqual(Buffer.from(easypostHmacSignature, 'utf8'), Buffer.from(digest, 'utf8'))) { webhook = JSON.parse(correctedEventBody); } else { throw new SignatureVerificationError({ message: Constants.WEBHOOK_DOES_NOT_MATCH }); diff --git a/test/helpers/fixture.ts b/test/helpers/fixture.ts index 0558e518a..b3703cfea 100644 --- a/test/helpers/fixture.ts +++ b/test/helpers/fixture.ts @@ -7,10 +7,7 @@ export default class Fixture { static readFixtureData(): FixtureData { const currentDir = process.cwd(); const fixtures = JSON.parse( - fs.readFileSync( - `${currentDir}/examples/official/fixtures/client-library-fixtures.json`, - 'utf8', - ), + fs.readFileSync(`${currentDir}/examples/official/fixtures/client-library-fixtures.json`, 'utf8'), ) as FixtureData; return fixtures; @@ -158,9 +155,7 @@ export default class Fixture { static eventBody(): Buffer { const currentDir = process.cwd(); - const eventBody = JSON.parse( - fs.readFileSync(`${currentDir}/examples/official/fixtures/event-body.json`, 'utf8'), - ); + const eventBody = JSON.parse(fs.readFileSync(`${currentDir}/examples/official/fixtures/event-body.json`, 'utf8')); return Buffer.from(JSON.stringify(eventBody), 'utf8'); } diff --git a/test/helpers/mocking.ts b/test/helpers/mocking.ts index 6d3b3ab30..cfdd3b560 100644 --- a/test/helpers/mocking.ts +++ b/test/helpers/mocking.ts @@ -9,8 +9,7 @@ export class MockRequestMatchRule { constructor(method: string, urlRegexPattern: string | RegExp) { this.method = method; - this.urlRegexPattern = - urlRegexPattern instanceof RegExp ? urlRegexPattern : new RegExp(urlRegexPattern); + this.urlRegexPattern = urlRegexPattern instanceof RegExp ? urlRegexPattern : new RegExp(urlRegexPattern); } } @@ -79,10 +78,7 @@ export class MockMiddleware { // For each mock request, check if the method and URL match. for (let i = 0; i < this.mockRequests.length; i += 1) { const mockRequest = this.mockRequests[i]; - if ( - mockRequest.matchRule.method === request.method && - request.url.match(mockRequest.matchRule.urlRegexPattern) - ) { + if (mockRequest.matchRule.method === request.method && request.url.match(mockRequest.matchRule.urlRegexPattern)) { return mockRequest; } } diff --git a/test/helpers/setup_polly.ts b/test/helpers/setup_polly.ts index ac4e368c8..5aa38e1e7 100644 --- a/test/helpers/setup_polly.ts +++ b/test/helpers/setup_polly.ts @@ -86,9 +86,7 @@ const scrubbers = { }; function scrubHeaders(recording: PollyRecording) { - recording.request.headers = recording.request.headers.filter( - ({ name }) => !headerScrubbers.includes(name), - ); + recording.request.headers = recording.request.headers.filter(({ name }) => !headerScrubbers.includes(name)); } /** diff --git a/test/services/address.test.ts b/test/services/address.test.ts index 126234e15..bb00a53db 100644 --- a/test/services/address.test.ts +++ b/test/services/address.test.ts @@ -10,9 +10,7 @@ import * as setupPolly from '../helpers/setup_polly'; import { withoutParams } from '../helpers/utils'; type AddressTestCreateInput = Parameters['create']>[0]; -type AddressTestCreateAndVerifyInput = Parameters< - ReturnType['createAndVerify'] ->[0]; +type AddressTestCreateAndVerifyInput = Parameters['createAndVerify']>[0]; /* eslint-disable func-names */ describe('Address Service', function () { diff --git a/test/services/base_service.test.ts b/test/services/base_service.test.ts index a606f8ab1..0612afd53 100644 --- a/test/services/base_service.test.ts +++ b/test/services/base_service.test.ts @@ -4,12 +4,7 @@ import { expect } from 'vitest'; import EasyPostClient from '../../src/easypost'; import EndOfPaginationError from '../../src/errors/general/end_of_pagination_error'; import * as setupPolly from '../helpers/setup_polly'; -import { - MockMiddleware, - MockRequest, - MockRequestMatchRule, - MockRequestResponseInfo, -} from '../helpers/mocking'; +import { MockMiddleware, MockRequest, MockRequestMatchRule, MockRequestResponseInfo } from '../helpers/mocking'; describe('Base Service', function () { const getPolly = setupPolly.setupPollyTests(); diff --git a/test/services/batch.test.ts b/test/services/batch.test.ts index eb6cf8d64..3fd4a008b 100644 --- a/test/services/batch.test.ts +++ b/test/services/batch.test.ts @@ -79,10 +79,7 @@ describe('Batch Service', function () { if ( !fs.existsSync( - resolve( - __dirname, - '../cassettes/Batch-Service_3950244400/creates-a-scanform-for-a-batch_397052124', - ), + resolve(__dirname, '../cassettes/Batch-Service_3950244400/creates-a-scanform-for-a-batch_397052124'), ) ) { await new Promise((res) => setTimeout(res, 5000)); // Wait enough time for the batch to process buying the shipment @@ -95,9 +92,7 @@ describe('Batch Service', function () { }); it('adds and removes shipments from a batch', async function () { - const shipment = await client.Shipment.create( - Fixture.oneCallBuyShipment() as ShipmentTestCreateInput, - ); + const shipment = await client.Shipment.create(Fixture.oneCallBuyShipment() as ShipmentTestCreateInput); const batch = await client.Batch.create({}); const addShipmentsResponse = await client.Batch.addShipments(batch.id, [shipment.id]); @@ -116,10 +111,7 @@ describe('Batch Service', function () { if ( !fs.existsSync( - resolve( - __dirname, - '../cassettes/Batch-Service_3950244400/generates-a-label-for-a-batch_2376202846', - ), + resolve(__dirname, '../cassettes/Batch-Service_3950244400/generates-a-label-for-a-batch_2376202846'), ) ) { await new Promise((res) => setTimeout(res, 5000)); // Wait enough time for the batch to process buying the shipment diff --git a/test/services/beta_rate.test.ts b/test/services/beta_rate.test.ts index ad8338ada..588369a62 100644 --- a/test/services/beta_rate.test.ts +++ b/test/services/beta_rate.test.ts @@ -7,9 +7,7 @@ import type BetaRateServiceFactory from '../../src/services/beta_rate_service'; import Fixture from '../helpers/fixture'; import * as setupPolly from '../helpers/setup_polly'; -type BetaRateRetrieveInput = Parameters< - ReturnType['retrieveStatelessRates'] ->[0]; +type BetaRateRetrieveInput = Parameters['retrieveStatelessRates']>[0]; /* eslint-disable func-names */ describe('BetaRateService', function () { @@ -53,11 +51,7 @@ describe('BetaRateService', function () { ); expect(() => { - client.Utils.getLowestRate( - statelessRateResponse.rates, - ['invalid_carrier'], - ['invalid_service'], - ); + client.Utils.getLowestRate(statelessRateResponse.rates, ['invalid_carrier'], ['invalid_service']); }).to.throw(FilteringError, 'No rates found.'); }); }); diff --git a/test/services/beta_referral_customer.test.ts b/test/services/beta_referral_customer.test.ts index a83bf6ed5..c634e46e4 100644 --- a/test/services/beta_referral_customer.test.ts +++ b/test/services/beta_referral_customer.test.ts @@ -29,9 +29,7 @@ describe('BetaReferralCustomerService', function () { await client.BetaReferralCustomer.refundByAmount(2000).catch((error: any) => { expect(error.statusCode).to.equal(422); expect(error.code).to.equal('TRANSACTION.AMOUNT_INVALID'); - expect(error.message).to.equal( - 'Refund amount is invalid. Please use a valid amount or escalate to finance.', - ); + expect(error.message).to.equal('Refund amount is invalid. Please use a valid amount or escalate to finance.'); }); }); diff --git a/test/services/billing.test.ts b/test/services/billing.test.ts index 4ae5ca116..8f61c4b8e 100644 --- a/test/services/billing.test.ts +++ b/test/services/billing.test.ts @@ -2,12 +2,7 @@ import { expect } from 'vitest'; import EasyPostClient from '../../src/easypost'; -import { - MockMiddleware, - MockRequest, - MockRequestMatchRule, - MockRequestResponseInfo, -} from '../helpers/mocking'; +import { MockMiddleware, MockRequest, MockRequestMatchRule, MockRequestResponseInfo } from '../helpers/mocking'; const middleware = (request: any) => { return new MockMiddleware(request, [ diff --git a/test/services/carrier_account.test.ts b/test/services/carrier_account.test.ts index c8974914c..ce31442d2 100644 --- a/test/services/carrier_account.test.ts +++ b/test/services/carrier_account.test.ts @@ -8,9 +8,7 @@ import Fixture from '../helpers/fixture'; import * as setupPolly from '../helpers/setup_polly'; import { withoutParams } from '../helpers/utils'; -type CarrierAccountTestCreateInput = Parameters< - ReturnType['create'] ->[0]; +type CarrierAccountTestCreateInput = Parameters['create']>[0]; /* eslint-disable func-names */ describe('CarrierAccount Service', function () { diff --git a/test/services/carrier_metadata.test.ts b/test/services/carrier_metadata.test.ts index 56390ef59..d3620012e 100644 --- a/test/services/carrier_metadata.test.ts +++ b/test/services/carrier_metadata.test.ts @@ -25,10 +25,7 @@ describe('CarrierMetadataService', function () { }); it('retrieves carrier metadata based on the filters provided', async function () { - const carrierMetadata = await client.CarrierMetadata.retrieve( - ['usps'], - ['service_levels', 'predefined_packages'], - ); + const carrierMetadata = await client.CarrierMetadata.retrieve(['usps'], ['service_levels', 'predefined_packages']); expect(carrierMetadata.some((carrier: any) => carrier.name === 'usps')).to.be.true; expect(carrierMetadata).to.have.lengthOf(1); diff --git a/test/services/customs_info.test.ts b/test/services/customs_info.test.ts index 8d28453a4..81eaaf8e4 100644 --- a/test/services/customs_info.test.ts +++ b/test/services/customs_info.test.ts @@ -8,9 +8,7 @@ import Fixture from '../helpers/fixture'; import * as setupPolly from '../helpers/setup_polly'; import { withoutParams } from '../helpers/utils'; -type CustomsInfoTestCreateInput = Parameters< - ReturnType['create'] ->[0]; +type CustomsInfoTestCreateInput = Parameters['create']>[0]; describe('CustomsInfo Service', function () { const getPolly = setupPolly.setupPollyTests(); diff --git a/test/services/customs_item.test.ts b/test/services/customs_item.test.ts index 49f4266fe..c9fc69755 100644 --- a/test/services/customs_item.test.ts +++ b/test/services/customs_item.test.ts @@ -9,9 +9,7 @@ import Fixture from '../helpers/fixture'; import * as setupPolly from '../helpers/setup_polly'; import { withoutParams } from '../helpers/utils'; -type CustomsItemTestCreateInput = Parameters< - ReturnType['create'] ->[0]; +type CustomsItemTestCreateInput = Parameters['create']>[0]; describe('CustomsItem Service', function () { const getPolly = setupPolly.setupPollyTests(); diff --git a/test/services/easypost.test.ts b/test/services/easypost.test.ts index 239c5ccd0..c77e1ae21 100644 --- a/test/services/easypost.test.ts +++ b/test/services/easypost.test.ts @@ -23,10 +23,7 @@ describe('EasyPost', function () { }); it('throws an error when no API key is provided', async function () { - expect(() => new EasyPostClient()).to.throw( - MissingParameterError, - 'Missing required parameter: API Key.', - ); + expect(() => new EasyPostClient()).to.throw(MissingParameterError, 'Missing required parameter: API Key.'); }); it('will log the appropriate values when a request and response hooks are provided', async function () { @@ -59,9 +56,7 @@ describe('EasyPost', function () { expect(responseConfig.headers).to.be.an('object'); expect(responseConfig.headers['content-type']).to.contain('application/json'); expect(responseConfig.responseTimestamp).to.be.a('number'); - expect(responseConfig.responseTimestamp).to.be.greaterThanOrEqual( - responseConfig.requestTimestamp, - ); + expect(responseConfig.responseTimestamp).to.be.greaterThanOrEqual(responseConfig.requestTimestamp); }); it('will add more than one request and response hook', async function () { diff --git a/test/services/end_shipper.test.ts b/test/services/end_shipper.test.ts index d80118ad3..f179889c0 100644 --- a/test/services/end_shipper.test.ts +++ b/test/services/end_shipper.test.ts @@ -23,9 +23,7 @@ describe('EndShipper Service', function () { }); it('creates an EndShipper object', async function () { - const endShipper = await client.EndShipper.create( - Fixture.caAddress1() as EndShipperCreateInput, - ); + const endShipper = await client.EndShipper.create(Fixture.caAddress1() as EndShipperCreateInput); expect(endShipper).to.be.an.instanceOf(EndShipper); expect(endShipper.id).to.match(/^es_/); @@ -33,9 +31,7 @@ describe('EndShipper Service', function () { }); it('retrieves an EndShipper object', async function () { - const endShipper = await client.EndShipper.create( - Fixture.caAddress2() as EndShipperCreateInput, - ); + const endShipper = await client.EndShipper.create(Fixture.caAddress2() as EndShipperCreateInput); const retrievedEndShipper = await client.EndShipper.retrieve(endShipper.id); expect(retrievedEndShipper).to.be.an.instanceOf(EndShipper); @@ -55,9 +51,7 @@ describe('EndShipper Service', function () { }); it('updates an EndShipper object', async function () { - const endShipper = await client.EndShipper.create( - Fixture.caAddress2() as EndShipperCreateInput, - ); + const endShipper = await client.EndShipper.create(Fixture.caAddress2() as EndShipperCreateInput); const params: EndShipperUpdateInput = {}; const newName = 'Captain Sparrow'; diff --git a/test/services/error.test.ts b/test/services/error.test.ts index 2e77c5298..aef2ef578 100644 --- a/test/services/error.test.ts +++ b/test/services/error.test.ts @@ -130,9 +130,7 @@ describe('Error Service', function () { }) .to.throw(NotFoundError) .and.satisfy((error: any) => { - expect(error.message).to.be.equal( - 'Bad format 1, Bad format 2, Bad format 3, Bad format 4, Bad format 5', - ); + expect(error.message).to.be.equal('Bad format 1, Bad format 2, Bad format 3, Bad format 4, Bad format 5'); expect(error.code).to.be.equal('NO RESPONSE CODE'); expect(error.errors).to.be.an('array').that.is.empty; return true; diff --git a/test/services/event.test.ts b/test/services/event.test.ts index 41686ba66..34b4c4cba 100644 --- a/test/services/event.test.ts +++ b/test/services/event.test.ts @@ -83,10 +83,7 @@ describe('Event Service', function () { if ( !fs.existsSync( - resolve( - __dirname, - '../cassettes/Event-Service_3026743340/retrieves-all-payloads-for-an-event_3292460230', - ), + resolve(__dirname, '../cassettes/Event-Service_3026743340/retrieves-all-payloads-for-an-event_3292460230'), ) ) { await new Promise((res) => setTimeout(res, 5000)); // Wait enough time for the event to be created @@ -121,10 +118,7 @@ describe('Event Service', function () { if ( !fs.existsSync( - resolve( - __dirname, - '../cassettes/Event-Service_3026743340/retrieves-a-payload-for-an-event_1410906611', - ), + resolve(__dirname, '../cassettes/Event-Service_3026743340/retrieves-a-payload-for-an-event_1410906611'), ) ) { await new Promise((res) => setTimeout(res, 5000)); // Wait enough time for the event to be created diff --git a/test/services/fedex_registration.test.ts b/test/services/fedex_registration.test.ts index b2d0b8c96..ad4cbf05f 100644 --- a/test/services/fedex_registration.test.ts +++ b/test/services/fedex_registration.test.ts @@ -1,12 +1,7 @@ import { expect } from 'vitest'; import EasyPostClient from '../../src/easypost'; -import { - MockMiddleware, - MockRequest, - MockRequestMatchRule, - MockRequestResponseInfo, -} from '../helpers/mocking'; +import { MockMiddleware, MockRequest, MockRequestMatchRule, MockRequestResponseInfo } from '../helpers/mocking'; /* eslint-disable func-names */ describe('FedExRegistrationService', function () { @@ -39,10 +34,7 @@ describe('FedExRegistrationService', function () { const middleware = (request: any) => { return new MockMiddleware(request, [ new MockRequest( - new MockRequestMatchRule( - 'POST', - `v2\\/fedex_registrations\\/${fedexAccountNumber}\\/address`, - ), + new MockRequestMatchRule('POST', `v2\\/fedex_registrations\\/${fedexAccountNumber}\\/address`), new MockRequestResponseInfo(200, mockResponse), ), ]); @@ -77,10 +69,7 @@ describe('FedExRegistrationService', function () { const middleware = (request: any) => { return new MockMiddleware(request, [ new MockRequest( - new MockRequestMatchRule( - 'POST', - `v2\\/fedex_registrations\\/${fedexAccountNumber}\\/pin`, - ), + new MockRequestMatchRule('POST', `v2\\/fedex_registrations\\/${fedexAccountNumber}\\/pin`), new MockRequestResponseInfo(200, mockResponse), ), ]); @@ -124,10 +113,7 @@ describe('FedExRegistrationService', function () { const middleware = (request: any) => { return new MockMiddleware(request, [ new MockRequest( - new MockRequestMatchRule( - 'POST', - `v2\\/fedex_registrations\\/${fedexAccountNumber}\\/pin\\/validate`, - ), + new MockRequestMatchRule('POST', `v2\\/fedex_registrations\\/${fedexAccountNumber}\\/pin\\/validate`), new MockRequestResponseInfo(200, mockResponse), ), ]); @@ -178,10 +164,7 @@ describe('FedExRegistrationService', function () { const middleware = (request: any) => { return new MockMiddleware(request, [ new MockRequest( - new MockRequestMatchRule( - 'POST', - `v2\\/fedex_registrations\\/${fedexAccountNumber}\\/invoice`, - ), + new MockRequestMatchRule('POST', `v2\\/fedex_registrations\\/${fedexAccountNumber}\\/invoice`), new MockRequestResponseInfo(200, mockResponse), ), ]); diff --git a/test/services/insurance.test.ts b/test/services/insurance.test.ts index b0d72b0e8..88dc9ba90 100644 --- a/test/services/insurance.test.ts +++ b/test/services/insurance.test.ts @@ -26,9 +26,7 @@ describe('Insurance Service', function () { }); it('creates an insurance object', async function () { - const shipment = await client.Shipment.create( - Fixture.oneCallBuyShipment() as ShipmentTestCreateInput, - ); + const shipment = await client.Shipment.create(Fixture.oneCallBuyShipment() as ShipmentTestCreateInput); const insuranceData = Fixture.basicInsurance() as InsuranceTestCreateInput; insuranceData.tracking_code = shipment.tracking_code; @@ -41,9 +39,7 @@ describe('Insurance Service', function () { }); it('retrieves an insurance object', async function () { - const shipment = await client.Shipment.create( - Fixture.oneCallBuyShipment() as ShipmentTestCreateInput, - ); + const shipment = await client.Shipment.create(Fixture.oneCallBuyShipment() as ShipmentTestCreateInput); const insuranceData = Fixture.basicInsurance() as InsuranceTestCreateInput; insuranceData.tracking_code = shipment.tracking_code; diff --git a/test/services/pickup.test.ts b/test/services/pickup.test.ts index 4205bbfb5..9f0e7225f 100644 --- a/test/services/pickup.test.ts +++ b/test/services/pickup.test.ts @@ -28,9 +28,7 @@ describe('Pickup Service', function () { }); it('creates a pickup', async function () { - const shipment = await client.Shipment.create( - Fixture.oneCallBuyShipment() as ShipmentTestCreateInput, - ); + const shipment = await client.Shipment.create(Fixture.oneCallBuyShipment() as ShipmentTestCreateInput); const pickupData = Fixture.basicPickup() as PickupTestCreateInput; pickupData.shipment = withoutParams(shipment); @@ -43,9 +41,7 @@ describe('Pickup Service', function () { }, 20000); it('retrieves a pickup', async function () { - const shipment = await client.Shipment.create( - Fixture.oneCallBuyShipment() as ShipmentTestCreateInput, - ); + const shipment = await client.Shipment.create(Fixture.oneCallBuyShipment() as ShipmentTestCreateInput); const pickupData = Fixture.basicPickup() as PickupTestCreateInput; pickupData.shipment = withoutParams(shipment); @@ -87,20 +83,14 @@ describe('Pickup Service', function () { }); it('buys a pickup', async function () { - const shipment = await client.Shipment.create( - Fixture.oneCallBuyShipment() as ShipmentTestCreateInput, - ); + const shipment = await client.Shipment.create(Fixture.oneCallBuyShipment() as ShipmentTestCreateInput); const pickupData = Fixture.basicPickup() as PickupTestCreateInput; pickupData.shipment = withoutParams(shipment); const pickup = await client.Pickup.create(pickupData); - const boughtPickup = await client.Pickup.buy( - pickup.id, - Fixture.usps(), - Fixture.pickupService(), - ); + const boughtPickup = await client.Pickup.buy(pickup.id, Fixture.usps(), Fixture.pickupService()); expect(boughtPickup).to.be.an.instanceOf(Pickup); expect(boughtPickup.id).to.match(/^pickup_/); @@ -109,19 +99,13 @@ describe('Pickup Service', function () { }, 20000); it('cancels a pickup', async function () { - const shipment = await client.Shipment.create( - Fixture.oneCallBuyShipment() as ShipmentTestCreateInput, - ); + const shipment = await client.Shipment.create(Fixture.oneCallBuyShipment() as ShipmentTestCreateInput); const pickupData = Fixture.basicPickup() as PickupTestCreateInput; pickupData.shipment = withoutParams(shipment); const pickup = await client.Pickup.create(pickupData); - const boughtPickup = await client.Pickup.buy( - pickup.id, - Fixture.usps(), - Fixture.pickupService(), - ); + const boughtPickup = await client.Pickup.buy(pickup.id, Fixture.usps(), Fixture.pickupService()); const cancelledPickup = await client.Pickup.cancel(boughtPickup.id); @@ -131,9 +115,7 @@ describe('Pickup Service', function () { }, 30000); it('gets the lowest rate', async function () { - const shipment = await client.Shipment.create( - Fixture.oneCallBuyShipment() as ShipmentTestCreateInput, - ); + const shipment = await client.Shipment.create(Fixture.oneCallBuyShipment() as ShipmentTestCreateInput); const pickupData = Fixture.basicPickup() as PickupTestCreateInput; pickupData.shipment = withoutParams(shipment); diff --git a/test/services/rate.test.ts b/test/services/rate.test.ts index 00da11646..d689b0fb6 100644 --- a/test/services/rate.test.ts +++ b/test/services/rate.test.ts @@ -23,9 +23,7 @@ describe('Rate Service', function () { }); it('retrieves a rate', async function () { - const shipment = await client.Shipment.create( - Fixture.basicShipment() as ShipmentTestCreateInput, - ); + const shipment = await client.Shipment.create(Fixture.basicShipment() as ShipmentTestCreateInput); const rate = await client.Rate.retrieve(shipment.rates[0].id); diff --git a/test/services/referral_customer.test.ts b/test/services/referral_customer.test.ts index 3f097ae0f..169d1510c 100644 --- a/test/services/referral_customer.test.ts +++ b/test/services/referral_customer.test.ts @@ -8,9 +8,7 @@ import type ReferralCustomerServiceFactory from '../../src/services/referral_cus import Fixture from '../helpers/fixture'; import * as setupPolly from '../helpers/setup_polly'; -type ReferralCustomerCreateInput = Parameters< - ReturnType['create'] ->[0]; +type ReferralCustomerCreateInput = Parameters['create']>[0]; type ReferralCustomerAddCardStripeParams = Parameters< ReturnType['addCreditCardFromStripe'] >; @@ -119,9 +117,7 @@ describe('ReferralCustomer Service', function () { billing.payment_method_id, billing.priority, ).catch((error: any) => { - expect(error.message).to.equal( - 'Stripe::PaymentMethod does not exist for the specified reference_id', - ); + expect(error.message).to.equal('Stripe::PaymentMethod does not exist for the specified reference_id'); }); }); diff --git a/test/services/refund.test.ts b/test/services/refund.test.ts index e41ea7c7d..8c623b6df 100644 --- a/test/services/refund.test.ts +++ b/test/services/refund.test.ts @@ -25,9 +25,7 @@ describe('Refund Service', function () { }); it('creates a refund', async function () { - const shipment = await client.Shipment.create( - Fixture.oneCallBuyShipment() as ShipmentTestCreateInput, - ); + const shipment = await client.Shipment.create(Fixture.oneCallBuyShipment() as ShipmentTestCreateInput); // We need to retrieve the shipment so that the tracking_code has time to populate const retrievedShipment = await client.Shipment.retrieve(shipment.id); diff --git a/test/services/scan_form.test.ts b/test/services/scan_form.test.ts index 736d64861..4bd679518 100644 --- a/test/services/scan_form.test.ts +++ b/test/services/scan_form.test.ts @@ -27,9 +27,7 @@ describe('ScanForm Service', function () { }); it('creates a scanform', async function () { - const shipment = await client.Shipment.create( - Fixture.oneCallBuyShipment() as ShipmentTestCreateInput, - ); + const shipment = await client.Shipment.create(Fixture.oneCallBuyShipment() as ShipmentTestCreateInput); const scanform = await client.ScanForm.create({ shipments: [shipment], @@ -40,9 +38,7 @@ describe('ScanForm Service', function () { }); it('retrieves a scanform', async function () { - const shipment = await client.Shipment.create( - Fixture.oneCallBuyShipment() as ShipmentTestCreateInput, - ); + const shipment = await client.Shipment.create(Fixture.oneCallBuyShipment() as ShipmentTestCreateInput); const scanform = await client.ScanForm.create({ shipments: [shipment], diff --git a/test/services/shipment.test.ts b/test/services/shipment.test.ts index 3db5b2995..7a6e68576 100644 --- a/test/services/shipment.test.ts +++ b/test/services/shipment.test.ts @@ -14,17 +14,11 @@ import Fixture from '../helpers/fixture'; import * as setupPolly from '../helpers/setup_polly'; type AddressTestCreateInput = Parameters['create']>[0]; -type EndShipperTestCreateInput = Parameters< - ReturnType['create'] ->[0]; +type EndShipperTestCreateInput = Parameters['create']>[0]; type ParcelTestCreateInput = Parameters['create']>[0]; type ShipmentTestCreateInput = Parameters['create']>[0]; -type ShipmentTestCreateAndBuyLumaInput = Parameters< - ReturnType['createAndBuyLuma'] ->[0]; -type ShipmentTestGenerateFormInput = Parameters< - ReturnType['generateForm'] ->[2]; +type ShipmentTestCreateAndBuyLumaInput = Parameters['createAndBuyLuma']>[0]; +type ShipmentTestGenerateFormInput = Parameters['generateForm']>[2]; /* eslint-disable func-names */ describe('Shipment Service', function () { @@ -41,9 +35,7 @@ describe('Shipment Service', function () { }); it('creates a shipment', async function () { - const shipment = await client.Shipment.create( - Fixture.fullShipment() as ShipmentTestCreateInput, - ); + const shipment = await client.Shipment.create(Fixture.fullShipment() as ShipmentTestCreateInput); expect(shipment).to.be.an.instanceOf(Shipment); expect(shipment.id).to.match(/^shp_/); @@ -101,9 +93,7 @@ describe('Shipment Service', function () { }); it('retrieves a shipment', async function () { - const shipment = await client.Shipment.create( - Fixture.fullShipment() as ShipmentTestCreateInput, - ); + const shipment = await client.Shipment.create(Fixture.fullShipment() as ShipmentTestCreateInput); const retrievedShipment = await client.Shipment.retrieve(shipment.id); @@ -142,9 +132,7 @@ describe('Shipment Service', function () { }); it('buys a shipment', async function () { - const shipment = await client.Shipment.create( - Fixture.fullShipment() as ShipmentTestCreateInput, - ); + const shipment = await client.Shipment.create(Fixture.fullShipment() as ShipmentTestCreateInput); const boughtShipment = await client.Shipment.buy(shipment.id, shipment.lowestRate()); @@ -152,9 +140,7 @@ describe('Shipment Service', function () { }); it('regenerates rates for a shipment', async function () { - const shipment = await client.Shipment.create( - Fixture.fullShipment() as ShipmentTestCreateInput, - ); + const shipment = await client.Shipment.create(Fixture.fullShipment() as ShipmentTestCreateInput); const rates = await client.Shipment.regenerateRates(shipment.id); @@ -167,9 +153,7 @@ describe('Shipment Service', function () { }); it('converts the label format of a shipment', async function () { - const shipment = await client.Shipment.create( - Fixture.fullShipment() as ShipmentTestCreateInput, - ); + const shipment = await client.Shipment.create(Fixture.fullShipment() as ShipmentTestCreateInput); const boughtShipment = await client.Shipment.buy(shipment.id, shipment.lowestRate()); @@ -195,9 +179,7 @@ describe('Shipment Service', function () { // Refunding a test shipment must happen within seconds of the shipment being created as test shipments naturally // follow a flow of created -> delivered to cycle through tracking events in test mode - as such anything older // than a few seconds in test mode may not be refundable. - const shipment = await client.Shipment.create( - Fixture.oneCallBuyShipment() as ShipmentTestCreateInput, - ); + const shipment = await client.Shipment.create(Fixture.oneCallBuyShipment() as ShipmentTestCreateInput); const refundedShipment = await client.Shipment.refund(shipment.id); @@ -205,9 +187,7 @@ describe('Shipment Service', function () { }); it('retrieves smartRates of a shipment', async function () { - const shipment = await client.Shipment.create( - Fixture.oneCallBuyShipment() as ShipmentTestCreateInput, - ); + const shipment = await client.Shipment.create(Fixture.oneCallBuyShipment() as ShipmentTestCreateInput); expect(shipment.rates).to.exist; @@ -223,9 +203,7 @@ describe('Shipment Service', function () { }); it('gets the lowest rate', async function () { - const shipment = await client.Shipment.create( - Fixture.fullShipment() as ShipmentTestCreateInput, - ); + const shipment = await client.Shipment.create(Fixture.fullShipment() as ShipmentTestCreateInput); // Test lowest rate with no filters const lowestRate = shipment.lowestRate(); @@ -246,9 +224,7 @@ describe('Shipment Service', function () { }); it('gets the lowest smartrate', async function () { - const shipment = await client.Shipment.create( - Fixture.basicShipment() as ShipmentTestCreateInput, - ); + const shipment = await client.Shipment.create(Fixture.basicShipment() as ShipmentTestCreateInput); // Test lowest smartrate with valid filters const lowestSmartRate = await client.Shipment.lowestSmartRate(shipment.id, 3, 'percentile_90'); @@ -258,9 +234,7 @@ describe('Shipment Service', function () { }); it('raises an error for lowestSmartRate when no rates are found due to deliveryDays', async function () { - const shipment = await client.Shipment.create( - Fixture.basicShipment() as ShipmentTestCreateInput, - ); + const shipment = await client.Shipment.create(Fixture.basicShipment() as ShipmentTestCreateInput); // Test lowest smartrate with invalid filters (should error due to strict deliveryDays) try { @@ -273,9 +247,7 @@ describe('Shipment Service', function () { }); it('raises an error for lowestSmartRate when no rates are found due to deliveryAccuracy', async function () { - const shipment = await client.Shipment.create( - Fixture.basicShipment() as ShipmentTestCreateInput, - ); + const shipment = await client.Shipment.create(Fixture.basicShipment() as ShipmentTestCreateInput); // Test lowest smartrate with invalid filters (should error due to invalid deliveryAccuracy) try { @@ -289,9 +261,7 @@ describe('Shipment Service', function () { }); it('gets the lowest smartrate from a list of smartRates', async function () { - const shipment = await client.Shipment.create( - Fixture.basicShipment() as ShipmentTestCreateInput, - ); + const shipment = await client.Shipment.create(Fixture.basicShipment() as ShipmentTestCreateInput); const smartRates = await client.Shipment.getSmartRates(shipment.id); // Test lowest smartrate with valid filters @@ -302,9 +272,7 @@ describe('Shipment Service', function () { }); it('raises an error for getLowestSmartRate when no rates are found due to deliveryDays', async function () { - const shipment = await client.Shipment.create( - Fixture.basicShipment() as ShipmentTestCreateInput, - ); + const shipment = await client.Shipment.create(Fixture.basicShipment() as ShipmentTestCreateInput); const smartRates = await client.Shipment.getSmartRates(shipment.id); // Test lowest smartrate with invalid filters (should error due to strict deliveryDays) @@ -314,9 +282,7 @@ describe('Shipment Service', function () { }); it('raises an error for getLowestSmartRate when no rates are found due to deliveryAccuracy', async function () { - const shipment = await client.Shipment.create( - Fixture.basicShipment() as ShipmentTestCreateInput, - ); + const shipment = await client.Shipment.create(Fixture.basicShipment() as ShipmentTestCreateInput); const smartRates = await client.Shipment.getSmartRates(shipment.id); // Test lowest smartrate with invalid filters (should error due to invalid deliveryAccuracy) @@ -329,9 +295,7 @@ describe('Shipment Service', function () { }); it('generates a form for a shipment', async function () { - const shipment = await client.Shipment.create( - Fixture.oneCallBuyShipment() as ShipmentTestCreateInput, - ); + const shipment = await client.Shipment.create(Fixture.oneCallBuyShipment() as ShipmentTestCreateInput); const formType = 'return_packing_slip'; @@ -350,36 +314,23 @@ describe('Shipment Service', function () { }); it('buys a shipment with insuranceAmount', async function () { - const shipment = await client.Shipment.create( - Fixture.basicShipment() as ShipmentTestCreateInput, - ); + const shipment = await client.Shipment.create(Fixture.basicShipment() as ShipmentTestCreateInput); const boughtShipment = await client.Shipment.buy(shipment.id, shipment.lowestRate(), 100); expect(boughtShipment.insurance).to.equal('100.00'); }); it('buys a shipment with end_shipper_id', async function () { - const endShipper = await client.EndShipper.create( - Fixture.caAddress1() as EndShipperTestCreateInput, - ); + const endShipper = await client.EndShipper.create(Fixture.caAddress1() as EndShipperTestCreateInput); - const shipment = await client.Shipment.create( - Fixture.basicShipment() as ShipmentTestCreateInput, - ); - const boughtShipment = await client.Shipment.buy( - shipment.id, - shipment.lowestRate(), - null, - endShipper.id, - ); + const shipment = await client.Shipment.create(Fixture.basicShipment() as ShipmentTestCreateInput); + const boughtShipment = await client.Shipment.buy(shipment.id, shipment.lowestRate(), null, endShipper.id); expect(boughtShipment.postage_label).to.exist; }); it('retrieve estimated delivery dates for each of the Rates of a shipment', async function () { - const shipment = await client.Shipment.create( - Fixture.basicShipment() as ShipmentTestCreateInput, - ); + const shipment = await client.Shipment.create(Fixture.basicShipment() as ShipmentTestCreateInput); const estimatedDeliveryDates = await client.Shipment.retrieveEstimatedDeliveryDate( shipment.id, Fixture.plannedShipDate(), @@ -393,13 +344,8 @@ describe('Shipment Service', function () { }); it('retrieve recommended ship dates for each of the Rates of a shipment', async function () { - const shipment = await client.Shipment.create( - Fixture.basicShipment() as ShipmentTestCreateInput, - ); - const recommendedShipDates = await client.Shipment.recommendShipDate( - shipment.id, - Fixture.plannedDeliveryDate(), - ); + const shipment = await client.Shipment.create(Fixture.basicShipment() as ShipmentTestCreateInput); + const recommendedShipDates = await client.Shipment.recommendShipDate(shipment.id, Fixture.plannedDeliveryDate()); for (const entry of recommendedShipDates) { expect(entry.rate).to.be.instanceOf(Rate); @@ -420,9 +366,7 @@ describe('Shipment Service', function () { }); it('buys a Shipment with Luma', async function () { - const shipment = await client.Shipment.create( - Fixture.basicShipment() as ShipmentTestCreateInput, - ); + const shipment = await client.Shipment.create(Fixture.basicShipment() as ShipmentTestCreateInput); const boughtShipment = await client.Shipment.buyLuma(shipment.id, { ruleset_name: Fixture.lumaRulesetName(), diff --git a/test/services/smart_rate.test.ts b/test/services/smart_rate.test.ts index 408cf1fa2..811504dec 100644 --- a/test/services/smart_rate.test.ts +++ b/test/services/smart_rate.test.ts @@ -7,12 +7,8 @@ import Fixture from '../helpers/fixture'; import * as setupPolly from '../helpers/setup_polly'; type AddressTestCreateInput = Parameters['create']>[0]; -type SmartRateEstimateInput = Parameters< - ReturnType['estimateDeliveryDate'] ->[0]; -type SmartRateRecommendInput = Parameters< - ReturnType['recommendShipDate'] ->[0]; +type SmartRateEstimateInput = Parameters['estimateDeliveryDate']>[0]; +type SmartRateRecommendInput = Parameters['recommendShipDate']>[0]; /* eslint-disable func-names */ describe('SmartRate Service', function () { diff --git a/test/services/webhook.test.ts b/test/services/webhook.test.ts index 6abe4c30f..081e926f6 100644 --- a/test/services/webhook.test.ts +++ b/test/services/webhook.test.ts @@ -101,11 +101,10 @@ describe('Webhook Service', function () { 'X-Hmac-Signature': Fixture.webhookHmacSignature(), }; - const webhookBody = client.Utils.validateWebhook( - Fixture.eventBody(), - headers, - Fixture.webhookSecret(), - ) as { description: string; result: { weight: number } }; + const webhookBody = client.Utils.validateWebhook(Fixture.eventBody(), headers, Fixture.webhookSecret()) as { + description: string; + result: { weight: number }; + }; expect(webhookBody.description).to.equal('tracker.updated'); expect(webhookBody.result.weight).to.equal(614.4); // Ensure we convert floats properly @@ -127,8 +126,7 @@ describe('Webhook Service', function () { it('throws an error when a webhook signature is invalid', function () { const webhookSecret = 'sécret'; - const expectedHmacSignature = - 'hmac-sha256-hex=e93977c8ccb20363d51a62b3fe1fc402b7829be1152da9e88cf9e8d07115aaaa'; // ending differs + const expectedHmacSignature = 'hmac-sha256-hex=e93977c8ccb20363d51a62b3fe1fc402b7829be1152da9e88cf9e8d07115aaaa'; // ending differs const headers = { 'X-Hmac-Signature': expectedHmacSignature, };