btrz-api-client 8.35.0 → 8.38.0
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/lib/client-standalone-min.js +3 -3
- package/lib/client.js +2 -0
- package/lib/endpoints/inventory/custom-content.js +0 -1
- package/lib/endpoints/inventory/fees.js +6 -5
- package/lib/endpoints/notifications/short-urls.js +83 -0
- package/lib/endpoints/operations/cancellation_settings.js +42 -0
- package/package.json +1 -1
- package/src/client.js +2 -0
- package/src/endpoints/inventory/custom-content.js +0 -1
- package/src/endpoints/inventory/fees.js +6 -5
- package/src/endpoints/notifications/short-urls.js +64 -0
- package/src/endpoints/operations/cancellation_settings.js +27 -0
- package/test/endpoints/notifications/short-urls.test.js +59 -0
- package/test/endpoints/operations/cancellation_settings.test.js +59 -0
package/lib/client.js
CHANGED
|
@@ -362,6 +362,7 @@ function createOperations(_ref6) {
|
|
|
362
362
|
transaction: require("./endpoints/operations/transaction.js")({ client: client, internalAuthTokenProvider: internalAuthTokenProvider }),
|
|
363
363
|
transactions: require("./endpoints/operations/transactions.js")({ client: client, internalAuthTokenProvider: internalAuthTokenProvider }),
|
|
364
364
|
tripChangeInfo: require("./endpoints/operations/trip_change_info.js")({ client: client, internalAuthTokenProvider: internalAuthTokenProvider }),
|
|
365
|
+
cancellationSettings: require("./endpoints/operations/cancellation_settings.js")({ client: client, internalAuthTokenProvider: internalAuthTokenProvider }),
|
|
365
366
|
vehicleAssignments: require("./endpoints/operations/vehicle_assignments.js")({ client: client, internalAuthTokenProvider: internalAuthTokenProvider }),
|
|
366
367
|
vouchers: require("./endpoints/operations/vouchers.js")({ client: client, internalAuthTokenProvider: internalAuthTokenProvider }),
|
|
367
368
|
waitlists: require("./endpoints/operations/waitlists.js")({ client: client, internalAuthTokenProvider: internalAuthTokenProvider }),
|
|
@@ -424,6 +425,7 @@ function createNotifications(_ref8) {
|
|
|
424
425
|
externalCustomers: require("./endpoints/notifications/external-customers.js")({ client: client, internalAuthTokenProvider: internalAuthTokenProvider }),
|
|
425
426
|
twilio: require("./endpoints/notifications/twilio.js")({ client: client, internalAuthTokenProvider: internalAuthTokenProvider }),
|
|
426
427
|
salesforce: require("./endpoints/notifications/salesforce.js")({ client: client, internalAuthTokenProvider: internalAuthTokenProvider }),
|
|
428
|
+
shortUrls: require("./endpoints/notifications/short-urls.js")({ client: client, internalAuthTokenProvider: internalAuthTokenProvider }),
|
|
427
429
|
notify: require("./endpoints/notifications/notify.js")({ client: client, internalAuthTokenProvider: internalAuthTokenProvider }),
|
|
428
430
|
ordersRulesValidations: require("./endpoints/notifications/orders-rules-validations.js")({ client: client, internalAuthTokenProvider: internalAuthTokenProvider }),
|
|
429
431
|
__test: {
|
|
@@ -27,7 +27,6 @@ function customContentFactory(_ref) {
|
|
|
27
27
|
* GET /custom-content — List custom content (paginated). Query: enabled, pageId.
|
|
28
28
|
* @param {Object} opts
|
|
29
29
|
* @param {string} [opts.token] - API key
|
|
30
|
-
* @param {string} [opts.jwtToken] - JWT or internal auth
|
|
31
30
|
* @param {InventoryCustomContentQuery} [opts.query] - Query params (enabled, pageId)
|
|
32
31
|
* @param {Object} [opts.headers] - Optional headers
|
|
33
32
|
* @returns {Promise<import("axios").AxiosResponse<{ customContent: Object[] }>>}
|
|
@@ -6,10 +6,11 @@ var _require = require("./../endpoints_helpers.js"),
|
|
|
6
6
|
/**
|
|
7
7
|
* Query params for GET /fees (btrz-api-inventory). See fees get-handler getSpec().
|
|
8
8
|
* @typedef {Object} InventoryFeesQuery
|
|
9
|
-
* @property {string} [providerIds] -
|
|
10
|
-
* @property {string} [rules] -
|
|
11
|
-
* @property {string} [productId] - Product ID
|
|
12
|
-
* @property {string} [internalId] - Fee internal id
|
|
9
|
+
* @property {string} [providerIds] - Comma-separated provider (account) IDs to get fees for
|
|
10
|
+
* @property {string} [rules] - Comma-separated rules where the fees apply (e.g. cancel, ticket, transaction)
|
|
11
|
+
* @property {string} [productId] - Product ID to filter fees by
|
|
12
|
+
* @property {string} [internalId] - Fee internal id to filter by
|
|
13
|
+
* @property {string} [page] - Page number for pagination (1-based). Response includes next, previous, count
|
|
13
14
|
*/
|
|
14
15
|
|
|
15
16
|
/**
|
|
@@ -32,7 +33,7 @@ function feesFactory(_ref) {
|
|
|
32
33
|
* @param {string} [opts.jwtToken] - JWT or internal auth symbol
|
|
33
34
|
* @param {InventoryFeesQuery} [opts.query] - Query params (providerIds, rules, productId, internalId)
|
|
34
35
|
* @param {Object} [opts.headers] - Optional headers
|
|
35
|
-
* @returns {Promise<import("axios").AxiosResponse<{ fees: Array, next
|
|
36
|
+
* @returns {Promise<import("axios").AxiosResponse<{ fees: Array, next: string, previous: string, count: number }>>}
|
|
36
37
|
* @throws When response is 4xx/5xx (401, 500)
|
|
37
38
|
*/
|
|
38
39
|
function all(_ref2) {
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _require = require("../endpoints_helpers.js"),
|
|
4
|
+
authorizationHeaders = _require.authorizationHeaders;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Request body for POST /short-urls (btrz-api-notifications). Sent as urlData.
|
|
8
|
+
* @typedef {Object} ShortUrlPostData
|
|
9
|
+
* @property {string} fullUrl - The full URL to shorten (target of the short link)
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Factory for short URLs API (btrz-api-notifications).
|
|
14
|
+
* @param {Object} deps
|
|
15
|
+
* @param {import("axios").AxiosInstance} deps.client
|
|
16
|
+
* @param {{ getToken: function(): string }} [deps.internalAuthTokenProvider]
|
|
17
|
+
* @returns {{ create: function, getByShortId: function }}
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
function shortUrlsFactory(_ref) {
|
|
22
|
+
var client = _ref.client,
|
|
23
|
+
internalAuthTokenProvider = _ref.internalAuthTokenProvider;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* POST /short-urls - create a short URL for the given fullUrl. Requires JWT (BETTEREZ_APP) and X-API-KEY.
|
|
27
|
+
* @param {Object} opts
|
|
28
|
+
* @param {string} [opts.token] - API key
|
|
29
|
+
* @param {string} [opts.jwtToken] - JWT or internal auth symbol (required for this endpoint)
|
|
30
|
+
* @param {ShortUrlPostData} opts.urlData - Payload: fullUrl (required), method (optional)
|
|
31
|
+
* @param {Object} [opts.headers] - Optional headers
|
|
32
|
+
* @returns {Promise<import("axios").AxiosResponse<{ shortUrl: string, shortId: string, fullUrl: string, createdAt: Object }>>}
|
|
33
|
+
* @throws When response is 4xx/5xx (400 WRONG_DATA fullUrl is required, 401, 500)
|
|
34
|
+
*/
|
|
35
|
+
function create(_ref2) {
|
|
36
|
+
var token = _ref2.token,
|
|
37
|
+
jwtToken = _ref2.jwtToken,
|
|
38
|
+
urlData = _ref2.urlData,
|
|
39
|
+
headers = _ref2.headers;
|
|
40
|
+
|
|
41
|
+
return client({
|
|
42
|
+
url: "/short-urls",
|
|
43
|
+
method: "post",
|
|
44
|
+
headers: authorizationHeaders({ token: token, jwtToken: jwtToken, internalAuthTokenProvider: internalAuthTokenProvider, headers: headers }),
|
|
45
|
+
data: { urlData: urlData }
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* GET /u/:shortId - resolve short ID. Returns 302 to full URL. Use maxRedirects: 0 to get Location.
|
|
51
|
+
* @param {Object} opts
|
|
52
|
+
* @param {string} [opts.token] - API key (X-API-KEY)
|
|
53
|
+
* @param {string} opts.shortId - The short identifier (e.g. from btrz.ca/u/<shortId>)
|
|
54
|
+
* @param {number} [opts.maxRedirects=0] - Set to 0 to receive 302 and Location header without following redirect
|
|
55
|
+
* @param {Object} [opts.headers] - Optional headers
|
|
56
|
+
* @returns {Promise<import("axios").AxiosResponse>}
|
|
57
|
+
* @throws When response is 4xx/5xx (400 WRONG_DATA shortId is required, 401, 404 SHORT_URL_NOT_FOUND, 500)
|
|
58
|
+
*/
|
|
59
|
+
function getByShortId(_ref3) {
|
|
60
|
+
var token = _ref3.token,
|
|
61
|
+
shortId = _ref3.shortId,
|
|
62
|
+
_ref3$maxRedirects = _ref3.maxRedirects,
|
|
63
|
+
maxRedirects = _ref3$maxRedirects === undefined ? 0 : _ref3$maxRedirects,
|
|
64
|
+
headers = _ref3.headers;
|
|
65
|
+
|
|
66
|
+
return client({
|
|
67
|
+
url: "/u/" + encodeURIComponent(shortId),
|
|
68
|
+
method: "get",
|
|
69
|
+
maxRedirects: maxRedirects,
|
|
70
|
+
validateStatus: function validateStatus(status) {
|
|
71
|
+
return status === 302 || status >= 200 && status < 300;
|
|
72
|
+
},
|
|
73
|
+
headers: authorizationHeaders({ token: token, internalAuthTokenProvider: internalAuthTokenProvider, headers: headers })
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
create: create,
|
|
79
|
+
getByShortId: getByShortId
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
module.exports = shortUrlsFactory;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _require = require("../endpoints_helpers.js"),
|
|
4
|
+
authorizationHeaders = _require.authorizationHeaders;
|
|
5
|
+
|
|
6
|
+
function cancellationSettingsFactory(_ref) {
|
|
7
|
+
var client = _ref.client,
|
|
8
|
+
internalAuthTokenProvider = _ref.internalAuthTokenProvider;
|
|
9
|
+
|
|
10
|
+
function get(_ref2) {
|
|
11
|
+
var token = _ref2.token,
|
|
12
|
+
jwtToken = _ref2.jwtToken,
|
|
13
|
+
headers = _ref2.headers;
|
|
14
|
+
|
|
15
|
+
return client({
|
|
16
|
+
url: "/cancellation-settings",
|
|
17
|
+
method: "get",
|
|
18
|
+
headers: authorizationHeaders({ token: token, jwtToken: jwtToken, internalAuthTokenProvider: internalAuthTokenProvider, headers: headers })
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function update(_ref3) {
|
|
23
|
+
var token = _ref3.token,
|
|
24
|
+
jwtToken = _ref3.jwtToken,
|
|
25
|
+
data = _ref3.data,
|
|
26
|
+
headers = _ref3.headers;
|
|
27
|
+
|
|
28
|
+
return client({
|
|
29
|
+
url: "/cancellation-settings",
|
|
30
|
+
method: "put",
|
|
31
|
+
headers: authorizationHeaders({ token: token, jwtToken: jwtToken, internalAuthTokenProvider: internalAuthTokenProvider, headers: headers }),
|
|
32
|
+
data: data
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
get: get,
|
|
38
|
+
update: update
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
module.exports = cancellationSettingsFactory;
|
package/package.json
CHANGED
package/src/client.js
CHANGED
|
@@ -314,6 +314,7 @@ function createOperations({baseURL, headers, timeout, overrideFn, internalAuthTo
|
|
|
314
314
|
transaction: require("./endpoints/operations/transaction.js")({client, internalAuthTokenProvider}),
|
|
315
315
|
transactions: require("./endpoints/operations/transactions.js")({client, internalAuthTokenProvider}),
|
|
316
316
|
tripChangeInfo: require("./endpoints/operations/trip_change_info.js")({client, internalAuthTokenProvider}),
|
|
317
|
+
cancellationSettings: require("./endpoints/operations/cancellation_settings.js")({client, internalAuthTokenProvider}),
|
|
317
318
|
vehicleAssignments: require("./endpoints/operations/vehicle_assignments.js")({client, internalAuthTokenProvider}),
|
|
318
319
|
vouchers: require("./endpoints/operations/vouchers.js")({client, internalAuthTokenProvider}),
|
|
319
320
|
waitlists: require("./endpoints/operations/waitlists.js")({client, internalAuthTokenProvider}),
|
|
@@ -362,6 +363,7 @@ function createNotifications({baseURL, headers, timeout, overrideFn, internalAut
|
|
|
362
363
|
externalCustomers: require("./endpoints/notifications/external-customers.js")({client, internalAuthTokenProvider}),
|
|
363
364
|
twilio: require("./endpoints/notifications/twilio.js")({client, internalAuthTokenProvider}),
|
|
364
365
|
salesforce: require("./endpoints/notifications/salesforce.js")({client, internalAuthTokenProvider}),
|
|
366
|
+
shortUrls: require("./endpoints/notifications/short-urls.js")({client, internalAuthTokenProvider}),
|
|
365
367
|
notify: require("./endpoints/notifications/notify.js")({client, internalAuthTokenProvider}),
|
|
366
368
|
ordersRulesValidations: require("./endpoints/notifications/orders-rules-validations.js")({client, internalAuthTokenProvider}),
|
|
367
369
|
__test: {
|
|
@@ -21,7 +21,6 @@ function customContentFactory({client, internalAuthTokenProvider}) {
|
|
|
21
21
|
* GET /custom-content — List custom content (paginated). Query: enabled, pageId.
|
|
22
22
|
* @param {Object} opts
|
|
23
23
|
* @param {string} [opts.token] - API key
|
|
24
|
-
* @param {string} [opts.jwtToken] - JWT or internal auth
|
|
25
24
|
* @param {InventoryCustomContentQuery} [opts.query] - Query params (enabled, pageId)
|
|
26
25
|
* @param {Object} [opts.headers] - Optional headers
|
|
27
26
|
* @returns {Promise<import("axios").AxiosResponse<{ customContent: Object[] }>>}
|
|
@@ -3,10 +3,11 @@ const {authorizationHeaders} = require("./../endpoints_helpers.js");
|
|
|
3
3
|
/**
|
|
4
4
|
* Query params for GET /fees (btrz-api-inventory). See fees get-handler getSpec().
|
|
5
5
|
* @typedef {Object} InventoryFeesQuery
|
|
6
|
-
* @property {string} [providerIds] -
|
|
7
|
-
* @property {string} [rules] -
|
|
8
|
-
* @property {string} [productId] - Product ID
|
|
9
|
-
* @property {string} [internalId] - Fee internal id
|
|
6
|
+
* @property {string} [providerIds] - Comma-separated provider (account) IDs to get fees for
|
|
7
|
+
* @property {string} [rules] - Comma-separated rules where the fees apply (e.g. cancel, ticket, transaction)
|
|
8
|
+
* @property {string} [productId] - Product ID to filter fees by
|
|
9
|
+
* @property {string} [internalId] - Fee internal id to filter by
|
|
10
|
+
* @property {string} [page] - Page number for pagination (1-based). Response includes next, previous, count
|
|
10
11
|
*/
|
|
11
12
|
|
|
12
13
|
/**
|
|
@@ -24,7 +25,7 @@ function feesFactory({client, internalAuthTokenProvider}) {
|
|
|
24
25
|
* @param {string} [opts.jwtToken] - JWT or internal auth symbol
|
|
25
26
|
* @param {InventoryFeesQuery} [opts.query] - Query params (providerIds, rules, productId, internalId)
|
|
26
27
|
* @param {Object} [opts.headers] - Optional headers
|
|
27
|
-
* @returns {Promise<import("axios").AxiosResponse<{ fees: Array, next
|
|
28
|
+
* @returns {Promise<import("axios").AxiosResponse<{ fees: Array, next: string, previous: string, count: number }>>}
|
|
28
29
|
* @throws When response is 4xx/5xx (401, 500)
|
|
29
30
|
*/
|
|
30
31
|
function all({token, jwtToken, query = {}, headers}) {
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
const {authorizationHeaders} = require("../endpoints_helpers.js");
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Request body for POST /short-urls (btrz-api-notifications). Sent as urlData.
|
|
5
|
+
* @typedef {Object} ShortUrlPostData
|
|
6
|
+
* @property {string} fullUrl - The full URL to shorten (target of the short link)
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Factory for short URLs API (btrz-api-notifications).
|
|
11
|
+
* @param {Object} deps
|
|
12
|
+
* @param {import("axios").AxiosInstance} deps.client
|
|
13
|
+
* @param {{ getToken: function(): string }} [deps.internalAuthTokenProvider]
|
|
14
|
+
* @returns {{ create: function, getByShortId: function }}
|
|
15
|
+
*/
|
|
16
|
+
function shortUrlsFactory({client, internalAuthTokenProvider}) {
|
|
17
|
+
/**
|
|
18
|
+
* POST /short-urls - create a short URL for the given fullUrl. Requires JWT (BETTEREZ_APP) and X-API-KEY.
|
|
19
|
+
* @param {Object} opts
|
|
20
|
+
* @param {string} [opts.token] - API key
|
|
21
|
+
* @param {string} [opts.jwtToken] - JWT or internal auth symbol (required for this endpoint)
|
|
22
|
+
* @param {ShortUrlPostData} opts.urlData - Payload: fullUrl (required), method (optional)
|
|
23
|
+
* @param {Object} [opts.headers] - Optional headers
|
|
24
|
+
* @returns {Promise<import("axios").AxiosResponse<{ shortUrl: string, shortId: string, fullUrl: string, createdAt: Object }>>}
|
|
25
|
+
* @throws When response is 4xx/5xx (400 WRONG_DATA fullUrl is required, 401, 500)
|
|
26
|
+
*/
|
|
27
|
+
function create({token, jwtToken, urlData, headers}) {
|
|
28
|
+
return client({
|
|
29
|
+
url: "/short-urls",
|
|
30
|
+
method: "post",
|
|
31
|
+
headers: authorizationHeaders({token, jwtToken, internalAuthTokenProvider, headers}),
|
|
32
|
+
data: {urlData}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* GET /u/:shortId - resolve short ID. Returns 302 to full URL. Use maxRedirects: 0 to get Location.
|
|
38
|
+
* @param {Object} opts
|
|
39
|
+
* @param {string} [opts.token] - API key (X-API-KEY)
|
|
40
|
+
* @param {string} opts.shortId - The short identifier (e.g. from btrz.ca/u/<shortId>)
|
|
41
|
+
* @param {number} [opts.maxRedirects=0] - Set to 0 to receive 302 and Location header without following redirect
|
|
42
|
+
* @param {Object} [opts.headers] - Optional headers
|
|
43
|
+
* @returns {Promise<import("axios").AxiosResponse>}
|
|
44
|
+
* @throws When response is 4xx/5xx (400 WRONG_DATA shortId is required, 401, 404 SHORT_URL_NOT_FOUND, 500)
|
|
45
|
+
*/
|
|
46
|
+
function getByShortId({token, shortId, maxRedirects = 0, headers}) {
|
|
47
|
+
return client({
|
|
48
|
+
url: `/u/${encodeURIComponent(shortId)}`,
|
|
49
|
+
method: "get",
|
|
50
|
+
maxRedirects,
|
|
51
|
+
validateStatus: (status) => {
|
|
52
|
+
return status === 302 || (status >= 200 && status < 300);
|
|
53
|
+
},
|
|
54
|
+
headers: authorizationHeaders({token, internalAuthTokenProvider, headers})
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
create,
|
|
60
|
+
getByShortId
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
module.exports = shortUrlsFactory;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const {authorizationHeaders} = require("../endpoints_helpers.js");
|
|
2
|
+
|
|
3
|
+
function cancellationSettingsFactory({client, internalAuthTokenProvider}) {
|
|
4
|
+
function get({token, jwtToken, headers}) {
|
|
5
|
+
return client({
|
|
6
|
+
url: "/cancellation-settings",
|
|
7
|
+
method: "get",
|
|
8
|
+
headers: authorizationHeaders({token, jwtToken, internalAuthTokenProvider, headers})
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function update({token, jwtToken, data, headers}) {
|
|
13
|
+
return client({
|
|
14
|
+
url: "/cancellation-settings",
|
|
15
|
+
method: "put",
|
|
16
|
+
headers: authorizationHeaders({token, jwtToken, internalAuthTokenProvider, headers}),
|
|
17
|
+
data
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
get,
|
|
23
|
+
update
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
module.exports = cancellationSettingsFactory;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
const {expect} = require("chai");
|
|
2
|
+
const {axiosMock} = require("./../../test-helpers.js");
|
|
3
|
+
const api = require("./../../../src/client.js").createApiClient({baseURL: "http://test.com"});
|
|
4
|
+
|
|
5
|
+
describe("notifications/short-urls", () => {
|
|
6
|
+
const token = "my-api-key";
|
|
7
|
+
const jwtToken = "my-jwt";
|
|
8
|
+
|
|
9
|
+
afterEach(() => {
|
|
10
|
+
axiosMock.reset();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("should POST create short URL with urlData (fullUrl)", () => {
|
|
14
|
+
const urlData = {fullUrl: "https://example.com/path"};
|
|
15
|
+
axiosMock.onPost("/short-urls").reply(({headers, data}) => {
|
|
16
|
+
if (headers["x-api-key"] === token && headers.authorization === `Bearer ${jwtToken}`) {
|
|
17
|
+
const body = JSON.parse(data);
|
|
18
|
+
if (body.urlData && body.urlData.fullUrl === urlData.fullUrl) {
|
|
19
|
+
return [200, {shortUrl: "https://btrz.ca/u/abc123", shortId: "abc123", fullUrl: urlData.fullUrl, createdAt: {}}];
|
|
20
|
+
}
|
|
21
|
+
return [400];
|
|
22
|
+
}
|
|
23
|
+
return [403];
|
|
24
|
+
});
|
|
25
|
+
return api.notifications.shortUrls.create({token, jwtToken, urlData}).then((res) => {
|
|
26
|
+
expect(res.status).to.equal(200);
|
|
27
|
+
expect(res.data.shortUrl).to.equal("https://btrz.ca/u/abc123");
|
|
28
|
+
expect(res.data.shortId).to.equal("abc123");
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("should POST create short URL with only fullUrl", () => {
|
|
33
|
+
const urlData = {fullUrl: "https://example.com/only"};
|
|
34
|
+
axiosMock.onPost("/short-urls").reply(({headers, data}) => {
|
|
35
|
+
const body = JSON.parse(data);
|
|
36
|
+
if (body.urlData && body.urlData.fullUrl === urlData.fullUrl && !body.urlData.method) {
|
|
37
|
+
return [200, {shortUrl: "https://btrz.ca/u/xyz", shortId: "xyz", fullUrl: urlData.fullUrl, createdAt: {}}];
|
|
38
|
+
}
|
|
39
|
+
return [400];
|
|
40
|
+
});
|
|
41
|
+
return api.notifications.shortUrls.create({token, jwtToken, urlData}).then((res) => {
|
|
42
|
+
expect(res.status).to.equal(200);
|
|
43
|
+
expect(res.data.fullUrl).to.equal("https://example.com/only");
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("should GET resolve shortId (returns 302)", () => {
|
|
48
|
+
axiosMock.onGet("/u/V1StGXR8_Z5j").reply(({headers}) => {
|
|
49
|
+
if (headers["x-api-key"] === token) {
|
|
50
|
+
return [302, {}, {location: "https://example.com/target"}];
|
|
51
|
+
}
|
|
52
|
+
return [401];
|
|
53
|
+
});
|
|
54
|
+
return api.notifications.shortUrls.getByShortId({token, shortId: "V1StGXR8_Z5j", maxRedirects: 0}).then((res) => {
|
|
55
|
+
expect(res.status).to.equal(302);
|
|
56
|
+
expect(res.headers.location || res.headers.Location).to.equal("https://example.com/target");
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
const {expect} = require("chai");
|
|
2
|
+
const {axiosMock, expectRequest} = require("./../../test-helpers.js");
|
|
3
|
+
const api = require("./../../../src/client.js").createApiClient({
|
|
4
|
+
baseURL: "http://test.com"
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
describe("operations/cancellation-settings", () => {
|
|
8
|
+
const token = "I owe you a token";
|
|
9
|
+
const jwtToken = "I owe you a JWT token";
|
|
10
|
+
|
|
11
|
+
afterEach(() => {
|
|
12
|
+
axiosMock.reset();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("should GET cancellation settings", () => {
|
|
16
|
+
axiosMock.onGet("/cancellation-settings").reply(expectRequest({
|
|
17
|
+
statusCode: 200,
|
|
18
|
+
token
|
|
19
|
+
}));
|
|
20
|
+
return api.operations.cancellationSettings.get({
|
|
21
|
+
token,
|
|
22
|
+
jwtToken
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("should PUT (update) cancellation settings", () => {
|
|
27
|
+
const data = {
|
|
28
|
+
cancellationWindowMinutes: 60,
|
|
29
|
+
allowCancellationAfterDeparture: false
|
|
30
|
+
};
|
|
31
|
+
axiosMock.onPut("/cancellation-settings").reply(expectRequest({
|
|
32
|
+
statusCode: 200,
|
|
33
|
+
token,
|
|
34
|
+
jwtToken
|
|
35
|
+
}));
|
|
36
|
+
return api.operations.cancellationSettings.update({
|
|
37
|
+
token,
|
|
38
|
+
jwtToken,
|
|
39
|
+
data
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("should send the request body when updating cancellation settings", async () => {
|
|
44
|
+
const data = {
|
|
45
|
+
cancellationWindowMinutes: 120,
|
|
46
|
+
allowCancellationAfterDeparture: true
|
|
47
|
+
};
|
|
48
|
+
axiosMock.onPut("/cancellation-settings").reply((config) => {
|
|
49
|
+
expect(JSON.parse(config.data)).to.eql(data);
|
|
50
|
+
return [200, {}];
|
|
51
|
+
});
|
|
52
|
+
const response = await api.operations.cancellationSettings.update({
|
|
53
|
+
token,
|
|
54
|
+
jwtToken,
|
|
55
|
+
data
|
|
56
|
+
});
|
|
57
|
+
return response;
|
|
58
|
+
});
|
|
59
|
+
});
|