@netresearch/node-magento-eqp 2.0.5 → 3.0.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/dist/Adapters.js +5 -5
- package/dist/Adapters.js.map +1 -1
- package/dist/AuthenticatedAdapter.js +7 -7
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/dist/services/CallbackService.js +1 -1
- package/dist/services/index.js +6 -6
- package/dist/services/index.js.map +1 -1
- package/dist/types/index.js +5 -5
- package/dist/types/index.js.map +1 -1
- package/dist/types/options.d.ts +1 -1
- package/package.json +18 -18
- package/tests/AuthenticatedAdapter.test.ts +0 -128
- package/tests/MockAdapter.ts +0 -14
- package/tests/index.test.ts +0 -41
- package/tests/mocks.ts +0 -200
- package/tests/services/CallbackService.test.ts +0 -119
- package/tests/services/FileService.test.ts +0 -66
- package/tests/services/KeySevice.test.ts +0 -73
- package/tests/services/PackageService.test.ts +0 -41
- package/tests/services/UserService.test.ts +0 -61
package/dist/Adapters.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AxiosAdapter = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const axios_1 =
|
|
5
|
+
const axios_1 = tslib_1.__importDefault(require("axios"));
|
|
6
6
|
class AxiosAdapter {
|
|
7
7
|
constructor(baseURL) {
|
|
8
8
|
this.client = axios_1.default.create({ baseURL });
|
|
@@ -11,22 +11,22 @@ class AxiosAdapter {
|
|
|
11
11
|
this.client.defaults.headers.common[header] = value;
|
|
12
12
|
}
|
|
13
13
|
get(url, config) {
|
|
14
|
-
return
|
|
14
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
15
15
|
return (yield this.client.get(url, config)).data;
|
|
16
16
|
});
|
|
17
17
|
}
|
|
18
18
|
post(url, body, config) {
|
|
19
|
-
return
|
|
19
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
20
20
|
return (yield this.client.post(url, body, config)).data;
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
put(url, body, config) {
|
|
24
|
-
return
|
|
24
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
25
25
|
return (yield this.client.put(url, body, config)).data;
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
28
|
delete(url, config) {
|
|
29
|
-
return
|
|
29
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
30
30
|
return (yield this.client.delete(url, config)).data;
|
|
31
31
|
});
|
|
32
32
|
}
|
package/dist/Adapters.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Adapters.js","sourceRoot":"","sources":["../src/Adapters.ts"],"names":[],"mappings":";;;;AAAA
|
|
1
|
+
{"version":3,"file":"Adapters.js","sourceRoot":"","sources":["../src/Adapters.ts"],"names":[],"mappings":";;;;AAAA,0DAAiE;AAGjE,MAAa,YAAY;IAGxB,YAAY,OAAe;QAC1B,IAAI,CAAC,MAAM,GAAG,eAAK,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;IACzC,CAAC;IAED,SAAS,CAAC,MAAc,EAAE,KAAa;QACtC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC;IACrD,CAAC;IAEK,GAAG,CAAI,GAAW,EAAE,MAA2B;;YACpD,OAAO,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC;QAClD,CAAC;KAAA;IAEK,IAAI,CAAI,GAAW,EAAE,IAAa,EAAE,MAA2B;;YACpE,OAAO,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC;QACzD,CAAC;KAAA;IAEK,GAAG,CAAI,GAAW,EAAE,IAAa,EAAE,MAA2B;;YACnE,OAAO,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC;QACxD,CAAC;KAAA;IAEK,MAAM,CAAI,GAAW,EAAE,MAA2B;;YACvD,OAAO,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC;QACrD,CAAC;KAAA;CACD;AA1BD,oCA0BC"}
|
|
@@ -12,31 +12,31 @@ class AuthenticatedAdapter {
|
|
|
12
12
|
return url.replace(/\|MAGE_ID\|/, this.mageId);
|
|
13
13
|
}
|
|
14
14
|
get(url, config) {
|
|
15
|
-
return
|
|
15
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
16
16
|
yield this.authenticate();
|
|
17
17
|
return this.baseAdapter.get(this.replaceMageIdInURL(url), config);
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
20
|
post(url, body, config) {
|
|
21
|
-
return
|
|
21
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
22
22
|
yield this.authenticate();
|
|
23
23
|
return this.baseAdapter.post(this.replaceMageIdInURL(url), body, config);
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
26
|
put(url, body, config) {
|
|
27
|
-
return
|
|
27
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
28
28
|
yield this.authenticate();
|
|
29
29
|
return this.baseAdapter.put(this.replaceMageIdInURL(url), body, config);
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
32
|
delete(url, config) {
|
|
33
|
-
return
|
|
33
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
34
34
|
yield this.authenticate();
|
|
35
35
|
return this.baseAdapter.delete(this.replaceMageIdInURL(url), config);
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
38
|
getMageId() {
|
|
39
|
-
return
|
|
39
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
40
40
|
yield this.authenticate();
|
|
41
41
|
return this.mageId;
|
|
42
42
|
});
|
|
@@ -48,7 +48,7 @@ class AuthenticatedAdapter {
|
|
|
48
48
|
*/
|
|
49
49
|
authenticate() {
|
|
50
50
|
var _a;
|
|
51
|
-
return
|
|
51
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
52
52
|
this.mageId = undefined;
|
|
53
53
|
const { expires_in, mage_id, ust } = yield this.baseAdapter.post('/app/session/token', { grant_type: 'session', expires_in: (_a = this.credentials.tokenTTL) !== null && _a !== void 0 ? _a : 7200 }, {
|
|
54
54
|
auth: {
|
|
@@ -60,7 +60,7 @@ class AuthenticatedAdapter {
|
|
|
60
60
|
this.baseAdapter.setHeader('Authorization', `Bearer ${ust}`);
|
|
61
61
|
if (this.credentials.autoRefresh) {
|
|
62
62
|
// Re-run this function 5 seconds before the token expires
|
|
63
|
-
setTimeout(() =>
|
|
63
|
+
setTimeout(() => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
64
64
|
this.authenticated = false;
|
|
65
65
|
yield this.authenticate();
|
|
66
66
|
}), expires_in * 1000 - 5);
|
package/dist/index.js
CHANGED
|
@@ -14,9 +14,13 @@ var Adapters_2 = require("./Adapters");
|
|
|
14
14
|
Object.defineProperty(exports, "AxiosAdapter", { enumerable: true, get: function () { return Adapters_2.AxiosAdapter; } });
|
|
15
15
|
var AuthenticatedAdapter_2 = require("./AuthenticatedAdapter");
|
|
16
16
|
Object.defineProperty(exports, "AuthenticatedAdapter", { enumerable: true, get: function () { return AuthenticatedAdapter_2.AuthenticatedAdapter; } });
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
tslib_1.__exportStar(require("./services"), exports);
|
|
18
|
+
tslib_1.__exportStar(require("./types"), exports);
|
|
19
19
|
class EQP {
|
|
20
|
+
/** The authenticated user's Magento ID */
|
|
21
|
+
get mageId() {
|
|
22
|
+
return this.adapter.mageId;
|
|
23
|
+
}
|
|
20
24
|
constructor(options) {
|
|
21
25
|
var _a, _b, _c;
|
|
22
26
|
this.adapter = new AuthenticatedAdapter_1.AuthenticatedAdapter((_a = options.adapter) !== null && _a !== void 0 ? _a : new Adapters_1.AxiosAdapter(`https://developer${((_b = options.environment) !== null && _b !== void 0 ? _b : 'production') === 'staging' ? '-stg' : ''}-api.magento.com/rest/v1`), {
|
|
@@ -32,10 +36,6 @@ class EQP {
|
|
|
32
36
|
this.reportService = new ReportService_1.ReportService(this.adapter);
|
|
33
37
|
this.packageService = new PackageService_1.PackageService(this.adapter);
|
|
34
38
|
}
|
|
35
|
-
/** The authenticated user's Magento ID */
|
|
36
|
-
get mageId() {
|
|
37
|
-
return this.adapter.mageId;
|
|
38
|
-
}
|
|
39
39
|
}
|
|
40
40
|
exports.EQP = EQP;
|
|
41
41
|
exports.default = EQP;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAAA,yCAA0C;AAC1C,iEAA8D;AAC9D,gEAA6D;AAC7D,wDAAqD;AACrD,sDAAmD;AACnD,8DAA2D;AAC3D,4DAAyD;AACzD,wDAAqD;AAGrD,uCAA0C;AAAjC,wGAAA,YAAY,OAAA;AACrB,+DAA8D;AAArD,4HAAA,oBAAoB,OAAA;AAC7B,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAAA,yCAA0C;AAC1C,iEAA8D;AAC9D,gEAA6D;AAC7D,wDAAqD;AACrD,sDAAmD;AACnD,8DAA2D;AAC3D,4DAAyD;AACzD,wDAAqD;AAGrD,uCAA0C;AAAjC,wGAAA,YAAY,OAAA;AACrB,+DAA8D;AAArD,4HAAA,oBAAoB,OAAA;AAC7B,qDAA2B;AAC3B,kDAAwB;AAExB,MAAa,GAAG;IAUf,0CAA0C;IAC1C,IAAI,MAAM;QACT,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;IAC5B,CAAC;IAED,YAAY,OAAmB;;QAC9B,IAAI,CAAC,OAAO,GAAG,IAAI,2CAAoB,CACtC,MAAA,OAAO,CAAC,OAAO,mCACd,IAAI,uBAAY,CAAC,oBAAoB,CAAC,MAAA,OAAO,CAAC,WAAW,mCAAI,YAAY,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,0BAA0B,CAAC,EAClI;YACC,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,WAAW,EAAE,MAAA,OAAO,CAAC,WAAW,mCAAI,KAAK;YACzC,QAAQ,EAAE,OAAO,CAAC,SAAS;SAC3B,CACD,CAAC;QAEF,IAAI,CAAC,WAAW,GAAG,IAAI,yBAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACjD,IAAI,CAAC,WAAW,GAAG,IAAI,yBAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACjD,IAAI,CAAC,UAAU,GAAG,IAAI,uBAAU,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC/C,IAAI,CAAC,eAAe,GAAG,IAAI,iCAAe,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QAC/D,IAAI,CAAC,aAAa,GAAG,IAAI,6BAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACrD,IAAI,CAAC,cAAc,GAAG,IAAI,+BAAc,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACxD,CAAC;CACD;AAlCD,kBAkCC;AAED,kBAAe,GAAG,CAAC"}
|
|
@@ -16,7 +16,7 @@ class CallbackService {
|
|
|
16
16
|
return this.eqp.userService.updateUser({ api_callbacks: [{ name, url, username, password }] });
|
|
17
17
|
}
|
|
18
18
|
parseCallback(event) {
|
|
19
|
-
return
|
|
19
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
20
20
|
switch (event.callback_event) {
|
|
21
21
|
case 'eqp_status_update': {
|
|
22
22
|
const { update_info: updateInfo } = event;
|
package/dist/services/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
tslib_1.__exportStar(require("./CallbackService"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./FileService"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./KeyService"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./PackageService"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./ReportService"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./UserService"), exports);
|
|
10
10
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":";;;AAAA,4DAAkC;AAClC,wDAA8B;AAC9B,uDAA6B;AAC7B,2DAAiC;AACjC,0DAAgC;AAChC,wDAA8B"}
|
package/dist/types/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
tslib_1.__exportStar(require("./callbacks"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./common"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./options"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./packages"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./users"), exports);
|
|
9
9
|
//# sourceMappingURL=index.js.map
|
package/dist/types/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;AAAA,sDAA4B;AAC5B,mDAAyB;AACzB,oDAA0B;AAC1B,qDAA2B;AAC3B,kDAAwB"}
|
package/dist/types/options.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netresearch/node-magento-eqp",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Simple API wrapper around the Magento Marketplace EQP API",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -21,26 +21,26 @@
|
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@types/jest": "^26.0.24",
|
|
24
|
-
"@types/node": "8.10.66",
|
|
25
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
26
|
-
"@typescript-eslint/parser": "^
|
|
27
|
-
"axios-mock-adapter": "^1.
|
|
28
|
-
"eslint": "^
|
|
29
|
-
"eslint-config-prettier": "^8.
|
|
30
|
-
"eslint-plugin-editorconfig": "^
|
|
31
|
-
"eslint-plugin-prettier": "^
|
|
32
|
-
"jest": "^
|
|
33
|
-
"prettier": "^2.
|
|
34
|
-
"ts-jest": "^
|
|
35
|
-
"ts-node": "^9.1
|
|
36
|
-
"typedoc": "^0.21
|
|
37
|
-
"typescript": "^4.
|
|
24
|
+
"@types/node": "^8.10.66",
|
|
25
|
+
"@typescript-eslint/eslint-plugin": "^5.44.0",
|
|
26
|
+
"@typescript-eslint/parser": "^5.44.0",
|
|
27
|
+
"axios-mock-adapter": "^1.21.2",
|
|
28
|
+
"eslint": "^8.28.0",
|
|
29
|
+
"eslint-config-prettier": "^8.5.0",
|
|
30
|
+
"eslint-plugin-editorconfig": "^4.0.2",
|
|
31
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
32
|
+
"jest": "^29.3.1",
|
|
33
|
+
"prettier": "^2.8.0",
|
|
34
|
+
"ts-jest": "^29.0.3",
|
|
35
|
+
"ts-node": "^10.9.1",
|
|
36
|
+
"typedoc": "^0.23.21",
|
|
37
|
+
"typescript": "^4.9.3"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"axios": "^
|
|
41
|
-
"tslib": "^2.
|
|
40
|
+
"axios": "^1.2.0",
|
|
41
|
+
"tslib": "^2.4.1"
|
|
42
42
|
},
|
|
43
43
|
"engines": {
|
|
44
|
-
"node": ">=
|
|
44
|
+
"node": ">=14"
|
|
45
45
|
}
|
|
46
46
|
}
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import MockAdapter from 'axios-mock-adapter/types';
|
|
2
|
-
import { AuthenticatedAdapter } from '../src/AuthenticatedAdapter';
|
|
3
|
-
import { AxiosMockAdapter } from './MockAdapter';
|
|
4
|
-
|
|
5
|
-
describe('AuthenticatedAdapter', () => {
|
|
6
|
-
const mock = new AxiosMockAdapter('http://localhost');
|
|
7
|
-
|
|
8
|
-
const mockAuth = (mock: MockAdapter) => {
|
|
9
|
-
mock.onPost('/app/session/token', {
|
|
10
|
-
grant_type: 'session',
|
|
11
|
-
expires_in: 7200
|
|
12
|
-
}).reply(async (config) => {
|
|
13
|
-
if (config.auth) {
|
|
14
|
-
return [200, { ust: 'TOKEN', expires_in: 7200, mage_id: 'MAGE_ID' }];
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return [400];
|
|
18
|
-
});
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const subject = new AuthenticatedAdapter(mock, {
|
|
22
|
-
appSecret: 'pass',
|
|
23
|
-
appId: 'id'
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
test('Base adapter is correct', async () => {
|
|
27
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
28
|
-
// @ts-ignore
|
|
29
|
-
expect(subject.baseAdapter).toHaveProperty('get');
|
|
30
|
-
|
|
31
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
32
|
-
// @ts-ignore
|
|
33
|
-
expect(subject.baseAdapter).toHaveProperty('post');
|
|
34
|
-
|
|
35
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
36
|
-
// @ts-ignore
|
|
37
|
-
expect(subject.baseAdapter).toHaveProperty('put');
|
|
38
|
-
|
|
39
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
40
|
-
// @ts-ignore
|
|
41
|
-
expect(subject.baseAdapter).toHaveProperty('delete');
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
test('GET requests', async () => {
|
|
45
|
-
mockAuth(mock.mockAdapter);
|
|
46
|
-
|
|
47
|
-
mock.mockAdapter
|
|
48
|
-
.onGet(
|
|
49
|
-
'/test',
|
|
50
|
-
undefined,
|
|
51
|
-
expect.objectContaining({
|
|
52
|
-
Authorization: expect.stringMatching('Bearer TOKEN')
|
|
53
|
-
})
|
|
54
|
-
)
|
|
55
|
-
.reply(200, {});
|
|
56
|
-
|
|
57
|
-
const response = await subject.get('/test');
|
|
58
|
-
|
|
59
|
-
expect(response).toBeDefined();
|
|
60
|
-
expect(response).toMatchObject({});
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
test('POST requests', async () => {
|
|
64
|
-
mockAuth(mock.mockAdapter);
|
|
65
|
-
|
|
66
|
-
mock.mockAdapter
|
|
67
|
-
.onPost(
|
|
68
|
-
'/test',
|
|
69
|
-
undefined,
|
|
70
|
-
expect.objectContaining({
|
|
71
|
-
Authorization: expect.stringMatching('Bearer TOKEN')
|
|
72
|
-
})
|
|
73
|
-
)
|
|
74
|
-
.reply(200, {});
|
|
75
|
-
|
|
76
|
-
const response = await subject.post('/test', {});
|
|
77
|
-
|
|
78
|
-
expect(response).toBeDefined();
|
|
79
|
-
expect(response).toMatchObject({});
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
test('PUT requests', async () => {
|
|
83
|
-
mockAuth(mock.mockAdapter);
|
|
84
|
-
|
|
85
|
-
mock.mockAdapter
|
|
86
|
-
.onPut(
|
|
87
|
-
'/test',
|
|
88
|
-
undefined,
|
|
89
|
-
expect.objectContaining({
|
|
90
|
-
Authorization: expect.stringMatching('Bearer TOKEN')
|
|
91
|
-
})
|
|
92
|
-
)
|
|
93
|
-
.reply(200, {});
|
|
94
|
-
|
|
95
|
-
const response = await subject.put('/test', {});
|
|
96
|
-
|
|
97
|
-
expect(response).toBeDefined();
|
|
98
|
-
expect(response).toMatchObject({});
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
test('DELETE requests', async () => {
|
|
102
|
-
mockAuth(mock.mockAdapter);
|
|
103
|
-
|
|
104
|
-
mock.mockAdapter
|
|
105
|
-
.onDelete(
|
|
106
|
-
'/test',
|
|
107
|
-
undefined,
|
|
108
|
-
expect.objectContaining({
|
|
109
|
-
Authorization: expect.stringMatching('Bearer TOKEN')
|
|
110
|
-
})
|
|
111
|
-
)
|
|
112
|
-
.reply(200, {});
|
|
113
|
-
|
|
114
|
-
const response = await subject.delete('/test');
|
|
115
|
-
|
|
116
|
-
expect(response).toBeDefined();
|
|
117
|
-
expect(response).toMatchObject({});
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
test("Get's the Mage ID", async () => {
|
|
121
|
-
mockAuth(mock.mockAdapter);
|
|
122
|
-
|
|
123
|
-
const response = await subject.getMageId();
|
|
124
|
-
|
|
125
|
-
expect(response).toBeDefined();
|
|
126
|
-
expect(response).toMatch('MAGE_ID');
|
|
127
|
-
});
|
|
128
|
-
});
|
package/tests/MockAdapter.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import MockAdapter from 'axios-mock-adapter';
|
|
2
|
-
import { AxiosAdapter } from '../src/Adapters';
|
|
3
|
-
|
|
4
|
-
export class AxiosMockAdapter extends AxiosAdapter {
|
|
5
|
-
mockAdapter: MockAdapter;
|
|
6
|
-
|
|
7
|
-
constructor(baseURL: string) {
|
|
8
|
-
super(baseURL);
|
|
9
|
-
|
|
10
|
-
this.mockAdapter = new MockAdapter(this.client, {
|
|
11
|
-
onNoMatch: 'throwException'
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
}
|
package/tests/index.test.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import MockAdapter from 'axios-mock-adapter/types';
|
|
2
|
-
import EQP from '../src';
|
|
3
|
-
import { AxiosMockAdapter } from './MockAdapter';
|
|
4
|
-
import { sampleUser } from './mocks';
|
|
5
|
-
|
|
6
|
-
describe('EQP', () => {
|
|
7
|
-
const mock = new AxiosMockAdapter('http://localhost');
|
|
8
|
-
|
|
9
|
-
const mockAuth = (mock: MockAdapter) => {
|
|
10
|
-
mock.onPost('/app/session/token', {
|
|
11
|
-
grant_type: 'session',
|
|
12
|
-
expires_in: 7200
|
|
13
|
-
}).reply(200, { ust: 'TOKEN', expires_in: 7200, mage_id: 'MAGE_ID' });
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const subject = new EQP({
|
|
17
|
-
appSecret: 'pass',
|
|
18
|
-
appId: 'id',
|
|
19
|
-
adapter: mock
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
test('get mageId', async () => {
|
|
23
|
-
mockAuth(mock.mockAdapter);
|
|
24
|
-
|
|
25
|
-
mock.mockAdapter
|
|
26
|
-
.onGet(
|
|
27
|
-
'/users/MAGE_ID',
|
|
28
|
-
undefined,
|
|
29
|
-
expect.objectContaining({
|
|
30
|
-
Authorization: expect.stringMatching('Bearer TOKEN')
|
|
31
|
-
})
|
|
32
|
-
)
|
|
33
|
-
.reply(200, sampleUser);
|
|
34
|
-
|
|
35
|
-
// Already tested in tests/services/UserService.test.ts
|
|
36
|
-
await subject.userService.getUser(false);
|
|
37
|
-
|
|
38
|
-
expect(subject.mageId).toBeDefined();
|
|
39
|
-
expect(subject.mageId).toEqual(sampleUser.mage_id);
|
|
40
|
-
});
|
|
41
|
-
});
|
package/tests/mocks.ts
DELETED
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
import { EQPStatusUpdateEvent, File, Magento1Key, Magento2Key, MalwareScanCompleteEvent, Package, User, UserSummary } from '../src';
|
|
2
|
-
|
|
3
|
-
export const sampleFile: File = {
|
|
4
|
-
content_type: '',
|
|
5
|
-
file_hash: '',
|
|
6
|
-
file_upload_id: '0',
|
|
7
|
-
filename: '',
|
|
8
|
-
is_profile_image: false,
|
|
9
|
-
malware_status: 'pass',
|
|
10
|
-
size: 0,
|
|
11
|
-
submission_ids: ['0'],
|
|
12
|
-
url: ''
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export const sampleUser: User = {
|
|
16
|
-
api_callbacks: [],
|
|
17
|
-
company_profile: {
|
|
18
|
-
addresses: [],
|
|
19
|
-
bio: '',
|
|
20
|
-
created_at: '',
|
|
21
|
-
modified_at: '',
|
|
22
|
-
name: '',
|
|
23
|
-
primary_email: '',
|
|
24
|
-
social_media_info: {},
|
|
25
|
-
support_email: '',
|
|
26
|
-
website_url: ''
|
|
27
|
-
},
|
|
28
|
-
email: '',
|
|
29
|
-
first_name: '',
|
|
30
|
-
last_name: '',
|
|
31
|
-
eqp_api: { is_eligible: false, has_credentials: false },
|
|
32
|
-
extension_share_percent: 0,
|
|
33
|
-
has_accepted_tos: false,
|
|
34
|
-
has_completed_profile: false,
|
|
35
|
-
install_share_percent: 0,
|
|
36
|
-
is_company: false,
|
|
37
|
-
locale: '',
|
|
38
|
-
mage_id: 'MAGE_ID',
|
|
39
|
-
partner_level: 0,
|
|
40
|
-
payment_info: '',
|
|
41
|
-
payment_type: 0,
|
|
42
|
-
personal_profile: {
|
|
43
|
-
addresses: [],
|
|
44
|
-
bio: '',
|
|
45
|
-
created_at: '',
|
|
46
|
-
last_logged_in: '',
|
|
47
|
-
modified_at: '',
|
|
48
|
-
social_media_info: [],
|
|
49
|
-
website_url: ''
|
|
50
|
-
},
|
|
51
|
-
privacy_policy_url: '',
|
|
52
|
-
profile_image_artifact: {
|
|
53
|
-
content_type: '',
|
|
54
|
-
file_hash: '',
|
|
55
|
-
file_upload_id: '',
|
|
56
|
-
filename: '',
|
|
57
|
-
malware_status: '',
|
|
58
|
-
size: 0,
|
|
59
|
-
url: ''
|
|
60
|
-
},
|
|
61
|
-
screen_name: '',
|
|
62
|
-
show_extension_workflow: false,
|
|
63
|
-
show_theme_workflow: false,
|
|
64
|
-
support_share_percent: 0,
|
|
65
|
-
tax_review_status: 100,
|
|
66
|
-
tax_withhold_percent: 100,
|
|
67
|
-
taxpayer_type: 0,
|
|
68
|
-
theme_share_percent: 100,
|
|
69
|
-
timezone: '',
|
|
70
|
-
tos_accepted_date: '',
|
|
71
|
-
tos_accepted_version: '',
|
|
72
|
-
vendor_name: ''
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
export const sampleUserSummary: UserSummary = {
|
|
76
|
-
email: '',
|
|
77
|
-
first_name: '',
|
|
78
|
-
last_name: '',
|
|
79
|
-
has_accepted_tos: false,
|
|
80
|
-
has_completed_profile: false,
|
|
81
|
-
mage_id: 'MAGE_ID',
|
|
82
|
-
profile_image_artifact: {
|
|
83
|
-
content_type: '',
|
|
84
|
-
file_hash: '',
|
|
85
|
-
file_upload_id: '',
|
|
86
|
-
filename: '',
|
|
87
|
-
malware_status: '',
|
|
88
|
-
size: 0,
|
|
89
|
-
url: ''
|
|
90
|
-
},
|
|
91
|
-
screen_name: ''
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
export const samplePackage: Package = {
|
|
95
|
-
actions_now_available: {
|
|
96
|
-
marketing: [],
|
|
97
|
-
overall: [],
|
|
98
|
-
technical: []
|
|
99
|
-
},
|
|
100
|
-
artifact: sampleFile,
|
|
101
|
-
browser_os_compatibility: [],
|
|
102
|
-
browsers: [],
|
|
103
|
-
categories: [],
|
|
104
|
-
created_at: '',
|
|
105
|
-
custom_license_name: '',
|
|
106
|
-
custom_license_url: '',
|
|
107
|
-
documentation_artifacts: {
|
|
108
|
-
user: [],
|
|
109
|
-
installation: [],
|
|
110
|
-
reference: []
|
|
111
|
-
},
|
|
112
|
-
eqp_status: {
|
|
113
|
-
marketing: '',
|
|
114
|
-
overall: '',
|
|
115
|
-
technical: ''
|
|
116
|
-
},
|
|
117
|
-
external_services: {
|
|
118
|
-
is_saas: false,
|
|
119
|
-
items: []
|
|
120
|
-
},
|
|
121
|
-
item_id: '0',
|
|
122
|
-
latest_launch_date: '',
|
|
123
|
-
launch_on_approval: true,
|
|
124
|
-
license_type: '',
|
|
125
|
-
long_description: '',
|
|
126
|
-
mage_id: 'MAGE_ID',
|
|
127
|
-
marketing_options: {
|
|
128
|
-
custom_implementation_ui: false,
|
|
129
|
-
included_external_service_contracts: false,
|
|
130
|
-
included_service_contracts: false,
|
|
131
|
-
released_with_setup_scripts: false,
|
|
132
|
-
support_responsive_design: false,
|
|
133
|
-
support_test_coverage: false,
|
|
134
|
-
support_web_api: false
|
|
135
|
-
},
|
|
136
|
-
max_version_launched: [],
|
|
137
|
-
media_artifacts: {
|
|
138
|
-
gallery_images: [],
|
|
139
|
-
icon_image: [],
|
|
140
|
-
video_urls: []
|
|
141
|
-
},
|
|
142
|
-
modified_at: '',
|
|
143
|
-
name: '',
|
|
144
|
-
platform: '',
|
|
145
|
-
prices: [],
|
|
146
|
-
process_as_patch: '',
|
|
147
|
-
release_notes: '',
|
|
148
|
-
requested_launch_date: '',
|
|
149
|
-
shared_packages: [],
|
|
150
|
-
short_description: '',
|
|
151
|
-
sku: '',
|
|
152
|
-
stability: '',
|
|
153
|
-
submission_counts: {
|
|
154
|
-
marketing_live_update_count: 0,
|
|
155
|
-
marketing_submission_count: 0,
|
|
156
|
-
technical_submission_count: 0
|
|
157
|
-
},
|
|
158
|
-
submission_id: '0',
|
|
159
|
-
support_tiers: [],
|
|
160
|
-
technical_options: {
|
|
161
|
-
page_builder_extends_content_type: false,
|
|
162
|
-
page_builder_new_content_type: false,
|
|
163
|
-
page_builder_used_for_content_creation: false
|
|
164
|
-
},
|
|
165
|
-
type: '',
|
|
166
|
-
url_key: '',
|
|
167
|
-
version: '',
|
|
168
|
-
version_compatibility: [],
|
|
169
|
-
original_launch_date: ''
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
export const sampleMalwareScanCompletedEvent: MalwareScanCompleteEvent = {
|
|
173
|
-
callback_event: 'malware_scan_complete',
|
|
174
|
-
update_info: {
|
|
175
|
-
file_upload_id: '0',
|
|
176
|
-
tool_result: 'pass'
|
|
177
|
-
}
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
export const sampleEQPStatusUpdateEvent: EQPStatusUpdateEvent = {
|
|
181
|
-
callback_event: 'eqp_status_update',
|
|
182
|
-
update_info: {
|
|
183
|
-
eqp_state: 'pass',
|
|
184
|
-
eqp_flow: '',
|
|
185
|
-
item_id: '0',
|
|
186
|
-
submission_id: '0'
|
|
187
|
-
}
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
export const sampleMagento1Key: Magento1Key = {
|
|
191
|
-
product_key: '',
|
|
192
|
-
product_name: 'Magento 1'
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
export const sampleMagento2Key: Magento2Key = {
|
|
196
|
-
is_enabled: true,
|
|
197
|
-
label: 'Magento 2 Sample key',
|
|
198
|
-
password_key: 'blah',
|
|
199
|
-
user_key: 'blah'
|
|
200
|
-
};
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import MockAdapter from 'axios-mock-adapter/types';
|
|
2
|
-
import EQP, { RawCallbackEvent } from '../../src';
|
|
3
|
-
import { AxiosMockAdapter } from '../MockAdapter';
|
|
4
|
-
import { sampleEQPStatusUpdateEvent, sampleFile, sampleMalwareScanCompletedEvent, samplePackage } from '../mocks';
|
|
5
|
-
|
|
6
|
-
describe('CallbackService', () => {
|
|
7
|
-
const mock = new AxiosMockAdapter('http://localhost');
|
|
8
|
-
|
|
9
|
-
const mockAuth = (mock: MockAdapter) => {
|
|
10
|
-
mock.onPost('/app/session/token', {
|
|
11
|
-
grant_type: 'session',
|
|
12
|
-
expires_in: 7200
|
|
13
|
-
}).reply(200, { ust: 'TOKEN', expires_in: 7200, mage_id: 'MAGE_ID' });
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const eqp = new EQP({
|
|
17
|
-
appSecret: 'pass',
|
|
18
|
-
appId: 'id',
|
|
19
|
-
adapter: mock
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
const subject = eqp.callbackService;
|
|
23
|
-
|
|
24
|
-
test('registerCallback() with success', async () => {
|
|
25
|
-
mockAuth(mock.mockAdapter);
|
|
26
|
-
|
|
27
|
-
mock.mockAdapter
|
|
28
|
-
.onPut(
|
|
29
|
-
'/users/MAGE_ID',
|
|
30
|
-
undefined,
|
|
31
|
-
expect.objectContaining({
|
|
32
|
-
Authorization: expect.stringMatching('Bearer TOKEN')
|
|
33
|
-
})
|
|
34
|
-
)
|
|
35
|
-
.reply(200, {});
|
|
36
|
-
|
|
37
|
-
const response = await subject.registerCallback('test', 'test', 'test', 'test');
|
|
38
|
-
|
|
39
|
-
expect(response).toBeDefined();
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
test('parseCallback() with MalwareScanCompletedEvent', async () => {
|
|
43
|
-
mockAuth(mock.mockAdapter);
|
|
44
|
-
|
|
45
|
-
mock.mockAdapter
|
|
46
|
-
.onGet(
|
|
47
|
-
'/files/uploads/0',
|
|
48
|
-
undefined,
|
|
49
|
-
expect.objectContaining({
|
|
50
|
-
Authorization: expect.stringMatching('Bearer TOKEN')
|
|
51
|
-
})
|
|
52
|
-
)
|
|
53
|
-
.reply(200, sampleFile);
|
|
54
|
-
|
|
55
|
-
mock.mockAdapter
|
|
56
|
-
.onGet(
|
|
57
|
-
'/products/packages/0',
|
|
58
|
-
undefined,
|
|
59
|
-
expect.objectContaining({
|
|
60
|
-
Authorization: expect.stringMatching('Bearer TOKEN')
|
|
61
|
-
})
|
|
62
|
-
)
|
|
63
|
-
.reply(200, samplePackage);
|
|
64
|
-
|
|
65
|
-
const response = await subject.parseCallback(sampleMalwareScanCompletedEvent);
|
|
66
|
-
|
|
67
|
-
expect(response).toBeDefined();
|
|
68
|
-
expect(response.file).toEqual(sampleFile);
|
|
69
|
-
expect(response.submissions).toEqual(expect.arrayContaining([samplePackage]));
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
test('parseCallback() with EQPStatusUpdateEvent', async () => {
|
|
73
|
-
mockAuth(mock.mockAdapter);
|
|
74
|
-
|
|
75
|
-
mock.mockAdapter
|
|
76
|
-
.onGet(
|
|
77
|
-
'/products/packages/items/0',
|
|
78
|
-
undefined,
|
|
79
|
-
expect.objectContaining({
|
|
80
|
-
Authorization: expect.stringMatching('Bearer TOKEN')
|
|
81
|
-
})
|
|
82
|
-
)
|
|
83
|
-
.reply(200, samplePackage);
|
|
84
|
-
|
|
85
|
-
mock.mockAdapter
|
|
86
|
-
.onGet(
|
|
87
|
-
'/products/packages/0',
|
|
88
|
-
undefined,
|
|
89
|
-
expect.objectContaining({
|
|
90
|
-
Authorization: expect.stringMatching('Bearer TOKEN')
|
|
91
|
-
})
|
|
92
|
-
)
|
|
93
|
-
.reply(200, samplePackage);
|
|
94
|
-
|
|
95
|
-
const response = await subject.parseCallback(sampleEQPStatusUpdateEvent);
|
|
96
|
-
|
|
97
|
-
expect(response).toBeDefined();
|
|
98
|
-
expect(response.flow).toEqual('');
|
|
99
|
-
expect(response.item).toMatchObject(samplePackage);
|
|
100
|
-
expect(response.submission).toMatchObject(samplePackage);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
test('parseCallback() with unknown event', async () => {
|
|
104
|
-
mockAuth(mock.mockAdapter);
|
|
105
|
-
|
|
106
|
-
expect.assertions(1);
|
|
107
|
-
|
|
108
|
-
const sampleCallback: RawCallbackEvent = {
|
|
109
|
-
callback_event: 'unknown',
|
|
110
|
-
update_info: {}
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
// TypeScript doesn't find matching overloads here, so we just gotta @ts-ignore our way through here
|
|
114
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
115
|
-
// @ts-ignore
|
|
116
|
-
|
|
117
|
-
return subject.parseCallback(sampleCallback).catch((e) => expect(e.message).toMatch(`unknown callback_event "${sampleCallback.callback_event}"`));
|
|
118
|
-
});
|
|
119
|
-
});
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import MockAdapter from 'axios-mock-adapter/types';
|
|
2
|
-
import { AuthenticatedAdapter } from '../../src/AuthenticatedAdapter';
|
|
3
|
-
import { FileService } from '../../src/services/FileService';
|
|
4
|
-
import { File } from '../../src/types';
|
|
5
|
-
import { AxiosMockAdapter } from '../MockAdapter';
|
|
6
|
-
import { sampleFile } from '../mocks';
|
|
7
|
-
|
|
8
|
-
describe('FileService', () => {
|
|
9
|
-
const mock = new AxiosMockAdapter('http://localhost');
|
|
10
|
-
|
|
11
|
-
const mockAuth = (mock: MockAdapter) => {
|
|
12
|
-
mock.onPost('/app/session/token', {
|
|
13
|
-
grant_type: 'session',
|
|
14
|
-
expires_in: 7200
|
|
15
|
-
}).reply(200, { ust: 'TOKEN', expires_in: 7200, mage_id: 'MAGE_ID' });
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const authAdapter = new AuthenticatedAdapter(mock, {
|
|
19
|
-
appSecret: 'pass',
|
|
20
|
-
appId: 'id'
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
const subject = new FileService(authAdapter);
|
|
24
|
-
|
|
25
|
-
test('getFile() with success', async () => {
|
|
26
|
-
mockAuth(mock.mockAdapter);
|
|
27
|
-
|
|
28
|
-
mock.mockAdapter
|
|
29
|
-
.onGet(
|
|
30
|
-
'/files/uploads/someId',
|
|
31
|
-
undefined,
|
|
32
|
-
expect.objectContaining({
|
|
33
|
-
Authorization: expect.stringMatching('Bearer TOKEN')
|
|
34
|
-
})
|
|
35
|
-
)
|
|
36
|
-
.reply(200, sampleFile);
|
|
37
|
-
|
|
38
|
-
const response = await subject.getFile('someId');
|
|
39
|
-
|
|
40
|
-
expect(response).toBeDefined();
|
|
41
|
-
expect(response).toMatchObject<File>(sampleFile);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
test('getFile() with error', async () => {
|
|
45
|
-
mockAuth(mock.mockAdapter);
|
|
46
|
-
|
|
47
|
-
try {
|
|
48
|
-
mock.mockAdapter
|
|
49
|
-
.onGet(
|
|
50
|
-
'/files/uploads/someId',
|
|
51
|
-
undefined,
|
|
52
|
-
expect.objectContaining({
|
|
53
|
-
Authorization: expect.stringMatching('Bearer TOKEN')
|
|
54
|
-
})
|
|
55
|
-
)
|
|
56
|
-
.reply(400, {
|
|
57
|
-
code: 1208,
|
|
58
|
-
message: 'Insufficient information for Technical Submission'
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
await subject.getFile('someId');
|
|
62
|
-
} catch (e) {
|
|
63
|
-
expect(e.toString()).toMatch('Error: Request failed with status code 400');
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
});
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import MockAdapter from 'axios-mock-adapter/types';
|
|
2
|
-
import { AuthenticatedAdapter } from '../../src/AuthenticatedAdapter';
|
|
3
|
-
import { KeyService } from '../../src/services/KeyService';
|
|
4
|
-
import { AxiosMockAdapter } from '../MockAdapter';
|
|
5
|
-
import { sampleMagento1Key, sampleMagento2Key } from '../mocks';
|
|
6
|
-
|
|
7
|
-
describe('KeyService', () => {
|
|
8
|
-
const mock = new AxiosMockAdapter('http://localhost');
|
|
9
|
-
|
|
10
|
-
const mockAuth = (mock: MockAdapter) => {
|
|
11
|
-
mock.onPost('/app/session/token', {
|
|
12
|
-
grant_type: 'session',
|
|
13
|
-
expires_in: 7200
|
|
14
|
-
}).reply(200, { ust: 'TOKEN', expires_in: 7200, mage_id: 'MAGE_ID' });
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
const authAdapter = new AuthenticatedAdapter(mock, {
|
|
18
|
-
appSecret: 'pass',
|
|
19
|
-
appId: 'id'
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
const subject = new KeyService(authAdapter);
|
|
23
|
-
|
|
24
|
-
test('getKeys() with success', async () => {
|
|
25
|
-
mockAuth(mock.mockAdapter);
|
|
26
|
-
|
|
27
|
-
mock.mockAdapter
|
|
28
|
-
.onGet(
|
|
29
|
-
'/users/MAGE_ID/keys',
|
|
30
|
-
undefined,
|
|
31
|
-
expect.objectContaining({
|
|
32
|
-
Authorization: expect.stringMatching('Bearer TOKEN')
|
|
33
|
-
})
|
|
34
|
-
)
|
|
35
|
-
.reply((config) => {
|
|
36
|
-
if (config.params.type === 'm1') {
|
|
37
|
-
return [200, { m1: [sampleMagento1Key] }];
|
|
38
|
-
} else if (config.params.type === 'm2') {
|
|
39
|
-
return [200, { m1: [sampleMagento2Key] }];
|
|
40
|
-
} else {
|
|
41
|
-
return [200, { m1: [sampleMagento1Key], m2: [sampleMagento2Key] }];
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
const response = await subject.getKeys({ type: 'm1' });
|
|
46
|
-
|
|
47
|
-
expect(response).toBeDefined();
|
|
48
|
-
expect(response.m1).toEqual(expect.arrayContaining([sampleMagento1Key]));
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
test('getKeys() with error', async () => {
|
|
52
|
-
mockAuth(mock.mockAdapter);
|
|
53
|
-
|
|
54
|
-
try {
|
|
55
|
-
mock.mockAdapter
|
|
56
|
-
.onGet(
|
|
57
|
-
'/users/MAGE_ID/keys',
|
|
58
|
-
undefined,
|
|
59
|
-
expect.objectContaining({
|
|
60
|
-
Authorization: expect.stringMatching('Bearer TOKEN')
|
|
61
|
-
})
|
|
62
|
-
)
|
|
63
|
-
.reply(400, {
|
|
64
|
-
code: 1208,
|
|
65
|
-
message: 'Insufficient information for Technical Submission'
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
await subject.getKeys({ type: 'm1' });
|
|
69
|
-
} catch (e) {
|
|
70
|
-
expect(e.toString()).toMatch('Error: Request failed with status code 400');
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
});
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import MockAdapter from 'axios-mock-adapter/types';
|
|
2
|
-
import { AuthenticatedAdapter, PackageService } from '../../src';
|
|
3
|
-
import { AxiosMockAdapter } from '../MockAdapter';
|
|
4
|
-
import { samplePackage } from '../mocks';
|
|
5
|
-
|
|
6
|
-
describe('PackageService', () => {
|
|
7
|
-
const mock = new AxiosMockAdapter('http://localhost');
|
|
8
|
-
|
|
9
|
-
const mockAuth = (mock: MockAdapter) => {
|
|
10
|
-
mock.onPost('/app/session/token', {
|
|
11
|
-
grant_type: 'session',
|
|
12
|
-
expires_in: 7200
|
|
13
|
-
}).reply(200, { ust: 'TOKEN', expires_in: 7200, mage_id: 'MAGE_ID' });
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const authAdapter = new AuthenticatedAdapter(mock, {
|
|
17
|
-
appSecret: 'pass',
|
|
18
|
-
appId: 'id'
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
const subject = new PackageService(authAdapter);
|
|
22
|
-
|
|
23
|
-
test('getPackages()', async () => {
|
|
24
|
-
mockAuth(mock.mockAdapter);
|
|
25
|
-
|
|
26
|
-
mock.mockAdapter
|
|
27
|
-
.onGet(
|
|
28
|
-
'/products/packages',
|
|
29
|
-
undefined,
|
|
30
|
-
expect.objectContaining({
|
|
31
|
-
Authorization: expect.stringMatching('Bearer TOKEN')
|
|
32
|
-
})
|
|
33
|
-
)
|
|
34
|
-
.reply(200, [samplePackage]);
|
|
35
|
-
|
|
36
|
-
const response = await subject.getPackages();
|
|
37
|
-
|
|
38
|
-
expect(response).toBeDefined();
|
|
39
|
-
expect(response).toEqual(expect.arrayContaining([samplePackage]));
|
|
40
|
-
});
|
|
41
|
-
});
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import MockAdapter from 'axios-mock-adapter/types';
|
|
2
|
-
import { UserService } from '../../src';
|
|
3
|
-
import { AuthenticatedAdapter } from '../../src/AuthenticatedAdapter';
|
|
4
|
-
import { AxiosMockAdapter } from '../MockAdapter';
|
|
5
|
-
import { sampleUser, sampleUserSummary } from '../mocks';
|
|
6
|
-
|
|
7
|
-
describe('UserService', () => {
|
|
8
|
-
const mock = new AxiosMockAdapter('http://localhost');
|
|
9
|
-
|
|
10
|
-
const mockAuth = (mock: MockAdapter) => {
|
|
11
|
-
mock.onPost('/app/session/token', {
|
|
12
|
-
grant_type: 'session',
|
|
13
|
-
expires_in: 7200
|
|
14
|
-
}).reply(200, { ust: 'TOKEN', expires_in: 7200, mage_id: 'MAGE_ID' });
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
const authAdapter = new AuthenticatedAdapter(mock, {
|
|
18
|
-
appSecret: 'pass',
|
|
19
|
-
appId: 'id'
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
const subject = new UserService(authAdapter);
|
|
23
|
-
|
|
24
|
-
test('getUser() full', async () => {
|
|
25
|
-
mockAuth(mock.mockAdapter);
|
|
26
|
-
|
|
27
|
-
mock.mockAdapter
|
|
28
|
-
.onGet(
|
|
29
|
-
`/users/${sampleUser.mage_id}`,
|
|
30
|
-
undefined,
|
|
31
|
-
expect.objectContaining({
|
|
32
|
-
Authorization: expect.stringMatching('Bearer TOKEN')
|
|
33
|
-
})
|
|
34
|
-
)
|
|
35
|
-
.reply(200, sampleUser);
|
|
36
|
-
|
|
37
|
-
const response = await subject.getUser(false);
|
|
38
|
-
|
|
39
|
-
expect(response).toBeDefined();
|
|
40
|
-
expect(response).toMatchObject(sampleUser);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
test('getUser() summary', async () => {
|
|
44
|
-
mockAuth(mock.mockAdapter);
|
|
45
|
-
|
|
46
|
-
mock.mockAdapter
|
|
47
|
-
.onGet(
|
|
48
|
-
`/users/${sampleUserSummary.mage_id}?style=summary`,
|
|
49
|
-
undefined,
|
|
50
|
-
expect.objectContaining({
|
|
51
|
-
Authorization: expect.stringMatching('Bearer TOKEN')
|
|
52
|
-
})
|
|
53
|
-
)
|
|
54
|
-
.reply(200, sampleUserSummary);
|
|
55
|
-
|
|
56
|
-
const response = await subject.getUser(true);
|
|
57
|
-
|
|
58
|
-
expect(response).toBeDefined();
|
|
59
|
-
expect(response).toMatchObject(sampleUserSummary);
|
|
60
|
-
});
|
|
61
|
-
});
|