Skip to content

Commit

Permalink
Modify the format of the air waybill number
Browse files Browse the repository at this point in the history
  • Loading branch information
liaohanfei committed Nov 3, 2023
1 parent 1f4ced7 commit 8514685
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion __tests__/airWaybills.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
38 changes: 19 additions & 19 deletions example/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
// 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)
// }
4 changes: 2 additions & 2 deletions src/tracking/airWaybills.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8514685

Please sign in to comment.