ti2-tourplan 1.0.125 → 1.0.127

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.
@@ -0,0 +1,10 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "Bash(gh pr diff:*)",
5
+ "Bash(gh pr view:*)"
6
+ ],
7
+ "deny": [],
8
+ "ask": []
9
+ }
10
+ }
@@ -172,7 +172,7 @@ const getAvailabilityOnly = async ({
172
172
  const model = {
173
173
  OptionInfoRequest: {
174
174
  Opt: optionId,
175
- Info: 'AD',
175
+ Info: 'GAR',
176
176
  AgentID: hostConnectAgentID,
177
177
  Password: hostConnectAgentPassword,
178
178
  DateFrom: startDate,
@@ -186,7 +186,11 @@ const getAvailabilityOnly = async ({
186
186
  axios,
187
187
  xmlOptions: hostConnectXmlOptions,
188
188
  });
189
- return R.pathOr([], ['OptionInfoReply', 'Option', 'OptAvail'], replyObj);
189
+ const option = R.path(['OptionInfoReply', 'Option'], replyObj);
190
+ return {
191
+ optAvail: R.pathOr([], ['OptAvail'], option),
192
+ optRates: R.path(['OptRates'], option),
193
+ };
190
194
  };
191
195
  /*
192
196
  Get general option information from Tourplan API.
@@ -152,7 +152,7 @@ const searchAvailabilityForItinerary = async ({
152
152
  const isAvailabilityOnly = availabilityOnly === true;
153
153
 
154
154
  if (isAvailabilityOnly) {
155
- const availabilityOnlyResponse = await getAvailabilityOnly({
155
+ const { optAvail, optRates } = await getAvailabilityOnly({
156
156
  optionId,
157
157
  hostConnectEndpoint,
158
158
  hostConnectAgentID,
@@ -162,8 +162,9 @@ const searchAvailabilityForItinerary = async ({
162
162
  requestedEndDate,
163
163
  callTourplan,
164
164
  });
165
- const optAvailValues = getOptAvailValues(availabilityOnlyResponse);
165
+ const optAvailValues = getOptAvailValues(optAvail);
166
166
  const SCheckPass = isOptAvailBookable(optAvailValues);
167
+ const rates = (SCheckPass && optRates) ? [optRates] : [];
167
168
  return {
168
169
  bookable: SCheckPass,
169
170
  type: 'availability',
@@ -172,7 +173,7 @@ const searchAvailabilityForItinerary = async ({
172
173
  ? 'Availability checked successfully'
173
174
  : 'No availability found for the requested range',
174
175
  availability: optAvailValues,
175
- rates: [],
176
+ rates,
176
177
  };
177
178
  }
178
179
 
@@ -24,7 +24,7 @@ jest.mock('./itinerary-availability-helper', () => ({
24
24
  maxPaxPerCharge: null,
25
25
  })),
26
26
  getNoRatesAvailableError: jest.fn(async () => 'No rates available'),
27
- getAvailabilityOnly: jest.fn(async () => '-1 -1 -1'),
27
+ getAvailabilityOnly: jest.fn(async () => ({ optAvail: '-1 -1 -1', optRates: null })),
28
28
  getStayResults: jest.fn(async () => ([{
29
29
  RateId: 'R1',
30
30
  Currency: 'USD',
@@ -149,7 +149,18 @@ describe('searchAvailabilityForItinerary validation flags', () => {
149
149
  });
150
150
 
151
151
  it('uses availabilityOnly flow and keeps response shape consistent', async () => {
152
- itineraryAvailabilityHelper.getAvailabilityOnly.mockResolvedValueOnce('-1 -2 -1');
152
+ const mockOptRates = {
153
+ Currency: 'JPY',
154
+ OptRate: {
155
+ Date: '2026-06-01',
156
+ RateName: '26年',
157
+ PersonRates: { AdultRate: 2700000, ChildRate: 1700000 },
158
+ },
159
+ };
160
+ itineraryAvailabilityHelper.getAvailabilityOnly.mockResolvedValueOnce({
161
+ optAvail: '-1 -2 -1',
162
+ optRates: mockOptRates,
163
+ });
153
164
 
154
165
  const result = await searchAvailabilityForItinerary({
155
166
  axios: jest.fn(),
@@ -160,6 +171,7 @@ describe('searchAvailabilityForItinerary validation flags', () => {
160
171
  });
161
172
 
162
173
  expect(itineraryAvailabilityHelper.getAvailabilityOnly).toHaveBeenCalledTimes(1);
174
+ expect(itineraryAvailabilityHelper.getStayResults).not.toHaveBeenCalled();
163
175
  expect(itineraryAvailabilityHelper.getAgentCurrencyCode).not.toHaveBeenCalled();
164
176
  expect(result).toEqual({
165
177
  bookable: true,
@@ -167,12 +179,15 @@ describe('searchAvailabilityForItinerary validation flags', () => {
167
179
  endDate: '2025-04-05',
168
180
  message: 'Availability checked successfully',
169
181
  availability: [-1, -2, -1],
170
- rates: [],
182
+ rates: [mockOptRates],
171
183
  });
172
184
  });
173
185
 
174
186
  it('marks availabilityOnly response as not bookable when all days are unavailable', async () => {
175
- itineraryAvailabilityHelper.getAvailabilityOnly.mockResolvedValueOnce('-1 -1 -1');
187
+ itineraryAvailabilityHelper.getAvailabilityOnly.mockResolvedValueOnce({
188
+ optAvail: '-1 -1 -1',
189
+ optRates: null,
190
+ });
176
191
 
177
192
  const result = await searchAvailabilityForItinerary({
178
193
  axios: jest.fn(),
@@ -186,5 +201,6 @@ describe('searchAvailabilityForItinerary validation flags', () => {
186
201
  expect(result.message).toBe('No availability found for the requested range');
187
202
  expect(result.availability).toEqual([-1, -1, -1]);
188
203
  expect(result.rates).toEqual([]);
204
+ expect(itineraryAvailabilityHelper.getStayResults).not.toHaveBeenCalled();
189
205
  });
190
206
  });
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 () => ({
@@ -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 } : {}),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ti2-tourplan",
3
- "version": "1.0.125",
3
+ "version": "1.0.127",
4
4
  "description": "Tourplan's TI2 Plugin",
5
5
  "main": "index.js",
6
6
  "scripts": {