Skip to content

Commit 8514685

Browse files
committed
Modify the format of the air waybill number
1 parent 1f4ced7 commit 8514685

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

__tests__/airWaybills.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe('AirWaybills', () => {
2727
const apiKey = 'your-api-key';
2828
const airWaybills = new AirWaybills(apiKey);
2929

30-
expect(() => airWaybills.createAnAirWayBill({awb_number: '123456'})).toThrow('The air waybill number format is invalid and can only be 12 digits in length');
30+
expect(() => airWaybills.createAnAirWayBill({awb_number: '123456'})).toThrow('The air waybill number format is invalid');
3131
});
3232

3333
it('should send a POST request to /awb with awb_number', () => {

example/example.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ const key = 'you api key'
44
const trackingmore = new TrackingMore(key)
55

66

7-
// try {
8-
// // Get all couriers (couriers/all)
9-
// trackingmore.couriers.getAllCouriers()
10-
// .then(result => console.log(result))
11-
// .catch(e => console.log(e))
12-
// } catch (error) {
13-
// console.error('An error occurred:', error.message)
14-
// }
7+
try {
8+
// Get all couriers (couriers/all)
9+
trackingmore.couriers.getAllCouriers()
10+
.then(result => console.log(result))
11+
.catch(e => console.log(e))
12+
} catch (error) {
13+
console.error('An error occurred:', error.message)
14+
}
1515

1616

1717
// try {
@@ -118,14 +118,14 @@ const trackingmore = new TrackingMore(key)
118118
// console.error('An error occurred:', error.message)
119119
// }
120120

121-
try {
122-
// Create an air waybill (awb)
123-
const params = {
124-
'awb_number': '235-69030430',
125-
}
126-
trackingmore.airWaybills.createAnAirWayBill(params)
127-
.then(result => console.log(result))
128-
.catch(e => console.log(e))
129-
} catch (error) {
130-
console.error('An error occurred:', error.message)
131-
}
121+
// try {
122+
// // Create an air waybill (awb)
123+
// const params = {
124+
// 'awb_number': '235-69030430',
125+
// }
126+
// trackingmore.airWaybills.createAnAirWayBill(params)
127+
// .then(result => console.log(result))
128+
// .catch(e => console.log(e))
129+
// } catch (error) {
130+
// console.error('An error occurred:', error.message)
131+
// }

src/tracking/airWaybills.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ class AirWaybills {
1414
if (!params.awb_number) {
1515
throw new Error('Awb number cannot be empty')
1616
}
17-
if (params.awb_number.length != 12) {
18-
throw new Error('The air waybill number format is invalid and can only be 12 digits in length')
17+
if (!/^\d{3}[ -]?(\d{8})$/.test(params.awb_number)) {
18+
throw new Error('The air waybill number format is invalid')
1919
}
2020
const apiPath = 'awb'
2121
const response = Request.sendApiRequest(this.apiModule + '/' + apiPath, this.apiKey, 'POST', params)

0 commit comments

Comments
 (0)