ti2-tourplan 1.0.126 → 1.0.128
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.test.js +140 -0
- package/itinerary-add-service.js +9 -1
- package/itinerary-products-search.js +9 -2
- package/package.json +1 -1
package/index.test.js
CHANGED
|
@@ -132,6 +132,84 @@ describe('search tests', () => {
|
|
|
132
132
|
}
|
|
133
133
|
});
|
|
134
134
|
});
|
|
135
|
+
describe('addServiceToItinerary', () => {
|
|
136
|
+
it('limits new booking names after escaping XML characters', async () => {
|
|
137
|
+
mockCallTourplan.mockImplementationOnce(async () => ({
|
|
138
|
+
AddServiceReply: {
|
|
139
|
+
BookingId: '12345',
|
|
140
|
+
Ref: 'TESTREF',
|
|
141
|
+
Services: {
|
|
142
|
+
Service: {
|
|
143
|
+
LinePrice: '10.00',
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
ServiceLineId: '10',
|
|
147
|
+
},
|
|
148
|
+
}));
|
|
149
|
+
|
|
150
|
+
const quoteName = 'Ä'.repeat(30);
|
|
151
|
+
await app.addServiceToItinerary({
|
|
152
|
+
axios,
|
|
153
|
+
token,
|
|
154
|
+
payload: {
|
|
155
|
+
quoteName,
|
|
156
|
+
optionId: 'ABC123',
|
|
157
|
+
startDate: '2026-07-03',
|
|
158
|
+
reference: 'TESTREF',
|
|
159
|
+
paxConfigs: [{ roomType: 'Double', adults: 2 }],
|
|
160
|
+
notes: '',
|
|
161
|
+
},
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
expect(mockCallTourplan).toHaveBeenCalledTimes(1);
|
|
165
|
+
const newBookingName = mockCallTourplan.mock.calls[0][0]
|
|
166
|
+
.model.AddServiceRequest.NewBookingInfo.Name;
|
|
167
|
+
|
|
168
|
+
expect(newBookingName.length).toBe(59);
|
|
169
|
+
expect(newBookingName).toBe(`${'Ae'.repeat(29)}A`);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it('limits new booking names supplied by directHeaderPayload after escaping XML characters', async () => {
|
|
173
|
+
mockCallTourplan.mockImplementationOnce(async () => ({
|
|
174
|
+
AddServiceReply: {
|
|
175
|
+
BookingId: '12345',
|
|
176
|
+
Ref: 'TESTREF',
|
|
177
|
+
Services: {
|
|
178
|
+
Service: {
|
|
179
|
+
LinePrice: '10.00',
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
ServiceLineId: '10',
|
|
183
|
+
},
|
|
184
|
+
}));
|
|
185
|
+
|
|
186
|
+
await app.addServiceToItinerary({
|
|
187
|
+
axios,
|
|
188
|
+
token,
|
|
189
|
+
payload: {
|
|
190
|
+
quoteName: 'Short quote name',
|
|
191
|
+
optionId: 'ABC123',
|
|
192
|
+
startDate: '2026-07-03',
|
|
193
|
+
reference: 'TESTREF',
|
|
194
|
+
paxConfigs: [{ roomType: 'Double', adults: 2 }],
|
|
195
|
+
notes: '',
|
|
196
|
+
directHeaderPayload: {
|
|
197
|
+
Name: 'Ä'.repeat(30),
|
|
198
|
+
HeaderField: 'kept',
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
expect(mockCallTourplan).toHaveBeenCalledTimes(1);
|
|
204
|
+
const newBookingInfo = mockCallTourplan.mock.calls[0][0]
|
|
205
|
+
.model.AddServiceRequest.NewBookingInfo;
|
|
206
|
+
|
|
207
|
+
expect(newBookingInfo.Name.length).toBe(59);
|
|
208
|
+
expect(newBookingInfo.Name).toBe(`${'Ae'.repeat(29)}A`);
|
|
209
|
+
expect(newBookingInfo.HeaderField).toBe('kept');
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
|
|
135
213
|
describe('cancelBooking', () => {
|
|
136
214
|
it('cancels a booking by id', async () => {
|
|
137
215
|
mockCallTourplan.mockImplementationOnce(async () => ({
|
|
@@ -721,6 +799,68 @@ describe('search tests', () => {
|
|
|
721
799
|
expect(retVal).toMatchSnapshot();
|
|
722
800
|
});
|
|
723
801
|
|
|
802
|
+
it('searchProductsForItinerary skips AC in full catalog when skipAccommodation is set', async () => {
|
|
803
|
+
const debugSpy = jest.spyOn(console, 'debug').mockImplementation(() => {});
|
|
804
|
+
const bdOption = {
|
|
805
|
+
Opt: 'TESTBDOPTION00001',
|
|
806
|
+
OptGeneral: {
|
|
807
|
+
SupplierId: '1001',
|
|
808
|
+
SupplierName: 'Test Supplier',
|
|
809
|
+
Description: 'Test BD Product',
|
|
810
|
+
SType: 'N',
|
|
811
|
+
AdultsAllowed: 'Y',
|
|
812
|
+
Adult_From: 16,
|
|
813
|
+
Adult_To: 999,
|
|
814
|
+
ButtonName: 'Sightseeing',
|
|
815
|
+
},
|
|
816
|
+
};
|
|
817
|
+
|
|
818
|
+
mockCallTourplan
|
|
819
|
+
.mockImplementationOnce(async () => ({
|
|
820
|
+
GetServicesReply: {
|
|
821
|
+
TPLServices: {
|
|
822
|
+
TPLService: [
|
|
823
|
+
{ Code: 'AC', Name: 'Accommodation' },
|
|
824
|
+
{ Code: 'BD', Name: 'Bundle' },
|
|
825
|
+
],
|
|
826
|
+
},
|
|
827
|
+
},
|
|
828
|
+
}))
|
|
829
|
+
.mockImplementationOnce(async ({ model }) => {
|
|
830
|
+
const opt = model.OptionInfoRequest.Opt;
|
|
831
|
+
if (opt === '???AC????????????') {
|
|
832
|
+
throw new Error('AC OptionInfo should have been skipped');
|
|
833
|
+
}
|
|
834
|
+
if (opt === '???BD????????????') {
|
|
835
|
+
return { OptionInfoReply: { Option: bdOption } };
|
|
836
|
+
}
|
|
837
|
+
throw new Error(`Unexpected OptionInfo Opt: ${opt}`);
|
|
838
|
+
});
|
|
839
|
+
|
|
840
|
+
const retVal = await app.searchProductsForItinerary({
|
|
841
|
+
axios,
|
|
842
|
+
token,
|
|
843
|
+
typeDefsAndQueries,
|
|
844
|
+
payload: {
|
|
845
|
+
searchInput: '',
|
|
846
|
+
skipAccommodation: true,
|
|
847
|
+
},
|
|
848
|
+
});
|
|
849
|
+
|
|
850
|
+
const optionInfoCalls = mockCallTourplan.mock.calls
|
|
851
|
+
.map(([call]) => call.model.OptionInfoRequest)
|
|
852
|
+
.filter(Boolean);
|
|
853
|
+
expect(optionInfoCalls).toHaveLength(1);
|
|
854
|
+
expect(optionInfoCalls[0].Opt).toBe('???BD????????????');
|
|
855
|
+
expect(debugSpy).toHaveBeenCalledWith(
|
|
856
|
+
'[tourplan] Accommodation (AC) service code will be skipped in full catalog product search',
|
|
857
|
+
);
|
|
858
|
+
expect(retVal.products).toHaveLength(1);
|
|
859
|
+
expect(retVal.products[0].options[0].optionId).toBe('TESTBDOPTION00001');
|
|
860
|
+
|
|
861
|
+
debugSpy.mockRestore();
|
|
862
|
+
});
|
|
863
|
+
|
|
724
864
|
describe('availability tests', () => {
|
|
725
865
|
it('searchAvailabilityForItinerary - not bookable', async () => {
|
|
726
866
|
axios.mockImplementation(getFixture);
|
package/itinerary-add-service.js
CHANGED
|
@@ -8,8 +8,12 @@ const {
|
|
|
8
8
|
} = require('./utils');
|
|
9
9
|
|
|
10
10
|
const DEFAULT_TOURPLAN_SERVICE_STATUS = 'IR';
|
|
11
|
+
const MAX_BOOKING_NAME_LENGTH = 59;
|
|
11
12
|
const SERVICE_CANNOT_BE_ADDED_ERROR_MESSAGE = 'Service cannot be added to quote for the requested date/stay. (e.g. no rates, block out period, on request, minimum stay etc.)';
|
|
12
13
|
|
|
14
|
+
const getBookingName = quoteName => escapeInvalidXmlChars(quoteName)
|
|
15
|
+
.substring(0, MAX_BOOKING_NAME_LENGTH);
|
|
16
|
+
|
|
13
17
|
const addServiceToItinerary = async ({
|
|
14
18
|
axios,
|
|
15
19
|
token: {
|
|
@@ -61,6 +65,10 @@ const addServiceToItinerary = async ({
|
|
|
61
65
|
return acc;
|
|
62
66
|
}, {});
|
|
63
67
|
|
|
68
|
+
const directHeaderPayloadHasName = directHeaderPayload &&
|
|
69
|
+
Object.prototype.hasOwnProperty.call(directHeaderPayload, 'Name');
|
|
70
|
+
const bookingNameSource = directHeaderPayloadHasName ? directHeaderPayload.Name : quoteName;
|
|
71
|
+
|
|
64
72
|
const rateIdFromAvailCheckObj = R.path(['rateId'], availCheckObj);
|
|
65
73
|
if (availCheckObj &&
|
|
66
74
|
(rateIdFromAvailCheckObj === CUSTOM_RATE_ID_NAME
|
|
@@ -141,9 +149,9 @@ const addServiceToItinerary = async ({
|
|
|
141
149
|
ExistingBookingInfo: { BookingId: quoteId },
|
|
142
150
|
} : {
|
|
143
151
|
NewBookingInfo: {
|
|
144
|
-
Name: escapeInvalidXmlChars(quoteName),
|
|
145
152
|
QB: QB || 'Q',
|
|
146
153
|
...(directHeaderPayload || {}),
|
|
154
|
+
Name: getBookingName(bookingNameSource),
|
|
147
155
|
},
|
|
148
156
|
}),
|
|
149
157
|
...(puTime ? { puTime } : {}),
|
|
@@ -22,6 +22,8 @@ const searchProductsForItinerary = async ({
|
|
|
22
22
|
// lastUpdatedFrom is used to get options that were updated after a certain date in Tourplan
|
|
23
23
|
// example: lastUpdatedFrom: '2024-04-22 05:17:57.427Z'
|
|
24
24
|
lastUpdatedFrom,
|
|
25
|
+
// skip Accommodation (AC) service code in full catalog search
|
|
26
|
+
skipAccommodation,
|
|
25
27
|
},
|
|
26
28
|
callTourplan,
|
|
27
29
|
}) => {
|
|
@@ -58,7 +60,7 @@ const searchProductsForItinerary = async ({
|
|
|
58
60
|
/*
|
|
59
61
|
Full catalog path:
|
|
60
62
|
1. getServiceCodes -> [AC, BD]
|
|
61
|
-
2. for each serviceCode getoptions
|
|
63
|
+
2. for each serviceCode getoptions (optionally skip AC when skipAccommodation is set)
|
|
62
64
|
3. convert them to ti2 products structure
|
|
63
65
|
4. merge all products from all serviceCodes
|
|
64
66
|
*/
|
|
@@ -77,7 +79,12 @@ const searchProductsForItinerary = async ({
|
|
|
77
79
|
});
|
|
78
80
|
let serviceCodes = R.pathOr([], ['GetServicesReply', 'TPLServices', 'TPLService'], getServicesReply);
|
|
79
81
|
if (!Array.isArray(serviceCodes)) serviceCodes = [serviceCodes];
|
|
80
|
-
|
|
82
|
+
if (skipAccommodation) {
|
|
83
|
+
console.debug('[tourplan] Accommodation (AC) service code will be skipped in full catalog product search');
|
|
84
|
+
}
|
|
85
|
+
serviceCodes = serviceCodes
|
|
86
|
+
.map(s => s.Code)
|
|
87
|
+
.filter(code => !(skipAccommodation && code === 'AC'));
|
|
81
88
|
await Promise.each(serviceCodes, async serviceCode => {
|
|
82
89
|
const getOptionsModel = {
|
|
83
90
|
OptionInfoRequest: {
|