@dotdev/harmony-sdk 1.0.6

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.
Files changed (124) hide show
  1. package/README.md +88 -0
  2. package/dist/HarmonyAPI.d.ts +37 -0
  3. package/dist/HarmonyAPI.js +113 -0
  4. package/dist/errors/index.d.ts +15 -0
  5. package/dist/errors/index.js +18 -0
  6. package/dist/helpers/index.d.ts +50 -0
  7. package/dist/helpers/index.js +167 -0
  8. package/dist/helpers/index.spec.d.ts +1 -0
  9. package/dist/helpers/index.spec.js +147 -0
  10. package/dist/helpers/mapper.d.ts +2 -0
  11. package/dist/helpers/mapper.js +28 -0
  12. package/dist/helpers/utils.d.ts +71 -0
  13. package/dist/helpers/utils.js +133 -0
  14. package/dist/helpers/utils.spec.d.ts +1 -0
  15. package/dist/helpers/utils.spec.js +96 -0
  16. package/dist/index.d.ts +5 -0
  17. package/dist/index.js +5 -0
  18. package/dist/modules/auth/auth.module.d.ts +7 -0
  19. package/dist/modules/auth/auth.module.js +42 -0
  20. package/dist/modules/auth/auth.module.spec.d.ts +1 -0
  21. package/dist/modules/auth/auth.module.spec.js +55 -0
  22. package/dist/modules/auth/index.d.ts +2 -0
  23. package/dist/modules/auth/index.js +2 -0
  24. package/dist/modules/auth/types/index.d.ts +7 -0
  25. package/dist/modules/auth/types/index.js +1 -0
  26. package/dist/modules/carrier/carrier.module.d.ts +10 -0
  27. package/dist/modules/carrier/carrier.module.js +39 -0
  28. package/dist/modules/carrier/carrier.module.spec.d.ts +1 -0
  29. package/dist/modules/carrier/carrier.module.spec.js +187 -0
  30. package/dist/modules/carrier/index.d.ts +3 -0
  31. package/dist/modules/carrier/index.js +3 -0
  32. package/dist/modules/carrier/mappings/index.d.ts +5 -0
  33. package/dist/modules/carrier/mappings/index.js +36 -0
  34. package/dist/modules/carrier/types/index.d.ts +42 -0
  35. package/dist/modules/carrier/types/index.js +2 -0
  36. package/dist/modules/diary/diary.module.d.ts +9 -0
  37. package/dist/modules/diary/diary.module.js +28 -0
  38. package/dist/modules/diary/index.d.ts +3 -0
  39. package/dist/modules/diary/index.js +3 -0
  40. package/dist/modules/diary/mappings/diary.mapper.d.ts +4 -0
  41. package/dist/modules/diary/mappings/diary.mapper.js +101 -0
  42. package/dist/modules/diary/mappings/diary.mapper.spec.d.ts +1 -0
  43. package/dist/modules/diary/mappings/diary.mapper.spec.js +18 -0
  44. package/dist/modules/diary/mappings/index.d.ts +1 -0
  45. package/dist/modules/diary/mappings/index.js +1 -0
  46. package/dist/modules/diary/types/diary.interface.d.ts +138 -0
  47. package/dist/modules/diary/types/diary.interface.js +24 -0
  48. package/dist/modules/diary/types/index.d.ts +1 -0
  49. package/dist/modules/diary/types/index.js +1 -0
  50. package/dist/modules/gift-voucher/gift-voucher.module.d.ts +12 -0
  51. package/dist/modules/gift-voucher/gift-voucher.module.js +55 -0
  52. package/dist/modules/gift-voucher/gift-voucher.module.spec.d.ts +1 -0
  53. package/dist/modules/gift-voucher/gift-voucher.module.spec.js +296 -0
  54. package/dist/modules/gift-voucher/index.d.ts +1 -0
  55. package/dist/modules/gift-voucher/index.js +1 -0
  56. package/dist/modules/gift-voucher/mappings/index.d.ts +6 -0
  57. package/dist/modules/gift-voucher/mappings/index.js +70 -0
  58. package/dist/modules/gift-voucher/mappings/index.spec.d.ts +1 -0
  59. package/dist/modules/gift-voucher/mappings/index.spec.js +21 -0
  60. package/dist/modules/gift-voucher/types/index.d.ts +92 -0
  61. package/dist/modules/gift-voucher/types/index.js +1 -0
  62. package/dist/modules/index.d.ts +8 -0
  63. package/dist/modules/index.js +8 -0
  64. package/dist/modules/point-of-sale/index.d.ts +3 -0
  65. package/dist/modules/point-of-sale/index.js +3 -0
  66. package/dist/modules/point-of-sale/mappings/index.d.ts +1 -0
  67. package/dist/modules/point-of-sale/mappings/index.js +1 -0
  68. package/dist/modules/point-of-sale/mappings/process-sale-order.mapper.d.ts +6 -0
  69. package/dist/modules/point-of-sale/mappings/process-sale-order.mapper.js +142 -0
  70. package/dist/modules/point-of-sale/point-of-sale.module.d.ts +43 -0
  71. package/dist/modules/point-of-sale/point-of-sale.module.js +64 -0
  72. package/dist/modules/point-of-sale/point-of-sale.module.spec.d.ts +1 -0
  73. package/dist/modules/point-of-sale/point-of-sale.module.spec.js +205 -0
  74. package/dist/modules/point-of-sale/types/cancel-existing-sales-order.interface.d.ts +13 -0
  75. package/dist/modules/point-of-sale/types/cancel-existing-sales-order.interface.js +1 -0
  76. package/dist/modules/point-of-sale/types/index.d.ts +124 -0
  77. package/dist/modules/point-of-sale/types/index.js +31 -0
  78. package/dist/modules/point-of-sale/types/modify-existing-sales-order.interface.d.ts +12 -0
  79. package/dist/modules/point-of-sale/types/modify-existing-sales-order.interface.js +1 -0
  80. package/dist/modules/point-of-sale/types/process-returns.interface.d.ts +17 -0
  81. package/dist/modules/point-of-sale/types/process-returns.interface.js +1 -0
  82. package/dist/modules/point-of-sale/types/process-sale-order.interface.d.ts +67 -0
  83. package/dist/modules/point-of-sale/types/process-sale-order.interface.js +1 -0
  84. package/dist/modules/shared/index.d.ts +1 -0
  85. package/dist/modules/shared/index.js +1 -0
  86. package/dist/modules/shared/types/index.d.ts +93 -0
  87. package/dist/modules/shared/types/index.js +53 -0
  88. package/dist/modules/stock-level-lookup/index.d.ts +3 -0
  89. package/dist/modules/stock-level-lookup/index.js +3 -0
  90. package/dist/modules/stock-level-lookup/mappings/index.d.ts +1 -0
  91. package/dist/modules/stock-level-lookup/mappings/index.js +1 -0
  92. package/dist/modules/stock-level-lookup/mappings/stock-level-lookup.mapper.d.ts +4 -0
  93. package/dist/modules/stock-level-lookup/mappings/stock-level-lookup.mapper.js +78 -0
  94. package/dist/modules/stock-level-lookup/mappings/stock-level-lookup.mapper.spec.d.ts +1 -0
  95. package/dist/modules/stock-level-lookup/mappings/stock-level-lookup.mapper.spec.js +57 -0
  96. package/dist/modules/stock-level-lookup/stock-level-lookup.module.d.ts +10 -0
  97. package/dist/modules/stock-level-lookup/stock-level-lookup.module.js +39 -0
  98. package/dist/modules/stock-level-lookup/stock-level-lookup.module.spec.d.ts +1 -0
  99. package/dist/modules/stock-level-lookup/stock-level-lookup.module.spec.js +317 -0
  100. package/dist/modules/stock-level-lookup/types/index.d.ts +1 -0
  101. package/dist/modules/stock-level-lookup/types/index.js +1 -0
  102. package/dist/modules/stock-level-lookup/types/stock-level-lookup.interface.d.ts +162 -0
  103. package/dist/modules/stock-level-lookup/types/stock-level-lookup.interface.js +61 -0
  104. package/dist/modules/stock-lookup/index.d.ts +3 -0
  105. package/dist/modules/stock-lookup/index.js +3 -0
  106. package/dist/modules/stock-lookup/mappings/index.d.ts +1 -0
  107. package/dist/modules/stock-lookup/mappings/index.js +1 -0
  108. package/dist/modules/stock-lookup/mappings/stock-lookup.mapper.d.ts +22 -0
  109. package/dist/modules/stock-lookup/mappings/stock-lookup.mapper.js +156 -0
  110. package/dist/modules/stock-lookup/mappings/stock-lookup.mapper.spec.d.ts +1 -0
  111. package/dist/modules/stock-lookup/mappings/stock-lookup.mapper.spec.js +92 -0
  112. package/dist/modules/stock-lookup/stock-lookup.module.d.ts +65 -0
  113. package/dist/modules/stock-lookup/stock-lookup.module.js +141 -0
  114. package/dist/modules/stock-lookup/stock-lookup.module.spec.d.ts +1 -0
  115. package/dist/modules/stock-lookup/stock-lookup.module.spec.js +419 -0
  116. package/dist/modules/stock-lookup/types/index.d.ts +1 -0
  117. package/dist/modules/stock-lookup/types/index.js +1 -0
  118. package/dist/modules/stock-lookup/types/stock-lookup.interface.d.ts +242 -0
  119. package/dist/modules/stock-lookup/types/stock-lookup.interface.js +82 -0
  120. package/dist/modules/stock-lookup/types/stock-lookup.interface.spec.d.ts +1 -0
  121. package/dist/modules/stock-lookup/types/stock-lookup.interface.spec.js +76 -0
  122. package/dist/types/index.d.ts +5 -0
  123. package/dist/types/index.js +6 -0
  124. package/package.json +39 -0
@@ -0,0 +1,55 @@
1
+ import { ApiHelper, Utils } from "../../helpers";
2
+ import { ServiceAlias } from "../shared";
3
+ import { mapGiftVoucher, mapGiftVoucherQueryParams, mapGiftVoucherReservationCancelQueryParams, mapGiftVoucherReservationQueryParams, mapGiftVoucherUsedQueryParams, } from "./mappings";
4
+ export class GiftVoucherModule {
5
+ axiosInstance;
6
+ SERVICE_URL = `GiftVoucherService/GiftVoucherService`;
7
+ constructor(axiosInstance) {
8
+ this.axiosInstance = axiosInstance;
9
+ }
10
+ async giftVoucherLookup(params, sessionId) {
11
+ try {
12
+ const response = await ApiHelper.sendServiceRequest(this.SERVICE_URL, `GiftVoucherLookup`, sessionId, ServiceAlias.GIFT_VOUCHER, this.axiosInstance, mapGiftVoucherQueryParams(params));
13
+ return response?.giftvoucherDetails?.map(mapGiftVoucher);
14
+ }
15
+ catch (error) {
16
+ throw await ApiHelper.parseError(error);
17
+ }
18
+ }
19
+ async giftVoucherVerificationKey(params, sessionId) {
20
+ try {
21
+ const response = await ApiHelper.sendServiceRequest(this.SERVICE_URL, `GiftVoucherVerificationKey`, sessionId, ServiceAlias.GIFT_VOUCHER, this.axiosInstance, mapGiftVoucherQueryParams(params));
22
+ return (response?.verification_key ?? [])[0];
23
+ }
24
+ catch (error) {
25
+ throw await ApiHelper.parseError(error);
26
+ }
27
+ }
28
+ async giftVoucherReservation(params, sessionId) {
29
+ try {
30
+ const response = await ApiHelper.sendServiceRequest(this.SERVICE_URL, `GiftVoucherReservation`, sessionId, ServiceAlias.GIFT_VOUCHER, this.axiosInstance, mapGiftVoucherReservationQueryParams(params));
31
+ return (response?.reservation_key ?? [])[0];
32
+ }
33
+ catch (error) {
34
+ throw await ApiHelper.parseError(error);
35
+ }
36
+ }
37
+ async giftVoucherReservationCancel(params, sessionId) {
38
+ try {
39
+ const response = await ApiHelper.sendServiceRequest(this.SERVICE_URL, `GiftVoucherReservationCancel`, sessionId, ServiceAlias.GIFT_VOUCHER, this.axiosInstance, mapGiftVoucherReservationCancelQueryParams(params));
40
+ return Boolean(response?.result[0]);
41
+ }
42
+ catch (error) {
43
+ throw await ApiHelper.parseError(error);
44
+ }
45
+ }
46
+ async giftVoucherUsed(params, sessionId) {
47
+ try {
48
+ const response = await ApiHelper.sendServiceRequest(this.SERVICE_URL, `GiftVoucherUsed`, sessionId, ServiceAlias.GIFT_VOUCHER, this.axiosInstance, mapGiftVoucherUsedQueryParams(params));
49
+ return Utils.toNumber((response?.reservation_history_no ?? [])[0]);
50
+ }
51
+ catch (error) {
52
+ throw await ApiHelper.parseError(error);
53
+ }
54
+ }
55
+ }
@@ -0,0 +1,296 @@
1
+ import axios from "axios";
2
+ import { ApiHelper, Utils } from "../../helpers";
3
+ import { ServiceAlias } from "../shared";
4
+ import { GiftVoucherModule } from "./gift-voucher.module";
5
+ jest.mock("axios");
6
+ const mAxios = axios;
7
+ describe("GiftVoucherModule", () => {
8
+ let gvModule;
9
+ let mockApiHelperSendRequest;
10
+ beforeAll(() => {
11
+ gvModule = new GiftVoucherModule(mAxios);
12
+ mockApiHelperSendRequest = jest.spyOn(ApiHelper, "sendSoapRequest");
13
+ });
14
+ it("giftVoucherLookup() should send correct request payload and parse the respone correctly", async () => {
15
+ const token = "test-token";
16
+ const ns = "S";
17
+ const params = {
18
+ stock: `GIFTVCHR-CLOTH ALLOW`,
19
+ serialNo: `40089`,
20
+ };
21
+ const expectedPayload = `
22
+ <${ns}:Envelope xmlns:${ns}="http://schemas.xmlsoap.org/soap/envelope/" xmlns:${ServiceAlias.GIFT_VOUCHER}="http://${ServiceAlias.GIFT_VOUCHER}.ws.fbsaust.com.au">
23
+ <${ns}:Header>
24
+ <${ServiceAlias.GIFT_VOUCHER}:SessionId>${token}</${ServiceAlias.GIFT_VOUCHER}:SessionId>
25
+ </${ns}:Header>
26
+ <${ns}:Body>
27
+ <${ServiceAlias.GIFT_VOUCHER}:GiftVoucherLookup>
28
+ <giftvoucher>
29
+ <stock>GIFTVCHR-CLOTH ALLOW</stock>
30
+ <serial_no>40089</serial_no>
31
+ </giftvoucher>
32
+ </${ServiceAlias.GIFT_VOUCHER}:GiftVoucherLookup>
33
+ </${ns}:Body>
34
+ </${ns}:Envelope>
35
+ `;
36
+ const mockedResp = `
37
+ <?xml version='1.0' encoding='UTF-8'?>
38
+ <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
39
+ <S:Body><ns2:GiftVoucherLookupResponse xmlns:ns2="http://gv.ws.fbsaust.com.au">
40
+ <giftvoucherDetails>
41
+ <stock>GIFTVCHR-CLOTH ALLOW</stock>
42
+ <serial_no>4008</serial_no>
43
+ <sales_code>#MGV</sales_code>
44
+ <sale_date>14-11-2011</sale_date>
45
+ <sale_warehouse>4AR</sale_warehouse>
46
+ <sale_reference>BRITTANY</sale_reference>
47
+ <sale_agent>1</sale_agent>
48
+ <redeem_date>05-06-2012</redeem_date>
49
+ <redeem_warehouse>4AR</redeem_warehouse>
50
+ <redeem_reference>P4AR002626</redeem_reference>
51
+ <redeem_agent>4008</redeem_agent>
52
+ <expiry_date>30-11-2012</expiry_date>
53
+ <stk_gl_account>LAGVS20004</stk_gl_account>
54
+ <last_used_date>02-11-2012</last_used_date>
55
+ <opening_amount>30.0</opening_amount>
56
+ <amount>30.0</amount>
57
+ <balance>30.0</balance>
58
+ <reservation_used>0.0</reservation_used>
59
+ <comment_1></comment_1>
60
+ <diary></diary>
61
+ <name_1>PRINCE</name_1>
62
+ <name_2>BRITTANY</name_2>
63
+ <address_1></address_1>
64
+ <address_2></address_2>
65
+ <address_3></address_3>
66
+ <address_4></address_4>
67
+ <postcode></postcode>
68
+ <email></email>
69
+ <telephone_1></telephone_1>
70
+ <country_code></country_code>
71
+ <currency></currency>
72
+ </giftvoucherDetails>
73
+ </ns2:GiftVoucherLookupResponse></S:Body>
74
+ </S:Envelope>
75
+ `;
76
+ const expectedResult = {
77
+ stock: "GIFTVCHR-CLOTH ALLOW",
78
+ serialNo: "4008",
79
+ salesCode: "#MGV",
80
+ saleDate: "14-11-2011",
81
+ saleWarehouse: "4AR",
82
+ saleReference: "BRITTANY",
83
+ saleAgent: 1,
84
+ redeemDate: "05-06-2012",
85
+ redeemWarehouse: "4AR",
86
+ redeemReference: "P4AR002626",
87
+ redeemAgent: 4008,
88
+ expiryDate: "30-11-2012",
89
+ stkGlAccount: "LAGVS20004",
90
+ lastUsedDate: "02-11-2012",
91
+ openingAmount: 30.0,
92
+ amount: 30.0,
93
+ balance: 30.0,
94
+ reservationUsed: 0.0,
95
+ comment1: "",
96
+ diary: "",
97
+ name1: "PRINCE",
98
+ name2: "BRITTANY",
99
+ address1: "",
100
+ address2: "",
101
+ address3: "",
102
+ address4: "",
103
+ postcode: "",
104
+ email: "",
105
+ telephone1: "",
106
+ countryCode: "",
107
+ currency: "",
108
+ };
109
+ mAxios.post.mockResolvedValueOnce({ data: mockedResp });
110
+ const response = await gvModule.giftVoucherLookup(params, token);
111
+ // Test that expected response is correct
112
+ expect(Array.isArray(response)).toBe(true);
113
+ expect(response.length).toBe(1);
114
+ expect(response[0]).toEqual(expectedResult);
115
+ const actualPayload = mAxios.post.mock.calls[0][1];
116
+ // Test that actual payload sent in the API matches expected payload
117
+ expect(Utils.removeEmptySpaces(actualPayload)).toEqual(Utils.removeEmptySpaces(expectedPayload));
118
+ mAxios.post.mockClear();
119
+ });
120
+ it("giftVoucherVerificationKey() should send correct request payload and parse the respone correctly", async () => {
121
+ const token = "test-token";
122
+ const ns = "S";
123
+ const params = {
124
+ stock: `GIFTVCHR-CLOTH ALLOW`,
125
+ serialNo: `40089`,
126
+ };
127
+ const expectedPayload = `
128
+ <${ns}:Envelope xmlns:${ns}="http://schemas.xmlsoap.org/soap/envelope/" xmlns:${ServiceAlias.GIFT_VOUCHER}="http://${ServiceAlias.GIFT_VOUCHER}.ws.fbsaust.com.au">
129
+ <${ns}:Header>
130
+ <${ServiceAlias.GIFT_VOUCHER}:SessionId>${token}</${ServiceAlias.GIFT_VOUCHER}:SessionId>
131
+ </${ns}:Header>
132
+ <${ns}:Body>
133
+ <${ServiceAlias.GIFT_VOUCHER}:GiftVoucherVerificationKey>
134
+ <giftvoucher>
135
+ <stock>GIFTVCHR-CLOTH ALLOW</stock>
136
+ <serial_no>40089</serial_no>
137
+ </giftvoucher>
138
+ </${ServiceAlias.GIFT_VOUCHER}:GiftVoucherVerificationKey>
139
+ </${ns}:Body>
140
+ </${ns}:Envelope>
141
+ `;
142
+ const mockedResp = `
143
+ <?xml version='1.0' encoding='UTF-8'?>
144
+ <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
145
+ <S:Body><ns2:GiftVoucherVerificationKeyResponse xmlns:ns2="http://gv.ws.fbsaust.com.au">
146
+ <verification_key>9426153259</verification_key>
147
+ </ns2:GiftVoucherVerificationKeyResponse></S:Body>
148
+ </S:Envelope>
149
+ `;
150
+ const expectedResult = "9426153259";
151
+ mAxios.post.mockResolvedValueOnce({ data: mockedResp });
152
+ const response = await gvModule.giftVoucherVerificationKey(params, token);
153
+ // Test that expected response is correct
154
+ expect(typeof response === "string").toBe(true);
155
+ expect(response).toEqual(expectedResult);
156
+ const actualPayload = mAxios.post.mock.calls[0][1];
157
+ // Test that actual payload sent in the API matches expected payload
158
+ expect(Utils.removeEmptySpaces(actualPayload)).toEqual(Utils.removeEmptySpaces(expectedPayload));
159
+ mAxios.post.mockClear();
160
+ });
161
+ it("giftVoucherReservation() should send correct request payload and parse the respone correctly", async () => {
162
+ const token = "test-token";
163
+ const ns = "S";
164
+ const params = {
165
+ stock: `GIFTVCHR-CLOTH ALLOW`,
166
+ serialNo: `40089`,
167
+ verificationKey: "9426153259",
168
+ amount: 100,
169
+ };
170
+ const expectedPayload = `
171
+ <${ns}:Envelope xmlns:${ns}="http://schemas.xmlsoap.org/soap/envelope/" xmlns:${ServiceAlias.GIFT_VOUCHER}="http://${ServiceAlias.GIFT_VOUCHER}.ws.fbsaust.com.au">
172
+ <${ns}:Header>
173
+ <${ServiceAlias.GIFT_VOUCHER}:SessionId>${token}</${ServiceAlias.GIFT_VOUCHER}:SessionId>
174
+ </${ns}:Header>
175
+ <${ns}:Body>
176
+ <${ServiceAlias.GIFT_VOUCHER}:GiftVoucherReservation>
177
+ <giftvoucher>
178
+ <stock>GIFTVCHR-CLOTH ALLOW</stock>
179
+ <serial_no>40089</serial_no>
180
+ </giftvoucher>
181
+ <verification_key>9426153259</verification_key>
182
+ <amount>100</amount>
183
+ </${ServiceAlias.GIFT_VOUCHER}:GiftVoucherReservation>
184
+ </${ns}:Body>
185
+ </${ns}:Envelope>
186
+ `;
187
+ const mockedResp = `
188
+ <?xml version='1.0' encoding='UTF-8'?>
189
+ <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
190
+ <S:Body><ns2:GiftVoucherReservationResponse xmlns:ns2="http://gv.ws.fbsaust.com.au">
191
+ <reservation_key>8951138685</reservation_key>
192
+ </ns2:GiftVoucherReservationResponse></S:Body>
193
+ </S:Envelope>
194
+ `;
195
+ const expectedResult = "8951138685";
196
+ mAxios.post.mockResolvedValueOnce({ data: mockedResp });
197
+ const response = await gvModule.giftVoucherReservation(params, token);
198
+ // Test that expected response is correct
199
+ expect(typeof response === "string").toBe(true);
200
+ expect(response).toEqual(expectedResult);
201
+ const actualPayload = mAxios.post.mock.calls[0][1];
202
+ // Test that actual payload sent in the API matches expected payload
203
+ expect(Utils.removeEmptySpaces(actualPayload)).toEqual(Utils.removeEmptySpaces(expectedPayload));
204
+ mAxios.post.mockClear();
205
+ });
206
+ it("giftVoucherUsed() should send correct request payload and parse the respone correctly", async () => {
207
+ const token = "test-token";
208
+ const ns = "S";
209
+ const params = {
210
+ stock: `GIFTVCHR-CLOTH ALLOW`,
211
+ serialNo: `40089`,
212
+ verificationKey: "9426153259",
213
+ reservationKey: "8951138685",
214
+ };
215
+ const expectedPayload = `
216
+ <${ns}:Envelope xmlns:${ns}="http://schemas.xmlsoap.org/soap/envelope/" xmlns:${ServiceAlias.GIFT_VOUCHER}="http://${ServiceAlias.GIFT_VOUCHER}.ws.fbsaust.com.au">
217
+ <${ns}:Header>
218
+ <${ServiceAlias.GIFT_VOUCHER}:SessionId>${token}</${ServiceAlias.GIFT_VOUCHER}:SessionId>
219
+ </${ns}:Header>
220
+ <${ns}:Body>
221
+ <${ServiceAlias.GIFT_VOUCHER}:GiftVoucherUsed>
222
+ <giftvoucher>
223
+ <stock>GIFTVCHR-CLOTH ALLOW</stock>
224
+ <serial_no>40089</serial_no>
225
+ </giftvoucher>
226
+ <verification_key>9426153259</verification_key>
227
+ <reservation_key>8951138685</reservation_key>
228
+ </${ServiceAlias.GIFT_VOUCHER}:GiftVoucherUsed>
229
+ </${ns}:Body>
230
+ </${ns}:Envelope>
231
+ `;
232
+ const mockedResp = `
233
+ <?xml version='1.0' encoding='UTF-8'?>
234
+ <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
235
+ <S:Body><ns2:GiftVoucherUsedResponse xmlns:ns2="http://gv.ws.fbsaust.com.au">
236
+ <reservation_history_no>111</reservation_history_no>
237
+ </ns2:GiftVoucherUsedResponse></S:Body>
238
+ </S:Envelope>
239
+ `;
240
+ const expectedResult = 111;
241
+ mAxios.post.mockResolvedValueOnce({ data: mockedResp });
242
+ const response = await gvModule.giftVoucherUsed(params, token);
243
+ // Test that expected response is correct
244
+ expect(typeof response === "number").toBe(true);
245
+ expect(response).toEqual(expectedResult);
246
+ const actualPayload = mAxios.post.mock.calls[0][1];
247
+ // Test that actual payload sent in the API matches expected payload
248
+ expect(Utils.removeEmptySpaces(actualPayload)).toEqual(Utils.removeEmptySpaces(expectedPayload));
249
+ mAxios.post.mockClear();
250
+ });
251
+ it("giftVoucherReservationCancel() should send correct request payload and parse the respone correctly", async () => {
252
+ const token = "test-token";
253
+ const ns = "S";
254
+ const params = {
255
+ stock: `GIFTVCHR-CLOTH ALLOW`,
256
+ serialNo: `40089`,
257
+ verificationKey: "9426153259",
258
+ reservationKey: "8951138685",
259
+ };
260
+ const expectedPayload = `
261
+ <${ns}:Envelope xmlns:${ns}="http://schemas.xmlsoap.org/soap/envelope/" xmlns:${ServiceAlias.GIFT_VOUCHER}="http://${ServiceAlias.GIFT_VOUCHER}.ws.fbsaust.com.au">
262
+ <${ns}:Header>
263
+ <${ServiceAlias.GIFT_VOUCHER}:SessionId>${token}</${ServiceAlias.GIFT_VOUCHER}:SessionId>
264
+ </${ns}:Header>
265
+ <${ns}:Body>
266
+ <${ServiceAlias.GIFT_VOUCHER}:GiftVoucherReservationCancel>
267
+ <giftvoucher>
268
+ <stock>GIFTVCHR-CLOTH ALLOW</stock>
269
+ <serial_no>40089</serial_no>
270
+ </giftvoucher>
271
+ <verification_key>9426153259</verification_key>
272
+ <reservation_key>8951138685</reservation_key>
273
+ </${ServiceAlias.GIFT_VOUCHER}:GiftVoucherReservationCancel>
274
+ </${ns}:Body>
275
+ </${ns}:Envelope>
276
+ `;
277
+ const mockedResp = `
278
+ <?xml version='1.0' encoding='UTF-8'?>
279
+ <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
280
+ <S:Body><ns2:GiftVoucherReservationCancelResponse xmlns:ns2="http://gv.ws.fbsaust.com.au">
281
+ <result>true</result>
282
+ </ns2:GiftVoucherReservationCancelResponse></S:Body>
283
+ </S:Envelope>
284
+ `;
285
+ const expectedResult = true;
286
+ mAxios.post.mockResolvedValueOnce({ data: mockedResp });
287
+ const response = await gvModule.giftVoucherReservationCancel(params, token);
288
+ // Test that expected response is correct
289
+ expect(typeof response === "boolean").toBe(true);
290
+ expect(response).toEqual(expectedResult);
291
+ const actualPayload = mAxios.post.mock.calls[0][1];
292
+ // Test that actual payload sent in the API matches expected payload
293
+ expect(Utils.removeEmptySpaces(actualPayload)).toEqual(Utils.removeEmptySpaces(expectedPayload));
294
+ mAxios.post.mockClear();
295
+ });
296
+ });
@@ -0,0 +1 @@
1
+ export * from "./gift-voucher.module";
@@ -0,0 +1 @@
1
+ export * from "./gift-voucher.module";
@@ -0,0 +1,6 @@
1
+ import { GiftVoucher, GiftVoucherLookupQueryParams, GiftVoucherRaw, GiftVoucherReservationCancelQueryParams, GiftVoucherReservationQueryParams, GiftVoucherUsedQueryParams } from "../types";
2
+ export declare function mapGiftVoucherQueryParams(src: GiftVoucherLookupQueryParams): string;
3
+ export declare function mapGiftVoucher(src: GiftVoucherRaw): GiftVoucher;
4
+ export declare function mapGiftVoucherReservationQueryParams(src: GiftVoucherReservationQueryParams): string;
5
+ export declare function mapGiftVoucherUsedQueryParams(src: GiftVoucherUsedQueryParams): string;
6
+ export declare function mapGiftVoucherReservationCancelQueryParams(src: GiftVoucherReservationCancelQueryParams): string;
@@ -0,0 +1,70 @@
1
+ import { Utils } from "../../../helpers";
2
+ export function mapGiftVoucherQueryParams(src) {
3
+ const params = {
4
+ stock: src?.stock,
5
+ serial_no: src?.serialNo,
6
+ };
7
+ return `<giftvoucher>${Utils.toXml(params)}</giftvoucher>`;
8
+ }
9
+ export function mapGiftVoucher(src) {
10
+ return {
11
+ stock: Utils.getFirst(src?.stock),
12
+ serialNo: Utils.getFirst(src?.serial_no),
13
+ salesCode: Utils.getFirst(src?.sales_code),
14
+ saleDate: Utils.getFirst(src?.sale_date),
15
+ saleWarehouse: Utils.getFirst(src?.sale_warehouse),
16
+ saleReference: Utils.getFirst(src?.sale_reference),
17
+ saleAgent: Utils.toNumber(Utils.getFirst(src?.sale_agent)),
18
+ redeemDate: Utils.getFirst(src?.redeem_date),
19
+ redeemWarehouse: Utils.getFirst(src?.redeem_warehouse),
20
+ redeemReference: Utils.getFirst(src?.redeem_reference),
21
+ redeemAgent: Utils.toNumber(Utils.getFirst(src?.redeem_agent)),
22
+ expiryDate: Utils.getFirst(src?.expiry_date),
23
+ stkGlAccount: Utils.getFirst(src?.stk_gl_account),
24
+ lastUsedDate: Utils.getFirst(src?.last_used_date),
25
+ openingAmount: Utils.toNumber(Utils.getFirst(src?.opening_amount)),
26
+ amount: Utils.toNumber(Utils.getFirst(src?.amount)),
27
+ balance: Utils.toNumber(Utils.getFirst(src?.balance)),
28
+ reservationUsed: Utils.toNumber(Utils.getFirst(src?.reservation_used)),
29
+ comment1: Utils.getFirst(src?.comment_1),
30
+ diary: Utils.getFirst(src?.diary),
31
+ name1: Utils.getFirst(src?.name_1),
32
+ name2: Utils.getFirst(src?.name_2),
33
+ address1: Utils.getFirst(src?.address_1),
34
+ address2: Utils.getFirst(src?.address_2),
35
+ address3: Utils.getFirst(src?.address_3),
36
+ address4: Utils.getFirst(src?.address_4),
37
+ postcode: Utils.getFirst(src?.postcode),
38
+ email: Utils.getFirst(src?.email),
39
+ telephone1: Utils.getFirst(src?.telephone_1),
40
+ countryCode: Utils.getFirst(src?.country_code),
41
+ currency: Utils.getFirst(src?.currency),
42
+ };
43
+ }
44
+ // GiftVoucherReservation
45
+ export function mapGiftVoucherReservationQueryParams(src) {
46
+ const params = {
47
+ giftvoucher: {
48
+ stock: src?.stock,
49
+ serial_no: src?.serialNo,
50
+ },
51
+ verification_key: src?.verificationKey,
52
+ amount: src?.amount,
53
+ };
54
+ return `${Utils.toXml(params)}`;
55
+ }
56
+ // GiftVoucherUsed
57
+ export function mapGiftVoucherUsedQueryParams(src) {
58
+ const params = {
59
+ giftvoucher: {
60
+ stock: src?.stock,
61
+ serial_no: src?.serialNo,
62
+ },
63
+ verification_key: src?.verificationKey,
64
+ reservation_key: src?.reservationKey,
65
+ };
66
+ return `${Utils.toXml(params)}`;
67
+ }
68
+ export function mapGiftVoucherReservationCancelQueryParams(src) {
69
+ return mapGiftVoucherUsedQueryParams(src);
70
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,21 @@
1
+ import { mapGiftVoucherReservationQueryParams } from ".";
2
+ import { Utils } from "../../../helpers";
3
+ describe("mapGiftVoucherReservationQueryParams", () => {
4
+ it("should map params and return XML string correctly", () => {
5
+ const params = {
6
+ stock: "12345",
7
+ serialNo: "ABC123",
8
+ verificationKey: "1234567890",
9
+ amount: 100,
10
+ };
11
+ const expectedXml = `
12
+ <giftvoucher>
13
+ <stock>12345</stock>
14
+ <serial_no>ABC123</serial_no>
15
+ </giftvoucher>
16
+ <verification_key>1234567890</verification_key>
17
+ <amount>100</amount>
18
+ `;
19
+ expect(Utils.removeEmptySpaces(mapGiftVoucherReservationQueryParams(params))).toEqual(Utils.removeEmptySpaces(expectedXml));
20
+ });
21
+ });
@@ -0,0 +1,92 @@
1
+ export interface GiftVoucherRaw {
2
+ stock: string[];
3
+ serial_no: string[];
4
+ sales_code: string[];
5
+ sale_date: string[];
6
+ sale_warehouse: string[];
7
+ sale_reference: string[];
8
+ sale_agent: string[];
9
+ redeem_date: string[];
10
+ redeem_warehouse: string[];
11
+ redeem_reference: string[];
12
+ redeem_agent: string[];
13
+ expiry_date: string[];
14
+ stk_gl_account: string[];
15
+ last_used_date: string[];
16
+ opening_amount: string[];
17
+ amount: string[];
18
+ balance: string[];
19
+ reservation_used: string[];
20
+ comment_1: string[];
21
+ diary: string[];
22
+ name_1: string[];
23
+ name_2: string[];
24
+ address_1: string[];
25
+ address_2: string[];
26
+ address_3: string[];
27
+ address_4: string[];
28
+ postcode: string[];
29
+ email: string[];
30
+ telephone_1: string[];
31
+ country_code: string[];
32
+ currency: string[];
33
+ }
34
+ export interface GiftVoucherLookupResponse {
35
+ giftvoucherDetails: GiftVoucherRaw[];
36
+ }
37
+ export interface GiftVoucher {
38
+ stock: string;
39
+ serialNo: string;
40
+ salesCode: string;
41
+ saleDate: string;
42
+ saleWarehouse: string;
43
+ saleReference: string;
44
+ saleAgent: number;
45
+ redeemDate: string;
46
+ redeemWarehouse: string;
47
+ redeemReference: string;
48
+ redeemAgent: number;
49
+ expiryDate: string;
50
+ stkGlAccount: string;
51
+ lastUsedDate: string;
52
+ openingAmount: number;
53
+ amount: number;
54
+ balance: number;
55
+ reservationUsed: number;
56
+ comment1: string;
57
+ diary: string;
58
+ name1: string;
59
+ name2: string;
60
+ address1: string;
61
+ address2: string;
62
+ address3: string;
63
+ address4: string;
64
+ postcode: string;
65
+ email: string;
66
+ telephone1: string;
67
+ countryCode: string;
68
+ currency: string;
69
+ }
70
+ export interface GiftVoucherLookupQueryParams {
71
+ stock: string;
72
+ serialNo: string;
73
+ }
74
+ export interface GiftVoucherVerificationKeyResponse {
75
+ verification_key: string[];
76
+ }
77
+ export type GiftVoucherVerificationKeyQueryParams = GiftVoucherLookupQueryParams;
78
+ export interface GiftVoucherReservationResponse {
79
+ reservation_key: string[];
80
+ }
81
+ export interface GiftVoucherReservationQueryParams extends GiftVoucherLookupQueryParams {
82
+ verificationKey: string;
83
+ amount: number;
84
+ }
85
+ export interface GiftVoucherUsedResponse {
86
+ reservation_history_no: string[];
87
+ }
88
+ export interface GiftVoucherUsedQueryParams extends GiftVoucherLookupQueryParams {
89
+ verificationKey: string;
90
+ reservationKey: string;
91
+ }
92
+ export type GiftVoucherReservationCancelQueryParams = GiftVoucherUsedQueryParams;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ export * from "./auth";
2
+ export * from "./carrier";
3
+ export * from "./diary";
4
+ export * from "./gift-voucher";
5
+ export * from "./point-of-sale";
6
+ export * from "./shared";
7
+ export * from "./stock-level-lookup";
8
+ export * from "./stock-lookup";
@@ -0,0 +1,8 @@
1
+ export * from "./auth";
2
+ export * from "./carrier";
3
+ export * from "./diary";
4
+ export * from "./gift-voucher";
5
+ export * from "./point-of-sale";
6
+ export * from "./shared";
7
+ export * from "./stock-level-lookup";
8
+ export * from "./stock-lookup";
@@ -0,0 +1,3 @@
1
+ export * from "./mappings";
2
+ export * from "./point-of-sale.module";
3
+ export * from "./types";
@@ -0,0 +1,3 @@
1
+ export * from "./mappings";
2
+ export * from "./point-of-sale.module";
3
+ export * from "./types";
@@ -0,0 +1 @@
1
+ export * from "./process-sale-order.mapper";
@@ -0,0 +1 @@
1
+ export * from "./process-sale-order.mapper";
@@ -0,0 +1,6 @@
1
+ import { ProcessSaleOrderQueryDebtor, ProcessSaleOrderQueryExtra, ProcessSaleOrderQueryHeader, ProcessSaleOrderQueryParams, ProcessSaleOrderQueryStock } from "../types";
2
+ export declare function mapProcessSaleOrderQueryParams(params: ProcessSaleOrderQueryParams): string;
3
+ export declare function mapProcessSaleOrderQueryHeaders(params: ProcessSaleOrderQueryHeader): string;
4
+ export declare function mapProcessSaleOrderQueryExtra(params: ProcessSaleOrderQueryExtra): string;
5
+ export declare function mapProcessSaleOrderQueryStock(params: ProcessSaleOrderQueryStock): string;
6
+ export declare function mapProcessSaleOrderQueryDebtor(params: ProcessSaleOrderQueryDebtor): string;