From 8514685f580e335bd678b194645b51e147127492 Mon Sep 17 00:00:00 2001 From: liaohanfei <2327441432@qq.com> Date: Fri, 3 Nov 2023 18:54:29 +0800 Subject: [PATCH] Modify the format of the air waybill number --- __tests__/airWaybills.test.js | 2 +- example/example.js | 38 +++++++++++++++++------------------ src/tracking/airWaybills.js | 4 ++-- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/__tests__/airWaybills.test.js b/__tests__/airWaybills.test.js index 161afb2..1b16fa2 100644 --- a/__tests__/airWaybills.test.js +++ b/__tests__/airWaybills.test.js @@ -27,7 +27,7 @@ describe('AirWaybills', () => { const apiKey = 'your-api-key'; const airWaybills = new AirWaybills(apiKey); - expect(() => airWaybills.createAnAirWayBill({awb_number: '123456'})).toThrow('The air waybill number format is invalid and can only be 12 digits in length'); + expect(() => airWaybills.createAnAirWayBill({awb_number: '123456'})).toThrow('The air waybill number format is invalid'); }); it('should send a POST request to /awb with awb_number', () => { diff --git a/example/example.js b/example/example.js index 47fd779..bee5157 100644 --- a/example/example.js +++ b/example/example.js @@ -4,14 +4,14 @@ const key = 'you api key' const trackingmore = new TrackingMore(key) -// try { -// // Get all couriers (couriers/all) -// trackingmore.couriers.getAllCouriers() -// .then(result => console.log(result)) -// .catch(e => console.log(e)) -// } catch (error) { -// console.error('An error occurred:', error.message) -// } +try { + // Get all couriers (couriers/all) + trackingmore.couriers.getAllCouriers() + .then(result => console.log(result)) + .catch(e => console.log(e)) +} catch (error) { + console.error('An error occurred:', error.message) +} // try { @@ -118,14 +118,14 @@ const trackingmore = new TrackingMore(key) // console.error('An error occurred:', error.message) // } -try { - // Create an air waybill (awb) - const params = { - 'awb_number': '235-69030430', - } - trackingmore.airWaybills.createAnAirWayBill(params) - .then(result => console.log(result)) - .catch(e => console.log(e)) -} catch (error) { - console.error('An error occurred:', error.message) -} \ No newline at end of file +// try { +// // Create an air waybill (awb) +// const params = { +// 'awb_number': '235-69030430', +// } +// trackingmore.airWaybills.createAnAirWayBill(params) +// .then(result => console.log(result)) +// .catch(e => console.log(e)) +// } catch (error) { +// console.error('An error occurred:', error.message) +// } \ No newline at end of file diff --git a/src/tracking/airWaybills.js b/src/tracking/airWaybills.js index 981fbd9..155651a 100644 --- a/src/tracking/airWaybills.js +++ b/src/tracking/airWaybills.js @@ -14,8 +14,8 @@ class AirWaybills { if (!params.awb_number) { throw new Error('Awb number cannot be empty') } - if (params.awb_number.length != 12) { - throw new Error('The air waybill number format is invalid and can only be 12 digits in length') + if (!/^\d{3}[ -]?(\d{8})$/.test(params.awb_number)) { + throw new Error('The air waybill number format is invalid') } const apiPath = 'awb' const response = Request.sendApiRequest(this.apiModule + '/' + apiPath, this.apiKey, 'POST', params)