soajs.multitenant 2.0.35 → 2.0.39
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/.travis.yml +4 -2
- package/_index.js +6 -1
- package/bl/tenant.js +7 -2
- package/config.js +14 -1
- package/model/mongo/tenant.js +8 -6
- package/package.json +6 -5
- package/test/data/provision_integration/resources/dash_cluster.js +1 -2
- package/test/integration/product/delete/deleteProduct.test.js +4 -4
- package/test/integration/product/schemas/deleteProduct.js +4 -4
- package/test/integration/tenant/get/getTenant.test.js +22 -2
- package/test/integration/tenant/schemas/deleteTenant.js +37 -38
- package/test/unit/bl/index.test.js +2 -3
- package/test/unit/model/mongo/product.indexes.test.js +74 -75
- package/test/unit/model/mongo/product.test.js +5 -9
- package/test/unit/model/mongo/tenant.indexes.test.js +74 -75
- package/test/unit/model/mongo/tenant.test.js +429 -433
package/.travis.yml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
language: node_js
|
|
2
2
|
|
|
3
|
-
node_js:
|
|
3
|
+
node_js: 16
|
|
4
4
|
|
|
5
5
|
jobs:
|
|
6
6
|
include:
|
|
@@ -56,9 +56,11 @@ jobs:
|
|
|
56
56
|
- docker tag soajsorg/multitenant:latest soajsorg/multitenant:${MAJOR_VERSION}.x
|
|
57
57
|
|
|
58
58
|
- docker push soajsorg/multitenant
|
|
59
|
+
- docker push soajsorg/multitenant:${PACKAGE_VERSION}
|
|
60
|
+
- docker push soajsorg/multitenant:${MAJOR_VERSION}.x
|
|
59
61
|
deploy:
|
|
60
62
|
on:
|
|
61
63
|
all_branches: true
|
|
62
64
|
provider: releases
|
|
63
65
|
api_key: ${GIT_TOKEN}
|
|
64
|
-
skip_cleanup: true
|
|
66
|
+
skip_cleanup: true
|
package/_index.js
CHANGED
|
@@ -509,6 +509,11 @@ function run(serviceStartCb) {
|
|
|
509
509
|
return res.json(req.soajs.buildResponse(error, data));
|
|
510
510
|
});
|
|
511
511
|
});
|
|
512
|
+
service.get("/admin/tenant/name", (req, res) => {
|
|
513
|
+
bl.tenant.get(req.soajs, req.soajs.inputmaskData, (error, data) => {
|
|
514
|
+
return res.json(req.soajs.buildResponse(error, data));
|
|
515
|
+
});
|
|
516
|
+
});
|
|
512
517
|
|
|
513
518
|
service.get("/tenant/console", (req, res) => {
|
|
514
519
|
req.soajs.inputmaskData.soajs = true;
|
|
@@ -915,4 +920,4 @@ module.exports = {
|
|
|
915
920
|
stop(null);
|
|
916
921
|
}
|
|
917
922
|
}
|
|
918
|
-
};
|
|
923
|
+
};
|
package/bl/tenant.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
'use strict';
|
|
10
|
+
const uuid = require("uuid");
|
|
10
11
|
const async = require('async');
|
|
11
12
|
const request = require("request");
|
|
12
13
|
|
|
@@ -216,8 +217,9 @@ let bl = {
|
|
|
216
217
|
let data = {};
|
|
217
218
|
data.id = inputmaskData.id;
|
|
218
219
|
data.code = inputmaskData.code;
|
|
220
|
+
data.name = inputmaskData.name;
|
|
219
221
|
|
|
220
|
-
if (!data.id && !data.code) {
|
|
222
|
+
if (!data.id && !data.code && !data.name) {
|
|
221
223
|
data.id = soajs.tenant.id;
|
|
222
224
|
}
|
|
223
225
|
data.soajs = !!inputmaskData.soajs;
|
|
@@ -494,6 +496,9 @@ let bl = {
|
|
|
494
496
|
}
|
|
495
497
|
if (inputmaskData.oauth) {
|
|
496
498
|
record.oauth = inputmaskData.oauth;
|
|
499
|
+
if (!record.oauth.secret || record.oauth.secret === "") {
|
|
500
|
+
record.oauth.secret = uuid.v4();
|
|
501
|
+
}
|
|
497
502
|
}
|
|
498
503
|
if (inputmaskData.profile) {
|
|
499
504
|
record.profile = inputmaskData.profile;
|
|
@@ -1740,4 +1745,4 @@ let bl = {
|
|
|
1740
1745
|
},
|
|
1741
1746
|
};
|
|
1742
1747
|
|
|
1743
|
-
module.exports = bl;
|
|
1748
|
+
module.exports = bl;
|
package/config.js
CHANGED
|
@@ -974,6 +974,19 @@ module.exports = {
|
|
|
974
974
|
}
|
|
975
975
|
}
|
|
976
976
|
},
|
|
977
|
+
"/admin/tenant/name": {
|
|
978
|
+
_apiInfo: {
|
|
979
|
+
"l": "Get admin tenant by name",
|
|
980
|
+
"group": "Admin Tenant"
|
|
981
|
+
},
|
|
982
|
+
"name": {
|
|
983
|
+
"source": ['query.name'],
|
|
984
|
+
"required": true,
|
|
985
|
+
"validation": {
|
|
986
|
+
"type": "string"
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
},
|
|
977
990
|
"/admin/tenant/application": {
|
|
978
991
|
_apiInfo: {
|
|
979
992
|
"l": "Get tenant application",
|
|
@@ -3408,4 +3421,4 @@ module.exports = {
|
|
|
3408
3421
|
}
|
|
3409
3422
|
}
|
|
3410
3423
|
}
|
|
3411
|
-
};
|
|
3424
|
+
};
|
package/model/mongo/tenant.js
CHANGED
|
@@ -109,8 +109,8 @@ Tenant.prototype.getTenants = function (data, cb) {
|
|
|
109
109
|
|
|
110
110
|
Tenant.prototype.getTenant = function (data, cb) {
|
|
111
111
|
let __self = this;
|
|
112
|
-
if (!data || !(data.id || data.code)) {
|
|
113
|
-
let error = new Error("id or
|
|
112
|
+
if (!data || !(data.id || data.code || data.name)) {
|
|
113
|
+
let error = new Error("id, code, or name is required.");
|
|
114
114
|
return cb(error, null);
|
|
115
115
|
}
|
|
116
116
|
|
|
@@ -136,11 +136,13 @@ Tenant.prototype.getTenant = function (data, cb) {
|
|
|
136
136
|
condition.$and.push({'_id': id});
|
|
137
137
|
__self.mongoCore.findOne(colName, condition, null, cb);
|
|
138
138
|
});
|
|
139
|
+
} else if (data.code) {
|
|
140
|
+
condition.$and.push({'code': data.code});
|
|
141
|
+
__self.mongoCore.findOne(colName, condition, null, cb);
|
|
139
142
|
} else {
|
|
140
|
-
if (data.
|
|
141
|
-
condition.$and.push({'
|
|
143
|
+
if (data.name) {
|
|
144
|
+
condition.$and.push({'name': data.name});
|
|
142
145
|
}
|
|
143
|
-
|
|
144
146
|
__self.mongoCore.findOne(colName, condition, null, cb);
|
|
145
147
|
}
|
|
146
148
|
};
|
|
@@ -590,4 +592,4 @@ Tenant.prototype.closeConnection = function () {
|
|
|
590
592
|
__self.mongoCore.closeDb();
|
|
591
593
|
};
|
|
592
594
|
|
|
593
|
-
module.exports = Tenant;
|
|
595
|
+
module.exports = Tenant;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "soajs.multitenant",
|
|
3
3
|
"description": "soajs multitenant service",
|
|
4
|
-
"version": "2.0.
|
|
4
|
+
"version": "2.0.39",
|
|
5
5
|
"author": "soajs team <team@soajs.org>",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -31,11 +31,12 @@
|
|
|
31
31
|
"mocha": "6.2.2",
|
|
32
32
|
"nock": "13.0.3",
|
|
33
33
|
"request": "2.88.2",
|
|
34
|
-
"soajs.controller": "4.0.
|
|
34
|
+
"soajs.controller": "4.0.48"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"async": "3.2.
|
|
38
|
-
"soajs": "4.0.
|
|
39
|
-
"soajs.core.libs": "1.2.0"
|
|
37
|
+
"async": "3.2.2",
|
|
38
|
+
"soajs": "4.0.33",
|
|
39
|
+
"soajs.core.libs": "1.2.0",
|
|
40
|
+
"uuid": "8.3.2"
|
|
40
41
|
}
|
|
41
42
|
}
|
|
@@ -105,10 +105,10 @@ describe("Testing delete product API", () => {
|
|
|
105
105
|
assert.ifError(error);
|
|
106
106
|
assert.ok(body);
|
|
107
107
|
assert.ok(body.data);
|
|
108
|
-
assert.
|
|
108
|
+
assert.strictEqual(body.data.acknowledged, true);
|
|
109
109
|
let check = validator.validate(body, deleteProductSchema);
|
|
110
|
-
assert.
|
|
111
|
-
assert.
|
|
110
|
+
assert.strictEqual(check.valid, true);
|
|
111
|
+
assert.deepStrictEqual(check.errors, []);
|
|
112
112
|
done();
|
|
113
113
|
});
|
|
114
114
|
|
|
@@ -173,4 +173,4 @@ describe("Testing delete product API", () => {
|
|
|
173
173
|
done();
|
|
174
174
|
});
|
|
175
175
|
});
|
|
176
|
-
});
|
|
176
|
+
});
|
|
@@ -22,12 +22,12 @@ let deleteProductSchema = {
|
|
|
22
22
|
"type": "object",
|
|
23
23
|
"required": false,
|
|
24
24
|
"properties": {
|
|
25
|
-
"
|
|
25
|
+
"deletedCount": {
|
|
26
26
|
"type": "integer",
|
|
27
27
|
"required": true
|
|
28
28
|
},
|
|
29
|
-
"
|
|
30
|
-
"type": "
|
|
29
|
+
"acknowledged": {
|
|
30
|
+
"type": "boolean",
|
|
31
31
|
"required": true
|
|
32
32
|
}
|
|
33
33
|
}
|
|
@@ -49,4 +49,4 @@ let deleteProductSchema = {
|
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
51
|
|
|
52
|
-
module.exports = deleteProductSchema;
|
|
52
|
+
module.exports = deleteProductSchema;
|
|
@@ -69,7 +69,27 @@ describe("Testing get tenant API", () => {
|
|
|
69
69
|
done();
|
|
70
70
|
});
|
|
71
71
|
});
|
|
72
|
-
|
|
72
|
+
|
|
73
|
+
it("Success - will return tenant record - name (admin)", (done) => {
|
|
74
|
+
let params = {
|
|
75
|
+
qs: {
|
|
76
|
+
name: selectedTenant.name
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
requester('/admin/tenant/name', 'get', params, (error, body) => {
|
|
80
|
+
assert.ifError(error);
|
|
81
|
+
assert.ok(body);
|
|
82
|
+
assert.ok(body.data);
|
|
83
|
+
assert.deepEqual(body.data.name, 'Test 2 Tenant');
|
|
84
|
+
assert.deepEqual(body.data.code, 'test2');
|
|
85
|
+
assert.deepEqual(body.data.description, 'this is a description for test tenant');
|
|
86
|
+
let check = validator.validate(body, getTenantsSchema);
|
|
87
|
+
assert.deepEqual(check.valid, true);
|
|
88
|
+
assert.deepEqual(check.errors, []);
|
|
89
|
+
done();
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
73
93
|
it("Success - will return tenant record - no id", (done) => {
|
|
74
94
|
let params = {
|
|
75
95
|
qs: {
|
|
@@ -120,4 +140,4 @@ describe("Testing get tenant API", () => {
|
|
|
120
140
|
done();
|
|
121
141
|
});
|
|
122
142
|
});
|
|
123
|
-
});
|
|
143
|
+
});
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
/**
|
|
3
2
|
* @license
|
|
4
3
|
* Copyright SOAJS All Rights Reserved.
|
|
@@ -10,43 +9,43 @@
|
|
|
10
9
|
"use strict";
|
|
11
10
|
|
|
12
11
|
let deleteTenantsSchema = {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
12
|
+
"type": "object",
|
|
13
|
+
"required": true,
|
|
14
|
+
"additionalProperties": false,
|
|
15
|
+
"properties": {
|
|
16
|
+
"result": {
|
|
17
|
+
"type": "boolean",
|
|
18
|
+
"required": true
|
|
19
|
+
},
|
|
20
|
+
"data": {
|
|
21
|
+
"type": "object",
|
|
22
|
+
"required": false,
|
|
23
|
+
"properties": {
|
|
24
|
+
"deletedCount": {
|
|
25
|
+
"type": "integer",
|
|
26
|
+
"required": true
|
|
27
|
+
},
|
|
28
|
+
"acknowledged": {
|
|
29
|
+
"type": "boolean",
|
|
30
|
+
"required": true
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"errors": {
|
|
35
|
+
"type": "object",
|
|
36
|
+
"required": false,
|
|
37
|
+
"properties": {
|
|
38
|
+
"codes": {
|
|
39
|
+
"type": "array",
|
|
40
|
+
"required": true
|
|
41
|
+
},
|
|
42
|
+
"details": {
|
|
43
|
+
"type": "array",
|
|
44
|
+
"required": true
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
50
49
|
};
|
|
51
50
|
|
|
52
51
|
module.exports = deleteTenantsSchema;
|
|
@@ -71,8 +71,7 @@ describe("Unit test for: BLs", () => {
|
|
|
71
71
|
],
|
|
72
72
|
"credentials": null,
|
|
73
73
|
"URLParam": {
|
|
74
|
-
|
|
75
|
-
"autoReconnect": true
|
|
74
|
+
"useUnifiedTopology": true
|
|
76
75
|
}
|
|
77
76
|
}
|
|
78
77
|
}
|
|
@@ -89,4 +88,4 @@ describe("Unit test for: BLs", () => {
|
|
|
89
88
|
});
|
|
90
89
|
});
|
|
91
90
|
|
|
92
|
-
});
|
|
91
|
+
});
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
/**
|
|
3
2
|
* @license
|
|
4
3
|
* Copyright SOAJS All Rights Reserved.
|
|
@@ -14,77 +13,77 @@ const Product = helper.requireModule('model/mongo/product.js');
|
|
|
14
13
|
const assert = require('assert');
|
|
15
14
|
|
|
16
15
|
describe("Unit test for: Model - product - indexes", () => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
});
|
|
16
|
+
let model;
|
|
17
|
+
let service = {
|
|
18
|
+
config: {
|
|
19
|
+
"errors": {},
|
|
20
|
+
},
|
|
21
|
+
log: {
|
|
22
|
+
error: () => {
|
|
23
|
+
console.log();
|
|
24
|
+
},
|
|
25
|
+
debug: () => {
|
|
26
|
+
console.log();
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
registry: {
|
|
30
|
+
get: () => {
|
|
31
|
+
return {
|
|
32
|
+
coreDB: {
|
|
33
|
+
provision: {
|
|
34
|
+
"name": "core_provision",
|
|
35
|
+
"prefix": '',
|
|
36
|
+
"servers": [
|
|
37
|
+
{
|
|
38
|
+
"host": "127.0.0.1",
|
|
39
|
+
"port": 27017
|
|
40
|
+
}
|
|
41
|
+
],
|
|
42
|
+
"credentials": null,
|
|
43
|
+
"URLParam": {
|
|
44
|
+
"useUnifiedTopology": true
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
before((done) => {
|
|
54
|
+
model = new Product(service);
|
|
55
|
+
done();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
afterEach((done) => {
|
|
59
|
+
done();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('Fails - Add Product - Code Exists - Index unique', (done) => {
|
|
63
|
+
model.addProduct({
|
|
64
|
+
name: "Console UI Product",
|
|
65
|
+
code: "DSBRD"
|
|
66
|
+
}, (err) => {
|
|
67
|
+
// assert.deepEqual(err.name, 'MongoServerError');
|
|
68
|
+
assert.ok(err.message.indexOf("E11000 duplicate key") !== -1);
|
|
69
|
+
// assert.deepEqual(err.message, 'E11000 duplicate key error collection: core_provision.products index: code_1 dup key: { code: "DSBRD" }');
|
|
70
|
+
assert.ok(err);
|
|
71
|
+
done();
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('Fails - Add Product - Code null - Index unique', (done) => {
|
|
76
|
+
model.addProduct({
|
|
77
|
+
name: "Console UI Product",
|
|
78
|
+
code: null
|
|
79
|
+
}, (err) => {
|
|
80
|
+
assert.ok(err);
|
|
81
|
+
done();
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("Success - closeConnection", (done) => {
|
|
86
|
+
model.closeConnection();
|
|
87
|
+
done();
|
|
88
|
+
});
|
|
89
|
+
});
|
|
@@ -41,8 +41,7 @@ describe("Unit test for: Model - product", () => {
|
|
|
41
41
|
],
|
|
42
42
|
"credentials": null,
|
|
43
43
|
"URLParam": {
|
|
44
|
-
"
|
|
45
|
-
"autoReconnect": true
|
|
44
|
+
"useUnifiedTopology": true
|
|
46
45
|
}
|
|
47
46
|
}
|
|
48
47
|
}
|
|
@@ -257,8 +256,7 @@ describe("Unit test for: Model - product", () => {
|
|
|
257
256
|
],
|
|
258
257
|
"credentials": null,
|
|
259
258
|
"URLParam": {
|
|
260
|
-
"
|
|
261
|
-
"autoReconnect": true
|
|
259
|
+
"useUnifiedTopology": true
|
|
262
260
|
}
|
|
263
261
|
}, null);
|
|
264
262
|
done();
|
|
@@ -539,8 +537,7 @@ describe("Unit test for: Model - product", () => {
|
|
|
539
537
|
"index": "test",
|
|
540
538
|
"credentials": null,
|
|
541
539
|
"URLParam": {
|
|
542
|
-
"
|
|
543
|
-
"autoReconnect": true
|
|
540
|
+
"useUnifiedTopology": true
|
|
544
541
|
},
|
|
545
542
|
}, null);
|
|
546
543
|
model.closeConnection();
|
|
@@ -560,12 +557,11 @@ describe("Unit test for: Model - product", () => {
|
|
|
560
557
|
"index": "test",
|
|
561
558
|
"credentials": null,
|
|
562
559
|
"URLParam": {
|
|
563
|
-
"
|
|
564
|
-
"autoReconnect": true
|
|
560
|
+
"useUnifiedTopology": true
|
|
565
561
|
},
|
|
566
562
|
"dbConfig": {}
|
|
567
563
|
}, null);
|
|
568
564
|
done();
|
|
569
565
|
});
|
|
570
566
|
});
|
|
571
|
-
});
|
|
567
|
+
});
|