@webda/core 2.0.0-beta.3 → 2.1.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/application.d.ts +5 -5
- package/lib/application.js +71 -84
- package/lib/application.js.map +1 -1
- package/lib/application.spec.js +121 -140
- package/lib/application.spec.js.map +1 -1
- package/lib/core.d.ts +21 -25
- package/lib/core.js +233 -320
- package/lib/core.js.map +1 -1
- package/lib/core.spec.js +334 -406
- package/lib/core.spec.js.map +1 -1
- package/lib/index.d.ts +49 -48
- package/lib/index.js +53 -70
- package/lib/index.js.map +1 -1
- package/lib/models/aclmodel.d.ts +2 -2
- package/lib/models/aclmodel.js +63 -90
- package/lib/models/aclmodel.js.map +1 -1
- package/lib/models/aclmodel.spec.js +128 -152
- package/lib/models/aclmodel.spec.js.map +1 -1
- package/lib/models/coremodel.d.ts +33 -14
- package/lib/models/coremodel.js +160 -117
- package/lib/models/coremodel.js.map +1 -1
- package/lib/models/coremodel.spec.js +143 -107
- package/lib/models/coremodel.spec.js.map +1 -1
- package/lib/models/deployment.js +1 -2
- package/lib/models/ident.d.ts +3 -3
- package/lib/models/ident.js +4 -9
- package/lib/models/ident.js.map +1 -1
- package/lib/models/ident.spec.js +9 -11
- package/lib/models/ident.spec.js.map +1 -1
- package/lib/models/ownermodel.d.ts +2 -2
- package/lib/models/ownermodel.js +39 -62
- package/lib/models/ownermodel.js.map +1 -1
- package/lib/models/ownermodel.spec.js +126 -168
- package/lib/models/ownermodel.spec.js.map +1 -1
- package/lib/models/rolemodel.d.ts +1 -1
- package/lib/models/rolemodel.js +24 -40
- package/lib/models/rolemodel.js.map +1 -1
- package/lib/models/rolemodel.spec.js +44 -63
- package/lib/models/rolemodel.spec.js.map +1 -1
- package/lib/models/user.d.ts +9 -9
- package/lib/models/user.js +3 -8
- package/lib/models/user.js.map +1 -1
- package/lib/models/user.spec.js +14 -16
- package/lib/models/user.spec.js.map +1 -1
- package/lib/queues/filequeue.d.ts +2 -2
- package/lib/queues/filequeue.js +72 -93
- package/lib/queues/filequeue.js.map +1 -1
- package/lib/queues/filequeue.spec.js +53 -70
- package/lib/queues/filequeue.spec.js.map +1 -1
- package/lib/queues/memoryqueue.d.ts +2 -2
- package/lib/queues/memoryqueue.js +37 -61
- package/lib/queues/memoryqueue.js.map +1 -1
- package/lib/queues/memoryqueue.spec.js +142 -165
- package/lib/queues/memoryqueue.spec.js.map +1 -1
- package/lib/queues/pubsubservice.d.ts +2 -2
- package/lib/queues/pubsubservice.js +3 -7
- package/lib/queues/pubsubservice.js.map +1 -1
- package/lib/queues/queue.spec.d.ts +1 -1
- package/lib/queues/queue.spec.js +42 -56
- package/lib/queues/queue.spec.js.map +1 -1
- package/lib/queues/queueservice.d.ts +3 -3
- package/lib/queues/queueservice.js +51 -67
- package/lib/queues/queueservice.js.map +1 -1
- package/lib/router.d.ts +3 -3
- package/lib/router.js +46 -47
- package/lib/router.js.map +1 -1
- package/lib/router.spec.js +64 -61
- package/lib/router.spec.js.map +1 -1
- package/lib/services/asyncevents.d.ts +2 -2
- package/lib/services/asyncevents.js +44 -64
- package/lib/services/asyncevents.js.map +1 -1
- package/lib/services/asyncevents.spec.js +81 -98
- package/lib/services/asyncevents.spec.js.map +1 -1
- package/lib/services/authentication.d.ts +23 -13
- package/lib/services/authentication.js +540 -566
- package/lib/services/authentication.js.map +1 -1
- package/lib/services/authentication.spec.js +411 -447
- package/lib/services/authentication.spec.js.map +1 -1
- package/lib/services/binary.d.ts +8 -6
- package/lib/services/binary.js +212 -245
- package/lib/services/binary.js.map +1 -1
- package/lib/services/binary.spec.d.ts +3 -3
- package/lib/services/binary.spec.js +390 -443
- package/lib/services/binary.spec.js.map +1 -1
- package/lib/services/cloudbinary.d.ts +3 -3
- package/lib/services/cloudbinary.js +45 -70
- package/lib/services/cloudbinary.js.map +1 -1
- package/lib/services/cloudbinary.spec.d.ts +3 -3
- package/lib/services/cloudbinary.spec.js +133 -162
- package/lib/services/cloudbinary.spec.js.map +1 -1
- package/lib/services/configuration.d.ts +1 -1
- package/lib/services/configuration.js +78 -105
- package/lib/services/configuration.js.map +1 -1
- package/lib/services/configuration.spec.js +63 -83
- package/lib/services/configuration.spec.js.map +1 -1
- package/lib/services/cron.d.ts +3 -2
- package/lib/services/cron.js +9 -13
- package/lib/services/cron.js.map +1 -1
- package/lib/services/cron.spec.js +18 -21
- package/lib/services/cron.spec.js.map +1 -1
- package/lib/services/cryptoservice.d.ts +9 -4
- package/lib/services/cryptoservice.js +187 -221
- package/lib/services/cryptoservice.js.map +1 -1
- package/lib/services/cryptoservice.spec.js +88 -115
- package/lib/services/cryptoservice.spec.js.map +1 -1
- package/lib/services/debugmailer.d.ts +1 -1
- package/lib/services/debugmailer.js +13 -34
- package/lib/services/debugmailer.js.map +1 -1
- package/lib/services/debugmailer.spec.js +16 -29
- package/lib/services/debugmailer.spec.js.map +1 -1
- package/lib/services/echo.d.ts +2 -2
- package/lib/services/echo.js +15 -31
- package/lib/services/echo.js.map +1 -1
- package/lib/services/echo.spec.js +27 -40
- package/lib/services/echo.spec.js.map +1 -1
- package/lib/services/filebinary.d.ts +5 -5
- package/lib/services/filebinary.js +165 -210
- package/lib/services/filebinary.js.map +1 -1
- package/lib/services/filebinary.spec.d.ts +2 -1
- package/lib/services/filebinary.spec.js +106 -116
- package/lib/services/filebinary.spec.js.map +1 -1
- package/lib/services/fileconfiguration.d.ts +1 -1
- package/lib/services/fileconfiguration.js +25 -44
- package/lib/services/fileconfiguration.js.map +1 -1
- package/lib/services/fileconfiguration.spec.js +79 -109
- package/lib/services/fileconfiguration.spec.js.map +1 -1
- package/lib/services/invitationservice.d.ts +8 -8
- package/lib/services/invitationservice.js +274 -314
- package/lib/services/invitationservice.js.map +1 -1
- package/lib/services/invitationservice.spec.js +443 -449
- package/lib/services/invitationservice.spec.js.map +1 -1
- package/lib/services/kubernetesconfiguration.d.ts +1 -1
- package/lib/services/kubernetesconfiguration.js +41 -60
- package/lib/services/kubernetesconfiguration.js.map +1 -1
- package/lib/services/kubernetesconfiguration.spec.js +80 -98
- package/lib/services/kubernetesconfiguration.spec.js.map +1 -1
- package/lib/services/mailer.d.ts +4 -4
- package/lib/services/mailer.js +62 -86
- package/lib/services/mailer.js.map +1 -1
- package/lib/services/mailer.spec.js +86 -127
- package/lib/services/mailer.spec.js.map +1 -1
- package/lib/services/notificationservice.d.ts +3 -3
- package/lib/services/notificationservice.js +21 -42
- package/lib/services/notificationservice.js.map +1 -1
- package/lib/services/notificationservice.spec.js +47 -73
- package/lib/services/notificationservice.spec.js.map +1 -1
- package/lib/services/oauth.d.ts +4 -4
- package/lib/services/oauth.js +68 -83
- package/lib/services/oauth.js.map +1 -1
- package/lib/services/oauth.spec.js +130 -156
- package/lib/services/oauth.spec.js.map +1 -1
- package/lib/services/proxy.d.ts +2 -6
- package/lib/services/proxy.js +45 -58
- package/lib/services/proxy.js.map +1 -1
- package/lib/services/proxy.spec.js +34 -53
- package/lib/services/proxy.spec.js.map +1 -1
- package/lib/services/resource.d.ts +2 -2
- package/lib/services/resource.js +12 -18
- package/lib/services/resource.js.map +1 -1
- package/lib/services/resource.spec.js +67 -99
- package/lib/services/resource.spec.js.map +1 -1
- package/lib/services/service.d.ts +26 -3
- package/lib/services/service.js +68 -40
- package/lib/services/service.js.map +1 -1
- package/lib/services/service.spec.js +62 -67
- package/lib/services/service.spec.js.map +1 -1
- package/lib/services/version.d.ts +1 -1
- package/lib/services/version.js +3 -8
- package/lib/services/version.js.map +1 -1
- package/lib/services/version.spec.js +11 -24
- package/lib/services/version.spec.js.map +1 -1
- package/lib/stores/aggregator.d.ts +2 -2
- package/lib/stores/aggregator.js +37 -58
- package/lib/stores/aggregator.js.map +1 -1
- package/lib/stores/file.d.ts +3 -3
- package/lib/stores/file.js +93 -131
- package/lib/stores/file.js.map +1 -1
- package/lib/stores/file.spec.d.ts +2 -2
- package/lib/stores/file.spec.js +262 -289
- package/lib/stores/file.spec.js.map +1 -1
- package/lib/stores/mapper.d.ts +3 -3
- package/lib/stores/mapper.js +110 -137
- package/lib/stores/mapper.js.map +1 -1
- package/lib/stores/mapper.spec.js +133 -150
- package/lib/stores/mapper.spec.js.map +1 -1
- package/lib/stores/memory.d.ts +3 -3
- package/lib/stores/memory.js +98 -144
- package/lib/stores/memory.js.map +1 -1
- package/lib/stores/memory.spec.d.ts +2 -2
- package/lib/stores/memory.spec.js +124 -145
- package/lib/stores/memory.spec.js.map +1 -1
- package/lib/stores/store.d.ts +27 -17
- package/lib/stores/store.js +833 -849
- package/lib/stores/store.js.map +1 -1
- package/lib/stores/store.spec.d.ts +5 -4
- package/lib/stores/store.spec.js +625 -669
- package/lib/stores/store.spec.js.map +1 -1
- package/lib/stores/webdaql/WebdaQLLexer.d.ts +4 -4
- package/lib/stores/webdaql/WebdaQLLexer.js +9 -13
- package/lib/stores/webdaql/WebdaQLLexer.js.map +1 -1
- package/lib/stores/webdaql/WebdaQLParserLexer.d.ts +4 -4
- package/lib/stores/webdaql/WebdaQLParserLexer.js +9 -13
- package/lib/stores/webdaql/WebdaQLParserLexer.js.map +1 -1
- package/lib/stores/webdaql/WebdaQLParserListener.d.ts +2 -2
- package/lib/stores/webdaql/WebdaQLParserListener.js +1 -2
- package/lib/stores/webdaql/WebdaQLParserListener.js.map +1 -1
- package/lib/stores/webdaql/WebdaQLParserParser.d.ts +10 -10
- package/lib/stores/webdaql/WebdaQLParserParser.js +62 -91
- package/lib/stores/webdaql/WebdaQLParserParser.js.map +1 -1
- package/lib/stores/webdaql/WebdaQLParserVisitor.d.ts +2 -2
- package/lib/stores/webdaql/WebdaQLParserVisitor.js +1 -2
- package/lib/stores/webdaql/WebdaQLParserVisitor.js.map +1 -1
- package/lib/stores/webdaql/query.d.ts +4 -5
- package/lib/stores/webdaql/query.js +16 -19
- package/lib/stores/webdaql/query.js.map +1 -1
- package/lib/stores/webdaql/query.spec.js +30 -32
- package/lib/stores/webdaql/query.spec.js.map +1 -1
- package/lib/test.d.ts +3 -3
- package/lib/test.js +73 -100
- package/lib/test.js.map +1 -1
- package/lib/unpackedapplication.d.ts +1 -1
- package/lib/unpackedapplication.js +49 -39
- package/lib/unpackedapplication.js.map +1 -1
- package/lib/utils/abstractdeployer.js +1 -5
- package/lib/utils/abstractdeployer.js.map +1 -1
- package/lib/utils/abstractdeployer.spec.js +6 -8
- package/lib/utils/abstractdeployer.spec.js.map +1 -1
- package/lib/utils/context.d.ts +7 -5
- package/lib/utils/context.js +95 -103
- package/lib/utils/context.js.map +1 -1
- package/lib/utils/context.spec.js +139 -163
- package/lib/utils/context.spec.js.map +1 -1
- package/lib/utils/cookie.d.ts +3 -3
- package/lib/utils/cookie.js +42 -61
- package/lib/utils/cookie.js.map +1 -1
- package/lib/utils/cookie.spec.js +42 -64
- package/lib/utils/cookie.spec.js.map +1 -1
- package/lib/utils/esm.d.ts +4 -0
- package/lib/utils/esm.js +10 -0
- package/lib/utils/esm.js.map +1 -0
- package/lib/utils/httpcontext.d.ts +3 -0
- package/lib/utils/httpcontext.js +48 -65
- package/lib/utils/httpcontext.js.map +1 -1
- package/lib/utils/httpcontext.spec.js +37 -56
- package/lib/utils/httpcontext.spec.js.map +1 -1
- package/lib/utils/logger.d.ts +2 -2
- package/lib/utils/logger.js +15 -28
- package/lib/utils/logger.js.map +1 -1
- package/lib/utils/logger.spec.js +9 -11
- package/lib/utils/logger.spec.js.map +1 -1
- package/lib/utils/serializers.js +17 -20
- package/lib/utils/serializers.js.map +1 -1
- package/lib/utils/serializers.spec.js +43 -44
- package/lib/utils/serializers.spec.js.map +1 -1
- package/lib/utils/session.d.ts +6 -6
- package/lib/utils/session.js +37 -59
- package/lib/utils/session.js.map +1 -1
- package/lib/utils/session.spec.js +38 -51
- package/lib/utils/session.spec.js.map +1 -1
- package/lib/utils/waiter.d.ts +1 -1
- package/lib/utils/waiter.js +32 -52
- package/lib/utils/waiter.js.map +1 -1
- package/lib/utils/waiter.spec.js +75 -92
- package/lib/utils/waiter.spec.js.map +1 -1
- package/package.json +18 -13
- package/test/config-invitation.json +1 -3
- package/test/config.json +1 -2
- package/test/config.old.json +1 -2
- package/test/moddas/annotatedservice.js +5 -5
- package/test/moddas/debugmailer.js +2 -3
- package/test/moddas/fakeservice.js +2 -3
- package/test/moddas/voidstore.js +6 -4
- package/test/models/ident.js +2 -6
- package/test/models/task.js +3 -7
- package/test/package.json +2 -1
- package/webda.module.json +895 -190
package/lib/stores/store.spec.js
CHANGED
|
@@ -1,88 +1,64 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
6
|
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
exports.StoreTest = exports.PermissionModel = void 0;
|
|
19
|
-
const mocha_1 = require("@testdeck/mocha");
|
|
20
|
-
const assert = require("assert");
|
|
21
|
-
const sinon_1 = require("sinon");
|
|
22
|
-
const uuid_1 = require("uuid");
|
|
23
|
-
const Idents = require("../../test/models/ident");
|
|
24
|
-
const index_1 = require("../index");
|
|
25
|
-
const coremodel_1 = require("../models/coremodel");
|
|
26
|
-
const test_1 = require("../test");
|
|
27
|
-
const httpcontext_1 = require("../utils/httpcontext");
|
|
28
|
-
const store_1 = require("./store");
|
|
7
|
+
import { suite, test } from "@testdeck/mocha";
|
|
8
|
+
import * as assert from "assert";
|
|
9
|
+
import { stub } from "sinon";
|
|
10
|
+
import { v4 as uuidv4 } from "uuid";
|
|
11
|
+
import { Ident } from "../../test/models/ident.js";
|
|
12
|
+
import { StoreParameters } from "../index.js";
|
|
13
|
+
import { CoreModel } from "../models/coremodel.js";
|
|
14
|
+
import { WebdaTest } from "../test.js";
|
|
15
|
+
import { HttpContext } from "../utils/httpcontext.js";
|
|
16
|
+
import { StoreNotFoundError, UpdateConditionFailError } from "./store.js";
|
|
29
17
|
/**
|
|
30
18
|
* Fake model that refuse the half of the items
|
|
31
19
|
*/
|
|
32
|
-
class PermissionModel extends
|
|
33
|
-
canAct(ctx, _action) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return this;
|
|
39
|
-
});
|
|
20
|
+
export class PermissionModel extends CoreModel {
|
|
21
|
+
async canAct(ctx, _action) {
|
|
22
|
+
if (this.order % 200 < 120) {
|
|
23
|
+
throw 403;
|
|
24
|
+
}
|
|
25
|
+
return this;
|
|
40
26
|
}
|
|
41
27
|
}
|
|
42
|
-
exports.PermissionModel = PermissionModel;
|
|
43
28
|
let StoreParametersTest = class StoreParametersTest {
|
|
44
29
|
cov() {
|
|
45
|
-
let params = new
|
|
30
|
+
let params = new StoreParameters({ expose: "/plop", lastUpdateField: "bz", creationDateField: "c" }, undefined);
|
|
46
31
|
assert.deepStrictEqual(params.expose, { queryMethod: "GET", url: "/plop", restrict: {} });
|
|
47
|
-
assert.throws(() => new
|
|
48
|
-
assert.throws(() => new
|
|
32
|
+
assert.throws(() => new StoreParameters({ map: {} }, undefined), Error);
|
|
33
|
+
assert.throws(() => new StoreParameters({ index: [] }, undefined), Error);
|
|
49
34
|
}
|
|
50
35
|
};
|
|
51
36
|
__decorate([
|
|
52
|
-
|
|
37
|
+
test
|
|
53
38
|
], StoreParametersTest.prototype, "cov", null);
|
|
54
39
|
StoreParametersTest = __decorate([
|
|
55
|
-
|
|
40
|
+
suite
|
|
56
41
|
], StoreParametersTest);
|
|
57
|
-
class StoreTest extends
|
|
42
|
+
class StoreTest extends WebdaTest {
|
|
58
43
|
/**
|
|
59
44
|
* By default no testing index
|
|
60
45
|
* @returns
|
|
61
46
|
*/
|
|
62
|
-
getIndex() {
|
|
63
|
-
return
|
|
64
|
-
return undefined;
|
|
65
|
-
});
|
|
47
|
+
async getIndex() {
|
|
48
|
+
return undefined;
|
|
66
49
|
}
|
|
67
50
|
/**
|
|
68
51
|
* Recreate index if needed
|
|
69
52
|
*/
|
|
70
|
-
recreateIndex() {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
});
|
|
77
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
-
yield _super.before.call(this);
|
|
79
|
-
yield this.getUserStore().__clean();
|
|
80
|
-
yield this.getIdentStore().__clean();
|
|
81
|
-
yield this.recreateIndex();
|
|
82
|
-
});
|
|
53
|
+
async recreateIndex() { }
|
|
54
|
+
async before() {
|
|
55
|
+
await super.before();
|
|
56
|
+
await this.getUserStore().__clean();
|
|
57
|
+
await this.getIdentStore().__clean();
|
|
58
|
+
await this.recreateIndex();
|
|
83
59
|
}
|
|
84
60
|
getModelClass() {
|
|
85
|
-
return
|
|
61
|
+
return Ident;
|
|
86
62
|
}
|
|
87
63
|
/**
|
|
88
64
|
* Get the base of documents to query
|
|
@@ -104,89 +80,85 @@ class StoreTest extends test_1.WebdaTest {
|
|
|
104
80
|
/**
|
|
105
81
|
* Fill the Store with data to be queried
|
|
106
82
|
*/
|
|
107
|
-
fillForQuery() {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
return userStore;
|
|
112
|
-
});
|
|
83
|
+
async fillForQuery() {
|
|
84
|
+
let userStore = this.getUserStore();
|
|
85
|
+
await Promise.all(this.getQueryDocuments().map(d => userStore.save(d)));
|
|
86
|
+
return userStore;
|
|
113
87
|
}
|
|
114
|
-
query() {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
88
|
+
async query() {
|
|
89
|
+
let userStore = await this.fillForQuery();
|
|
90
|
+
const queries = {
|
|
91
|
+
'state = "CA"': 250,
|
|
92
|
+
"team.id > 15": 200,
|
|
93
|
+
"team.id >= 15": 250,
|
|
94
|
+
"team.id <= 14": 750,
|
|
95
|
+
'state IN ["CA", "NY"]': 500,
|
|
96
|
+
'state IN ["CA", "NY", "NV"]': 500,
|
|
97
|
+
'state = "CA" AND team.id > 15': 50,
|
|
98
|
+
"team.id < 5 OR team.id > 15": 450,
|
|
99
|
+
"role < 5 AND team.id > 10 OR team.id > 15": 400,
|
|
100
|
+
"role < 5 AND (team.id > 10 OR team.id > 15)": 200,
|
|
101
|
+
'state LIKE "C_"': 250,
|
|
102
|
+
'state LIKE "C__"': 0,
|
|
103
|
+
'state LIKE "C%"': 250,
|
|
104
|
+
'state != "CA"': 750,
|
|
105
|
+
"": 1000
|
|
106
|
+
};
|
|
107
|
+
for (let i in queries) {
|
|
108
|
+
assert.strictEqual((await userStore.query(i)).results.length, queries[i], `Query: ${i} should return ${queries[i]}`);
|
|
109
|
+
}
|
|
110
|
+
// Verify pagination system
|
|
111
|
+
let offset;
|
|
112
|
+
let res;
|
|
113
|
+
let i = 0;
|
|
114
|
+
do {
|
|
115
|
+
res = await userStore.query(`LIMIT 100 ${offset ? 'OFFSET "' + offset + '"' : ""}`);
|
|
116
|
+
offset = res.continuationToken;
|
|
117
|
+
if (i++ > 9) {
|
|
118
|
+
assert.strictEqual(res.results.length, 0, `Query: LIMIT 100 ${offset ? 'OFFSET "' + offset + '"' : ""} should return 0`);
|
|
119
|
+
assert.strictEqual(offset, undefined);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
assert.strictEqual(res.results.length, 100, `Query: LIMIT 100 ${offset ? 'OFFSET "' + offset + '"' : ""} should return 0`);
|
|
136
123
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
} while (offset !== undefined);
|
|
152
|
-
// Verify permission issue and half pagination
|
|
153
|
-
userStore.setModel(PermissionModel);
|
|
154
|
-
let context = yield this.newContext();
|
|
155
|
-
// Verify pagination system
|
|
156
|
-
i = 0;
|
|
157
|
-
let total = 0;
|
|
158
|
-
let q;
|
|
159
|
-
// To ensure we trigger slowQuery
|
|
160
|
-
userStore.getParameters().slowQueryThreshold = 0;
|
|
161
|
-
do {
|
|
162
|
-
q = `LIMIT 100 ${offset ? 'OFFSET "' + offset + '"' : ""}`;
|
|
163
|
-
context.setHttpContext(new httpcontext_1.HttpContext("test.webda.io", i++ % 2 ? "GET" : "PUT", userStore.getParameters().expose.url + "?q=" + encodeURI(q), "https", 443));
|
|
164
|
-
context.getHttpContext().setBody({ q });
|
|
165
|
-
context.getParameters().q = q;
|
|
166
|
-
// @ts-ignore
|
|
167
|
-
yield userStore.httpQuery(context);
|
|
168
|
-
res = JSON.parse(context.getResponseBody());
|
|
169
|
-
offset = res.continuationToken;
|
|
170
|
-
total += res.results.length;
|
|
171
|
-
} while (offset !== undefined);
|
|
172
|
-
assert.strictEqual(total, 400);
|
|
173
|
-
q = "BAD QUERY !";
|
|
174
|
-
context.setHttpContext(new httpcontext_1.HttpContext("test.webda.io", "PUT", userStore.getParameters().expose.url, "https", 443));
|
|
124
|
+
} while (offset !== undefined);
|
|
125
|
+
// Verify permission issue and half pagination
|
|
126
|
+
userStore.setModel(PermissionModel);
|
|
127
|
+
let context = await this.newContext();
|
|
128
|
+
// Verify pagination system
|
|
129
|
+
i = 0;
|
|
130
|
+
let total = 0;
|
|
131
|
+
let q;
|
|
132
|
+
// To ensure we trigger slowQuery
|
|
133
|
+
userStore.getParameters().slowQueryThreshold = 0;
|
|
134
|
+
do {
|
|
135
|
+
q = `LIMIT 100 ${offset ? 'OFFSET "' + offset + '"' : ""}`;
|
|
136
|
+
context.setHttpContext(new HttpContext("test.webda.io", i++ % 2 ? "GET" : "PUT", userStore.getParameters().expose.url + "?q=" + encodeURI(q), "https", 443));
|
|
175
137
|
context.getHttpContext().setBody({ q });
|
|
138
|
+
context.getParameters().q = q;
|
|
176
139
|
// @ts-ignore
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
140
|
+
await userStore.httpQuery(context);
|
|
141
|
+
res = JSON.parse(context.getResponseBody());
|
|
142
|
+
offset = res.continuationToken;
|
|
143
|
+
total += res.results.length;
|
|
144
|
+
} while (offset !== undefined);
|
|
145
|
+
assert.strictEqual(total, 400);
|
|
146
|
+
q = "BAD QUERY !";
|
|
147
|
+
context.setHttpContext(new HttpContext("test.webda.io", "PUT", userStore.getParameters().expose.url, "https", 443));
|
|
148
|
+
context.getHttpContext().setBody({ q });
|
|
149
|
+
// @ts-ignore
|
|
150
|
+
await assert.rejects(() => userStore.httpQuery(context), /400/);
|
|
151
|
+
let mock = stub(userStore, "query").callsFake(() => {
|
|
152
|
+
throw new Error("Plop");
|
|
189
153
|
});
|
|
154
|
+
try {
|
|
155
|
+
// @ts-ignore
|
|
156
|
+
await assert.rejects(() => userStore.httpQuery(context), /Plop/);
|
|
157
|
+
}
|
|
158
|
+
finally {
|
|
159
|
+
mock.restore();
|
|
160
|
+
}
|
|
161
|
+
return userStore;
|
|
190
162
|
}
|
|
191
163
|
/**
|
|
192
164
|
* Simplify model
|
|
@@ -200,600 +172,584 @@ class StoreTest extends test_1.WebdaTest {
|
|
|
200
172
|
state: model.state
|
|
201
173
|
};
|
|
202
174
|
}
|
|
203
|
-
queryOrder() {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
team: { id: 16 }
|
|
210
|
-
});
|
|
211
|
-
try {
|
|
212
|
-
let res = yield userStore.query('state = "CA" ORDER BY order DESC LIMIT 10');
|
|
213
|
-
assert.deepStrictEqual(res.results.map((c) => ({ state: c.state, order: c.order, teamId: c.team.id })), [
|
|
214
|
-
{ state: "CA", order: 996, teamId: 16 },
|
|
215
|
-
{ state: "CA", order: 996, teamId: 16 },
|
|
216
|
-
{ state: "CA", order: 992, teamId: 12 },
|
|
217
|
-
{ state: "CA", order: 988, teamId: 8 },
|
|
218
|
-
{ state: "CA", order: 984, teamId: 4 },
|
|
219
|
-
{ state: "CA", order: 980, teamId: 0 },
|
|
220
|
-
{ state: "CA", order: 976, teamId: 16 },
|
|
221
|
-
{ state: "CA", order: 972, teamId: 12 },
|
|
222
|
-
{ state: "CA", order: 968, teamId: 8 },
|
|
223
|
-
{ state: "CA", order: 964, teamId: 4 }
|
|
224
|
-
]);
|
|
225
|
-
res = yield userStore.query("order > 980 ORDER BY state ASC, order DESC LIMIT 10");
|
|
226
|
-
assert.deepStrictEqual(res.results.map((c) => ({ state: c.state, order: c.order, teamId: c.team.id })), [
|
|
227
|
-
{ state: "CA", order: 996, teamId: 16 },
|
|
228
|
-
{ state: "CA", order: 996, teamId: 16 },
|
|
229
|
-
{ state: "CA", order: 992, teamId: 12 },
|
|
230
|
-
{ state: "CA", order: 988, teamId: 8 },
|
|
231
|
-
{ state: "CA", order: 984, teamId: 4 },
|
|
232
|
-
{ state: "FL", order: 999, teamId: 19 },
|
|
233
|
-
{ state: "FL", order: 995, teamId: 15 },
|
|
234
|
-
{ state: "FL", order: 991, teamId: 11 },
|
|
235
|
-
{ state: "FL", order: 987, teamId: 7 },
|
|
236
|
-
{ state: "FL", order: 983, teamId: 3 }
|
|
237
|
-
]);
|
|
238
|
-
}
|
|
239
|
-
finally {
|
|
240
|
-
yield model.delete();
|
|
241
|
-
}
|
|
175
|
+
async queryOrder() {
|
|
176
|
+
let userStore = await this.fillForQuery();
|
|
177
|
+
let model = await userStore.save({
|
|
178
|
+
order: 996,
|
|
179
|
+
state: "CA",
|
|
180
|
+
team: { id: 16 }
|
|
242
181
|
});
|
|
182
|
+
try {
|
|
183
|
+
let res = await userStore.query('state = "CA" ORDER BY order DESC LIMIT 10');
|
|
184
|
+
assert.deepStrictEqual(res.results.map((c) => ({ state: c.state, order: c.order, teamId: c.team.id })), [
|
|
185
|
+
{ state: "CA", order: 996, teamId: 16 },
|
|
186
|
+
{ state: "CA", order: 996, teamId: 16 },
|
|
187
|
+
{ state: "CA", order: 992, teamId: 12 },
|
|
188
|
+
{ state: "CA", order: 988, teamId: 8 },
|
|
189
|
+
{ state: "CA", order: 984, teamId: 4 },
|
|
190
|
+
{ state: "CA", order: 980, teamId: 0 },
|
|
191
|
+
{ state: "CA", order: 976, teamId: 16 },
|
|
192
|
+
{ state: "CA", order: 972, teamId: 12 },
|
|
193
|
+
{ state: "CA", order: 968, teamId: 8 },
|
|
194
|
+
{ state: "CA", order: 964, teamId: 4 }
|
|
195
|
+
]);
|
|
196
|
+
res = await userStore.query("order > 980 ORDER BY state ASC, order DESC LIMIT 10");
|
|
197
|
+
assert.deepStrictEqual(res.results.map((c) => ({ state: c.state, order: c.order, teamId: c.team.id })), [
|
|
198
|
+
{ state: "CA", order: 996, teamId: 16 },
|
|
199
|
+
{ state: "CA", order: 996, teamId: 16 },
|
|
200
|
+
{ state: "CA", order: 992, teamId: 12 },
|
|
201
|
+
{ state: "CA", order: 988, teamId: 8 },
|
|
202
|
+
{ state: "CA", order: 984, teamId: 4 },
|
|
203
|
+
{ state: "FL", order: 999, teamId: 19 },
|
|
204
|
+
{ state: "FL", order: 995, teamId: 15 },
|
|
205
|
+
{ state: "FL", order: 991, teamId: 11 },
|
|
206
|
+
{ state: "FL", order: 987, teamId: 7 },
|
|
207
|
+
{ state: "FL", order: 983, teamId: 3 }
|
|
208
|
+
]);
|
|
209
|
+
}
|
|
210
|
+
finally {
|
|
211
|
+
await model.delete();
|
|
212
|
+
}
|
|
243
213
|
}
|
|
244
|
-
mapper() {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
eventFired++;
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
assert.strictEqual(yield userStore.get(undefined), undefined);
|
|
267
|
-
user1 = (yield userStore.save({
|
|
268
|
-
name: "test"
|
|
269
|
-
})).uuid;
|
|
270
|
-
let user = yield userStore.get(user1);
|
|
271
|
-
// Save a user and add an ident
|
|
272
|
-
assert.notStrictEqual(user, undefined);
|
|
273
|
-
user1 = user.uuid;
|
|
274
|
-
ident1 = yield identStore.save({
|
|
275
|
-
type: "facebook",
|
|
276
|
-
_user: user.uuid
|
|
277
|
-
});
|
|
278
|
-
user = yield userStore.get(user1);
|
|
279
|
-
// Verify the ident is on the user
|
|
280
|
-
assert.notStrictEqual(user, undefined);
|
|
281
|
-
assert.notStrictEqual(user.idents, undefined);
|
|
282
|
-
assert.strictEqual(user.idents.length, 1);
|
|
283
|
-
// Retrieve index to verify it is in it too
|
|
284
|
-
let index = yield this.getIndex();
|
|
285
|
-
// Do not force index test for store
|
|
286
|
-
if (index) {
|
|
287
|
-
assert.notStrictEqual(index[ident1.uuid], undefined);
|
|
288
|
-
assert.strictEqual(index[ident1.uuid].type, "facebook");
|
|
289
|
-
}
|
|
290
|
-
let lastUpdate = user.idents[0]._lastUpdate;
|
|
291
|
-
yield this.sleep(10);
|
|
292
|
-
yield identStore.incrementAttribute(ident1.uuid, "counter", 1);
|
|
293
|
-
yield user.refresh();
|
|
294
|
-
assert.notStrictEqual(user.idents[0]._lastUpdate, 0);
|
|
295
|
-
this.assertLastUpdateNotEqual(user.idents[0]._lastUpdate, lastUpdate, "lastUpdate on a map after incrementAttribute");
|
|
296
|
-
lastUpdate = user.idents[0]._lastUpdate;
|
|
297
|
-
yield this.sleep(10);
|
|
298
|
-
yield identStore.upsertItemToCollection(ident1.uuid, "actions", {
|
|
299
|
-
uuid: "action_1",
|
|
300
|
-
type: "plop",
|
|
301
|
-
date: new Date()
|
|
302
|
-
});
|
|
303
|
-
yield user.refresh();
|
|
304
|
-
assert.notStrictEqual(user.idents[0]._lastUpdate.length, 0);
|
|
305
|
-
this.assertLastUpdateNotEqual(user.idents[0]._lastUpdate, lastUpdate, "lastUpdate on a map after upsertItemToCollection");
|
|
306
|
-
lastUpdate = user.idents[0]._lastUpdate;
|
|
307
|
-
yield this.sleep(10);
|
|
308
|
-
yield identStore.deleteItemFromCollection(ident1.uuid, "actions", 0, "plop", "type");
|
|
309
|
-
yield user.refresh();
|
|
310
|
-
assert.notStrictEqual(user.idents[0]._lastUpdate.length, 0);
|
|
311
|
-
this.assertLastUpdateNotEqual(user.idents[0]._lastUpdate, lastUpdate, "lastUpdate on a map after deleteItemFromCollection");
|
|
312
|
-
ident2 = yield identStore.save({
|
|
313
|
-
type: "google",
|
|
314
|
-
_user: user.uuid
|
|
214
|
+
async mapper() {
|
|
215
|
+
let identStore = this.getIdentStore();
|
|
216
|
+
let userStore = this.getUserStore();
|
|
217
|
+
let user1, ident1, ident2, user2;
|
|
218
|
+
var eventFired = 0;
|
|
219
|
+
var events = [
|
|
220
|
+
"Store.Save",
|
|
221
|
+
"Store.Saved",
|
|
222
|
+
"Store.Get",
|
|
223
|
+
"Store.Delete",
|
|
224
|
+
"Store.Deleted",
|
|
225
|
+
"Store.Update",
|
|
226
|
+
"Store.Updated",
|
|
227
|
+
"Store.Query",
|
|
228
|
+
"Store.Queried"
|
|
229
|
+
];
|
|
230
|
+
for (let evt in events) {
|
|
231
|
+
identStore.on(events[evt], function (evt) {
|
|
232
|
+
eventFired++;
|
|
315
233
|
});
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
type: "google2"
|
|
329
|
-
});
|
|
330
|
-
assert.strictEqual(res.type, "google2");
|
|
331
|
-
assert.strictEqual(res._user, user1);
|
|
332
|
-
// Check index
|
|
333
|
-
if (index) {
|
|
334
|
-
yield index.refresh();
|
|
335
|
-
assert.strictEqual(index[ident2.uuid].type, "google2");
|
|
336
|
-
}
|
|
337
|
-
user = yield userStore.get(user1);
|
|
338
|
-
assert.strictEqual(user.idents.length, 2);
|
|
339
|
-
assert.strictEqual(user.idents[1].type, "google2");
|
|
340
|
-
assert.strictEqual(user.idents[1] instanceof this.getModelClass(), true);
|
|
341
|
-
yield identStore.delete(ident1.uuid);
|
|
342
|
-
user = yield userStore.get(user1);
|
|
343
|
-
assert.strictEqual(user.idents.length, 1);
|
|
344
|
-
assert.strictEqual(user.idents[0].type, "google2");
|
|
345
|
-
// Add a second user to play
|
|
346
|
-
user = yield userStore.save({
|
|
347
|
-
name: "test2"
|
|
348
|
-
});
|
|
349
|
-
user2 = user.uuid;
|
|
350
|
-
// Move ident2 from user1 to user2
|
|
351
|
-
yield identStore.patch({
|
|
352
|
-
_user: user.uuid,
|
|
353
|
-
uuid: ident2.uuid
|
|
354
|
-
});
|
|
355
|
-
// Check user1 has no more ident
|
|
356
|
-
user = yield userStore.get(user1);
|
|
357
|
-
assert.strictEqual(user.idents.length, 0);
|
|
358
|
-
// Check user2 has one ident
|
|
359
|
-
user = yield userStore.get(user2);
|
|
360
|
-
assert.strictEqual(user.idents.length, 1);
|
|
361
|
-
assert.strictEqual(user.idents[0].type, "google2");
|
|
362
|
-
// Verify you cannot update a collection from patch
|
|
363
|
-
yield userStore.patch({
|
|
364
|
-
idents: []
|
|
365
|
-
}, user2);
|
|
366
|
-
user = yield userStore.get(user2);
|
|
367
|
-
assert.strictEqual(user.idents.length, 1);
|
|
368
|
-
// Verify you cannot update a collection from update
|
|
369
|
-
yield userStore.update({
|
|
370
|
-
idents: []
|
|
371
|
-
}, user2);
|
|
372
|
-
user = yield userStore.get(user2);
|
|
373
|
-
assert.strictEqual(user.idents.length, 1);
|
|
374
|
-
assert.strictEqual(user.idents[0].type, "google2");
|
|
375
|
-
// Verify delete cascade with empty collection
|
|
376
|
-
yield userStore.delete(user1);
|
|
377
|
-
user = yield userStore.get(user2);
|
|
378
|
-
assert.strictEqual(user.idents.length, 1);
|
|
379
|
-
assert.strictEqual(user.idents[0].type, "google2");
|
|
380
|
-
// Verify delete cascade
|
|
381
|
-
yield userStore.delete(user2);
|
|
382
|
-
let ident = yield identStore.get(ident2.uuid);
|
|
383
|
-
assert.strictEqual(ident.__deleted, true);
|
|
384
|
-
// Check index
|
|
385
|
-
if (index) {
|
|
386
|
-
yield index.refresh();
|
|
387
|
-
assert.strictEqual(index[ident2.uuid], undefined);
|
|
388
|
-
assert.strictEqual(index[ident1.uuid], undefined);
|
|
389
|
-
}
|
|
390
|
-
assert.strictEqual(eventFired, 9);
|
|
391
|
-
// Force sync delete - overriding the asyncDelete parameter
|
|
392
|
-
yield identStore.forceDelete(ident2.uuid);
|
|
393
|
-
ident = yield identStore.get(ident2.uuid);
|
|
394
|
-
assert.strictEqual(ident, undefined);
|
|
395
|
-
assert.strictEqual(eventFired, 11);
|
|
234
|
+
}
|
|
235
|
+
assert.strictEqual(await userStore.get(undefined), undefined);
|
|
236
|
+
user1 = (await userStore.save({
|
|
237
|
+
name: "test"
|
|
238
|
+
})).uuid;
|
|
239
|
+
let user = await userStore.get(user1);
|
|
240
|
+
// Save a user and add an ident
|
|
241
|
+
assert.notStrictEqual(user, undefined);
|
|
242
|
+
user1 = user.uuid;
|
|
243
|
+
ident1 = await identStore.save({
|
|
244
|
+
type: "facebook",
|
|
245
|
+
_user: user.uuid
|
|
396
246
|
});
|
|
247
|
+
user = await userStore.get(user1);
|
|
248
|
+
// Verify the ident is on the user
|
|
249
|
+
assert.notStrictEqual(user, undefined);
|
|
250
|
+
assert.notStrictEqual(user.idents, undefined);
|
|
251
|
+
assert.strictEqual(user.idents.length, 1);
|
|
252
|
+
// Retrieve index to verify it is in it too
|
|
253
|
+
let index = await this.getIndex();
|
|
254
|
+
// Do not force index test for store
|
|
255
|
+
if (index) {
|
|
256
|
+
assert.notStrictEqual(index[ident1.uuid], undefined);
|
|
257
|
+
assert.strictEqual(index[ident1.uuid].type, "facebook");
|
|
258
|
+
}
|
|
259
|
+
let lastUpdate = user.idents[0]._lastUpdate;
|
|
260
|
+
await this.sleep(10);
|
|
261
|
+
await identStore.incrementAttribute(ident1.uuid, "counter", 1);
|
|
262
|
+
await user.refresh();
|
|
263
|
+
assert.notStrictEqual(user.idents[0]._lastUpdate, 0);
|
|
264
|
+
this.assertLastUpdateNotEqual(user.idents[0]._lastUpdate, lastUpdate, "lastUpdate on a map after incrementAttribute");
|
|
265
|
+
lastUpdate = user.idents[0]._lastUpdate;
|
|
266
|
+
await this.sleep(10);
|
|
267
|
+
await identStore.upsertItemToCollection(ident1.uuid, "actions", {
|
|
268
|
+
uuid: "action_1",
|
|
269
|
+
type: "plop",
|
|
270
|
+
date: new Date()
|
|
271
|
+
});
|
|
272
|
+
await user.refresh();
|
|
273
|
+
assert.notStrictEqual(user.idents[0]._lastUpdate.length, 0);
|
|
274
|
+
this.assertLastUpdateNotEqual(user.idents[0]._lastUpdate, lastUpdate, "lastUpdate on a map after upsertItemToCollection");
|
|
275
|
+
lastUpdate = user.idents[0]._lastUpdate;
|
|
276
|
+
await this.sleep(10);
|
|
277
|
+
await identStore.deleteItemFromCollection(ident1.uuid, "actions", 0, "plop", "type");
|
|
278
|
+
await user.refresh();
|
|
279
|
+
assert.notStrictEqual(user.idents[0]._lastUpdate.length, 0);
|
|
280
|
+
this.assertLastUpdateNotEqual(user.idents[0]._lastUpdate, lastUpdate, "lastUpdate on a map after deleteItemFromCollection");
|
|
281
|
+
ident2 = await identStore.save({
|
|
282
|
+
type: "google",
|
|
283
|
+
_user: user.uuid
|
|
284
|
+
});
|
|
285
|
+
// Ensure Date is returned
|
|
286
|
+
assert.ok(ident2._creationDate instanceof Date);
|
|
287
|
+
assert.ok(ident2._lastUpdate instanceof Date);
|
|
288
|
+
// Add a second ident and check it is on the user aswell
|
|
289
|
+
user = await userStore.get(user1);
|
|
290
|
+
assert.strictEqual(user.idents.length, 2);
|
|
291
|
+
// Check index
|
|
292
|
+
if (index) {
|
|
293
|
+
await index.refresh();
|
|
294
|
+
assert.notStrictEqual(index[ident2.uuid], undefined);
|
|
295
|
+
}
|
|
296
|
+
ident2.type = "google2";
|
|
297
|
+
// Update ident2 to check mapper update
|
|
298
|
+
let res = await identStore.patch({
|
|
299
|
+
uuid: ident2.uuid,
|
|
300
|
+
type: "google2"
|
|
301
|
+
}, true, null);
|
|
302
|
+
assert.strictEqual(res.type, "google2");
|
|
303
|
+
assert.strictEqual(res._user, user1);
|
|
304
|
+
// Check index
|
|
305
|
+
if (index) {
|
|
306
|
+
await index.refresh();
|
|
307
|
+
assert.strictEqual(index[ident2.uuid].type, "google2");
|
|
308
|
+
}
|
|
309
|
+
user = await userStore.get(user1);
|
|
310
|
+
assert.strictEqual(user.idents.length, 2);
|
|
311
|
+
assert.strictEqual(user.idents[1].type, "google2");
|
|
312
|
+
assert.strictEqual(user.idents[1] instanceof this.getModelClass(), true);
|
|
313
|
+
await identStore.delete(ident1.uuid);
|
|
314
|
+
user = await userStore.get(user1);
|
|
315
|
+
assert.strictEqual(user.idents.length, 1);
|
|
316
|
+
assert.strictEqual(user.idents[0].type, "google2");
|
|
317
|
+
// Add a second user to play
|
|
318
|
+
user = await userStore.save({
|
|
319
|
+
name: "test2"
|
|
320
|
+
});
|
|
321
|
+
user2 = user.uuid;
|
|
322
|
+
// Move ident2 from user1 to user2
|
|
323
|
+
await identStore.patch({
|
|
324
|
+
_user: user.uuid,
|
|
325
|
+
uuid: ident2.uuid
|
|
326
|
+
});
|
|
327
|
+
// Check user1 has no more ident
|
|
328
|
+
user = await userStore.get(user1);
|
|
329
|
+
assert.strictEqual(user.idents.length, 0);
|
|
330
|
+
// Check user2 has one ident
|
|
331
|
+
user = await userStore.get(user2);
|
|
332
|
+
assert.strictEqual(user.idents.length, 1);
|
|
333
|
+
assert.strictEqual(user.idents[0].type, "google2");
|
|
334
|
+
// Verify you cannot update a collection from patch
|
|
335
|
+
await userStore.patch({
|
|
336
|
+
idents: []
|
|
337
|
+
}, user2);
|
|
338
|
+
user = await userStore.get(user2);
|
|
339
|
+
assert.strictEqual(user.idents.length, 1);
|
|
340
|
+
// Verify you cannot update a collection from update
|
|
341
|
+
await userStore.update({
|
|
342
|
+
idents: []
|
|
343
|
+
}, user2);
|
|
344
|
+
user = await userStore.get(user2);
|
|
345
|
+
assert.strictEqual(user.idents.length, 1);
|
|
346
|
+
assert.strictEqual(user.idents[0].type, "google2");
|
|
347
|
+
// Verify delete cascade with empty collection
|
|
348
|
+
await userStore.delete(user1);
|
|
349
|
+
user = await userStore.get(user2);
|
|
350
|
+
assert.strictEqual(user.idents.length, 1);
|
|
351
|
+
assert.strictEqual(user.idents[0].type, "google2");
|
|
352
|
+
// Verify delete cascade
|
|
353
|
+
await userStore.delete(user2);
|
|
354
|
+
let ident = await identStore.get(ident2.uuid);
|
|
355
|
+
assert.strictEqual(ident.__deleted, true);
|
|
356
|
+
// Check index
|
|
357
|
+
if (index) {
|
|
358
|
+
await index.refresh();
|
|
359
|
+
assert.strictEqual(index[ident2.uuid], undefined);
|
|
360
|
+
assert.strictEqual(index[ident1.uuid], undefined);
|
|
361
|
+
}
|
|
362
|
+
assert.strictEqual(eventFired, 9);
|
|
363
|
+
// Force sync delete - overriding the asyncDelete parameter
|
|
364
|
+
await identStore.forceDelete(ident2.uuid);
|
|
365
|
+
ident = await identStore.get(ident2.uuid);
|
|
366
|
+
assert.strictEqual(ident, undefined);
|
|
367
|
+
assert.strictEqual(eventFired, 11);
|
|
397
368
|
}
|
|
398
|
-
collection() {
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
date: new Date()
|
|
409
|
-
});
|
|
410
|
-
yield ident.refresh();
|
|
411
|
-
assert.notStrictEqual(ident.actions, undefined);
|
|
412
|
-
assert.strictEqual(ident.actions.length, 1);
|
|
413
|
-
yield identStore.upsertItemToCollection(ident.uuid, "actions", {
|
|
414
|
-
uuid: "action_2",
|
|
415
|
-
type: "plop",
|
|
416
|
-
date: new Date()
|
|
417
|
-
});
|
|
418
|
-
yield ident.refresh();
|
|
419
|
-
assert.notStrictEqual(ident.actions, undefined);
|
|
420
|
-
assert.strictEqual(ident.actions.length, 2);
|
|
421
|
-
yield identStore.upsertItemToCollection(ident.uuid, "actions", {
|
|
422
|
-
uuid: "action_1",
|
|
423
|
-
type: "plop2",
|
|
424
|
-
date: new Date()
|
|
425
|
-
}, 0);
|
|
426
|
-
yield ident.refresh();
|
|
427
|
-
this.log("DEBUG", "Action", ident.actions);
|
|
428
|
-
assert.notStrictEqual(ident.actions, undefined);
|
|
429
|
-
assert.strictEqual(ident.actions.length, 2);
|
|
430
|
-
assert.strictEqual(ident.actions[0].type, "plop2");
|
|
431
|
-
assert.strictEqual(ident.actions[0].uuid, "action_1");
|
|
432
|
-
yield assert.rejects(() => identStore.upsertItemToCollection(ident.uuid, "actions", {
|
|
433
|
-
uuid: "action_1",
|
|
434
|
-
type: "plop2",
|
|
435
|
-
date: new Date()
|
|
436
|
-
}, 0, "plop", "type"), err => true);
|
|
437
|
-
yield assert.rejects(() => identStore.deleteItemFromCollection(ident.uuid, "actions", 0, "action_2"), err => true);
|
|
438
|
-
yield ident.refresh();
|
|
439
|
-
assert.strictEqual(ident.actions.length, 2);
|
|
440
|
-
assert.strictEqual(ident.actions[0].type, "plop2");
|
|
441
|
-
let lastUpdate = ident._lastUpdate;
|
|
442
|
-
yield this.sleep(10);
|
|
443
|
-
yield identStore.upsertItemToCollection(ident.uuid, "actions", {
|
|
444
|
-
uuid: "action_1",
|
|
445
|
-
type: "plop",
|
|
446
|
-
date: new Date()
|
|
447
|
-
}, 0, "plop2", "type");
|
|
448
|
-
yield ident.refresh();
|
|
449
|
-
this.assertLastUpdateNotEqual(ident._lastUpdate, lastUpdate, "lastUpdate after upsertItemToColletion failed");
|
|
450
|
-
lastUpdate = ident._lastUpdate;
|
|
451
|
-
yield this.sleep(10);
|
|
452
|
-
yield identStore.deleteItemFromCollection(ident.uuid, "actions", 0, "plop", "type");
|
|
453
|
-
ident = yield identStore.get(ident.uuid);
|
|
454
|
-
this.assertLastUpdateNotEqual(ident._lastUpdate, lastUpdate, "lastUpdate after deleteItemToColletion failed");
|
|
455
|
-
assert.notStrictEqual(ident.actions, undefined);
|
|
456
|
-
assert.strictEqual(ident.actions.length, 1);
|
|
457
|
-
assert.strictEqual(ident.actions[0].type, "plop");
|
|
458
|
-
assert.strictEqual(ident.actions[0].uuid, "action_2");
|
|
369
|
+
async collection() {
|
|
370
|
+
let identStore = this.getIdentStore();
|
|
371
|
+
var ident;
|
|
372
|
+
ident = await identStore.save({
|
|
373
|
+
test: "plop"
|
|
374
|
+
});
|
|
375
|
+
await identStore.upsertItemToCollection(ident.uuid, "actions", {
|
|
376
|
+
uuid: "action_1",
|
|
377
|
+
type: "plop",
|
|
378
|
+
date: new Date()
|
|
459
379
|
});
|
|
380
|
+
await ident.refresh();
|
|
381
|
+
assert.notStrictEqual(ident.actions, undefined);
|
|
382
|
+
assert.strictEqual(ident.actions.length, 1);
|
|
383
|
+
await identStore.upsertItemToCollection(ident.uuid, "actions", {
|
|
384
|
+
uuid: "action_2",
|
|
385
|
+
type: "plop",
|
|
386
|
+
date: new Date()
|
|
387
|
+
});
|
|
388
|
+
await ident.refresh();
|
|
389
|
+
assert.notStrictEqual(ident.actions, undefined);
|
|
390
|
+
assert.strictEqual(ident.actions.length, 2);
|
|
391
|
+
await identStore.upsertItemToCollection(ident.uuid, "actions", {
|
|
392
|
+
uuid: "action_1",
|
|
393
|
+
type: "plop2",
|
|
394
|
+
date: new Date()
|
|
395
|
+
}, 0);
|
|
396
|
+
await ident.refresh();
|
|
397
|
+
this.log("DEBUG", "Action", ident.actions);
|
|
398
|
+
assert.notStrictEqual(ident.actions, undefined);
|
|
399
|
+
assert.strictEqual(ident.actions.length, 2);
|
|
400
|
+
assert.strictEqual(ident.actions[0].type, "plop2");
|
|
401
|
+
assert.strictEqual(ident.actions[0].uuid, "action_1");
|
|
402
|
+
await assert.rejects(() => identStore.upsertItemToCollection(ident.uuid, "actions", {
|
|
403
|
+
uuid: "action_1",
|
|
404
|
+
type: "plop2",
|
|
405
|
+
date: new Date()
|
|
406
|
+
}, 0, "plop", "type"), err => true);
|
|
407
|
+
await assert.rejects(() => identStore.deleteItemFromCollection(ident.uuid, "actions", 0, "action_2"), err => true);
|
|
408
|
+
await ident.refresh();
|
|
409
|
+
assert.strictEqual(ident.actions.length, 2);
|
|
410
|
+
assert.strictEqual(ident.actions[0].type, "plop2");
|
|
411
|
+
let lastUpdate = ident._lastUpdate;
|
|
412
|
+
await this.sleep(10);
|
|
413
|
+
await identStore.upsertItemToCollection(ident.uuid, "actions", {
|
|
414
|
+
uuid: "action_1",
|
|
415
|
+
type: "plop",
|
|
416
|
+
date: new Date()
|
|
417
|
+
}, 0, "plop2", "type");
|
|
418
|
+
await ident.refresh();
|
|
419
|
+
this.assertLastUpdateNotEqual(ident._lastUpdate, lastUpdate, "lastUpdate after upsertItemToColletion failed");
|
|
420
|
+
lastUpdate = ident._lastUpdate;
|
|
421
|
+
await this.sleep(10);
|
|
422
|
+
await identStore.deleteItemFromCollection(ident.uuid, "actions", 0, "plop", "type");
|
|
423
|
+
ident = await identStore.get(ident.uuid);
|
|
424
|
+
this.assertLastUpdateNotEqual(ident._lastUpdate, lastUpdate, "lastUpdate after deleteItemToColletion failed");
|
|
425
|
+
assert.notStrictEqual(ident.actions, undefined);
|
|
426
|
+
assert.strictEqual(ident.actions.length, 1);
|
|
427
|
+
assert.strictEqual(ident.actions[0].type, "plop");
|
|
428
|
+
assert.strictEqual(ident.actions[0].uuid, "action_2");
|
|
460
429
|
}
|
|
461
|
-
getAll() {
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
name: "test3"
|
|
474
|
-
});
|
|
475
|
-
let users = yield userStore.getAll();
|
|
476
|
-
assert.strictEqual(users.length, 3);
|
|
477
|
-
assert.strictEqual(users[0] instanceof userStore._model, true);
|
|
478
|
-
assert.strictEqual(users[1] instanceof userStore._model, true);
|
|
479
|
-
assert.strictEqual(users[2] instanceof userStore._model, true);
|
|
480
|
-
users = yield userStore.getAll([user1.uuid, user3.uuid, (0, uuid_1.v4)()]);
|
|
481
|
-
assert.strictEqual(users.length, 2);
|
|
482
|
-
assert.strictEqual(users[0] instanceof userStore._model, true);
|
|
483
|
-
assert.strictEqual(users[1] instanceof userStore._model, true);
|
|
430
|
+
async getAll() {
|
|
431
|
+
let userStore = this.getUserStore();
|
|
432
|
+
var user1;
|
|
433
|
+
var user3;
|
|
434
|
+
user1 = await userStore.save({
|
|
435
|
+
name: "test1"
|
|
436
|
+
});
|
|
437
|
+
await userStore.save({
|
|
438
|
+
name: "test2"
|
|
439
|
+
});
|
|
440
|
+
user3 = await userStore.save({
|
|
441
|
+
name: "test3"
|
|
484
442
|
});
|
|
443
|
+
let users = await userStore.getAll();
|
|
444
|
+
assert.strictEqual(users.length, 3);
|
|
445
|
+
assert.strictEqual(users[0] instanceof userStore._model, true);
|
|
446
|
+
assert.strictEqual(users[1] instanceof userStore._model, true);
|
|
447
|
+
assert.strictEqual(users[2] instanceof userStore._model, true);
|
|
448
|
+
users = await userStore.getAll([user1.uuid, user3.uuid, uuidv4()]);
|
|
449
|
+
assert.strictEqual(users.length, 2);
|
|
450
|
+
assert.strictEqual(users[0] instanceof userStore._model, true);
|
|
451
|
+
assert.strictEqual(users[1] instanceof userStore._model, true);
|
|
485
452
|
}
|
|
486
|
-
crud() {
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
eventFired++;
|
|
507
|
-
});
|
|
508
|
-
}
|
|
509
|
-
this.log("DEBUG", "Save ident");
|
|
510
|
-
// Check CREATE - READ
|
|
511
|
-
let ident1 = yield identStore.save({
|
|
512
|
-
test: "plop",
|
|
513
|
-
cool: "",
|
|
514
|
-
lastUsed: new Date(),
|
|
515
|
-
arr: [],
|
|
516
|
-
details: {
|
|
517
|
-
plop: "plop1",
|
|
518
|
-
clean: undefined,
|
|
519
|
-
yop: "pouf"
|
|
520
|
-
}
|
|
453
|
+
async crud() {
|
|
454
|
+
let identStore = this.getIdentStore();
|
|
455
|
+
var eventFired = 0;
|
|
456
|
+
var events = [
|
|
457
|
+
"Store.Save",
|
|
458
|
+
"Store.Saved",
|
|
459
|
+
"Store.Get",
|
|
460
|
+
"Store.Delete",
|
|
461
|
+
"Store.Deleted",
|
|
462
|
+
"Store.Update",
|
|
463
|
+
"Store.Updated",
|
|
464
|
+
"Store.PatchUpdate",
|
|
465
|
+
"Store.PatchUpdated",
|
|
466
|
+
"Store.PartialUpdated",
|
|
467
|
+
"Store.Query",
|
|
468
|
+
"Store.Queried"
|
|
469
|
+
];
|
|
470
|
+
for (let evt in events) {
|
|
471
|
+
identStore.on(events[evt], function (e) {
|
|
472
|
+
eventFired++;
|
|
521
473
|
});
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
getter.test = "plop2";
|
|
536
|
-
getter.details.plop = "plop2";
|
|
537
|
-
getter.details.blank = "";
|
|
538
|
-
getter.details.bouzouf = undefined;
|
|
539
|
-
getter.empty = [];
|
|
540
|
-
let object;
|
|
541
|
-
this.log("DEBUG", "Update ident");
|
|
542
|
-
yield identStore.update(getter);
|
|
543
|
-
assert.strictEqual(eventFired, 2);
|
|
544
|
-
eventFired = 0;
|
|
545
|
-
getter = {};
|
|
546
|
-
getter.uuid = ident1.uuid;
|
|
547
|
-
getter.bouzouf = "test";
|
|
548
|
-
this.log("DEBUG", "Patch ident");
|
|
549
|
-
yield identStore.patch(getter);
|
|
550
|
-
assert.strictEqual(eventFired, 2);
|
|
551
|
-
eventFired = 0;
|
|
552
|
-
this.log("DEBUG", "Get ident to check update");
|
|
553
|
-
object = yield identStore.get(ident1.uuid);
|
|
554
|
-
this.log("DEBUG", "Retrieved object", object);
|
|
555
|
-
assert.strictEqual(object.test, "plop2");
|
|
556
|
-
assert.strictEqual(object.details.plop, "plop2");
|
|
557
|
-
getter = yield identStore.get(object.uuid);
|
|
558
|
-
assert.strictEqual(eventFired, 2);
|
|
559
|
-
assert.strictEqual(getter.test, "plop2");
|
|
560
|
-
yield this.sleep(10);
|
|
561
|
-
this.log("DEBUG", "Increment attribute");
|
|
562
|
-
yield identStore.incrementAttribute(ident1.uuid, "counter", 1);
|
|
563
|
-
let ident = yield identStore.get(ident1.uuid);
|
|
564
|
-
// Verify lastUpdate is updated too
|
|
565
|
-
this.assertLastUpdateNotEqual(ident._lastUpdate, ident1._lastUpdate, "lastUpdate after incrementAttribute failed");
|
|
566
|
-
assert.strictEqual(ident.counter, 1);
|
|
567
|
-
yield identStore.incrementAttribute(ident1.uuid, "counter", 3);
|
|
568
|
-
ident1 = yield identStore.get(ident1.uuid);
|
|
569
|
-
assert.strictEqual(ident1.counter, 4);
|
|
570
|
-
yield identStore.incrementAttribute(ident1.uuid, "counter", -6);
|
|
571
|
-
let res = yield identStore.exists(ident1.uuid);
|
|
572
|
-
assert.strictEqual(res, true);
|
|
573
|
-
ident1 = yield identStore.get(ident1.uuid);
|
|
574
|
-
assert.strictEqual(ident1.counter, -2);
|
|
575
|
-
// Check DELETE
|
|
576
|
-
eventFired = 0;
|
|
577
|
-
yield identStore.forceDelete(ident1.uuid);
|
|
578
|
-
assert.strictEqual(eventFired, 2);
|
|
579
|
-
eventFired = 0;
|
|
580
|
-
ident = yield identStore.get(ident1.uuid);
|
|
581
|
-
assert.strictEqual(ident, undefined);
|
|
582
|
-
res = yield identStore.exists(ident1.uuid);
|
|
583
|
-
assert.strictEqual(res, false);
|
|
474
|
+
}
|
|
475
|
+
this.log("DEBUG", "Save ident");
|
|
476
|
+
// Check CREATE - READ
|
|
477
|
+
let ident1 = await identStore.save({
|
|
478
|
+
test: "plop",
|
|
479
|
+
cool: "",
|
|
480
|
+
lastUsed: new Date(),
|
|
481
|
+
arr: [],
|
|
482
|
+
details: {
|
|
483
|
+
plop: "plop1",
|
|
484
|
+
clean: undefined,
|
|
485
|
+
yop: "pouf"
|
|
486
|
+
}
|
|
584
487
|
});
|
|
488
|
+
assert.strictEqual(eventFired, 2);
|
|
489
|
+
assert.notStrictEqual(ident1, undefined);
|
|
490
|
+
eventFired = 0;
|
|
491
|
+
this.log("DEBUG", "Get ident");
|
|
492
|
+
let getter = await identStore.get(ident1.uuid);
|
|
493
|
+
assert.strictEqual(eventFired, 1);
|
|
494
|
+
eventFired = 0;
|
|
495
|
+
assert.notStrictEqual(getter, undefined);
|
|
496
|
+
assert.notStrictEqual(getter.lastUsed, undefined);
|
|
497
|
+
assert.notStrictEqual(getter._lastUpdate, undefined);
|
|
498
|
+
assert.strictEqual(getter.uuid, ident1.uuid);
|
|
499
|
+
assert.strictEqual(getter.test, ident1.test);
|
|
500
|
+
// Check UPDATE
|
|
501
|
+
getter.test = "plop2";
|
|
502
|
+
getter.details.plop = "plop2";
|
|
503
|
+
getter.details.blank = "";
|
|
504
|
+
getter.details.bouzouf = undefined;
|
|
505
|
+
getter.empty = [];
|
|
506
|
+
let object;
|
|
507
|
+
this.log("DEBUG", "Update ident");
|
|
508
|
+
await identStore.update(getter);
|
|
509
|
+
assert.strictEqual(eventFired, 2);
|
|
510
|
+
eventFired = 0;
|
|
511
|
+
getter = {};
|
|
512
|
+
getter.uuid = ident1.uuid;
|
|
513
|
+
getter.bouzouf = "test";
|
|
514
|
+
this.log("DEBUG", "Patch ident");
|
|
515
|
+
await identStore.patch(getter);
|
|
516
|
+
assert.strictEqual(eventFired, 2);
|
|
517
|
+
eventFired = 0;
|
|
518
|
+
this.log("DEBUG", "Get ident to check update");
|
|
519
|
+
object = await identStore.get(ident1.uuid);
|
|
520
|
+
this.log("DEBUG", "Retrieved object", object);
|
|
521
|
+
assert.strictEqual(object.test, "plop2");
|
|
522
|
+
assert.strictEqual(object.details.plop, "plop2");
|
|
523
|
+
getter = await identStore.get(object.uuid);
|
|
524
|
+
assert.strictEqual(eventFired, 2);
|
|
525
|
+
assert.strictEqual(getter.test, "plop2");
|
|
526
|
+
await this.sleep(10);
|
|
527
|
+
this.log("DEBUG", "Increment attribute");
|
|
528
|
+
await identStore.incrementAttribute(ident1.uuid, "counter", 1);
|
|
529
|
+
let ident = await identStore.get(ident1.uuid);
|
|
530
|
+
// Verify lastUpdate is updated too
|
|
531
|
+
this.assertLastUpdateNotEqual(ident._lastUpdate, ident1._lastUpdate, "lastUpdate after incrementAttribute failed");
|
|
532
|
+
assert.strictEqual(ident.counter, 1);
|
|
533
|
+
await identStore.incrementAttribute(ident1.uuid, "counter", 3);
|
|
534
|
+
ident1 = await identStore.get(ident1.uuid);
|
|
535
|
+
assert.strictEqual(ident1.counter, 4);
|
|
536
|
+
await identStore.incrementAttribute(ident1.uuid, "counter", -6);
|
|
537
|
+
let res = await identStore.exists(ident1.uuid);
|
|
538
|
+
assert.strictEqual(res, true);
|
|
539
|
+
ident1 = await identStore.get(ident1.uuid);
|
|
540
|
+
assert.strictEqual(ident1.counter, -2);
|
|
541
|
+
// Check DELETE
|
|
542
|
+
eventFired = 0;
|
|
543
|
+
await identStore.forceDelete(ident1.uuid);
|
|
544
|
+
assert.strictEqual(eventFired, 2);
|
|
545
|
+
eventFired = 0;
|
|
546
|
+
ident = await identStore.get(ident1.uuid);
|
|
547
|
+
assert.strictEqual(ident, undefined);
|
|
548
|
+
res = await identStore.exists(ident1.uuid);
|
|
549
|
+
assert.strictEqual(res, false);
|
|
585
550
|
}
|
|
586
551
|
assertLastUpdateNotEqual(d1, d2, msg) {
|
|
587
552
|
assert.notStrictEqual(d1, d2, msg);
|
|
588
553
|
}
|
|
589
|
-
exists() {
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
assert.ok(!(yield store.exists((0, uuid_1.v4)())));
|
|
595
|
-
});
|
|
554
|
+
async exists() {
|
|
555
|
+
let store = this.getIdentStore();
|
|
556
|
+
let model = await store.save({});
|
|
557
|
+
assert.ok(await store.exists(model.getUuid()));
|
|
558
|
+
assert.ok(!(await store.exists(uuidv4())));
|
|
596
559
|
}
|
|
597
|
-
incrementAttribute() {
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
yield assert.rejects(() => store.incrementAttribute((0, uuid_1.v4)(), "counter", 1), store_1.StoreNotFoundError);
|
|
607
|
-
});
|
|
560
|
+
async incrementAttribute() {
|
|
561
|
+
let store = this.getIdentStore();
|
|
562
|
+
let model = await store.save({ counter: 0 });
|
|
563
|
+
await store.incrementAttribute(model.getUuid(), "counter", 3);
|
|
564
|
+
await store.incrementAttribute(model.getUuid(), "counter2", 2);
|
|
565
|
+
await model.refresh();
|
|
566
|
+
assert.strictEqual(model.counter, 3);
|
|
567
|
+
assert.strictEqual(model.counter2, 2);
|
|
568
|
+
await assert.rejects(() => store.incrementAttribute(uuidv4(), "counter", 1), StoreNotFoundError);
|
|
608
569
|
}
|
|
609
|
-
removeAttribute() {
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
assert.strictEqual(model.counter2, 12);
|
|
620
|
-
});
|
|
570
|
+
async removeAttribute() {
|
|
571
|
+
let store = this.getIdentStore();
|
|
572
|
+
let model = await store.save({ counter: 0, counter2: 12, counter3: 13 });
|
|
573
|
+
await store.removeAttribute(model.getUuid(), "counter");
|
|
574
|
+
await model.refresh();
|
|
575
|
+
assert.strictEqual(model.counter, undefined);
|
|
576
|
+
await assert.rejects(() => store.removeAttribute(uuidv4(), "counter"), StoreNotFoundError);
|
|
577
|
+
await assert.rejects(() => store.removeAttribute(model.getUuid(), "counter2", 10, "counter3"), UpdateConditionFailError);
|
|
578
|
+
await model.refresh();
|
|
579
|
+
assert.strictEqual(model.counter2, 12);
|
|
621
580
|
}
|
|
622
|
-
setAttribute() {
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
yield store._update(model, model.getUuid());
|
|
635
|
-
yield this.sleep(1);
|
|
636
|
-
}));
|
|
637
|
-
yield assert.rejects(() => store.setAttribute(model.getUuid(), "counter", 4), store_1.UpdateConditionFailError);
|
|
638
|
-
store.removeAllListeners("Store.PatchUpdate");
|
|
639
|
-
store.on("Store.PatchUpdate", () => __awaiter(this, void 0, void 0, function* () {
|
|
640
|
-
yield store._delete(model.getUuid());
|
|
641
|
-
yield this.sleep(1);
|
|
642
|
-
}));
|
|
643
|
-
yield assert.rejects(() => store.setAttribute(model.getUuid(), "counter", 4), err => err instanceof store_1.StoreNotFoundError || err instanceof store_1.UpdateConditionFailError);
|
|
644
|
-
yield assert.rejects(() => store.setAttribute((0, uuid_1.v4)(), "counter", 4), err => err instanceof store_1.StoreNotFoundError || err instanceof store_1.UpdateConditionFailError);
|
|
581
|
+
async setAttribute() {
|
|
582
|
+
let store = this.getIdentStore();
|
|
583
|
+
let model = await store.save({ counter: 0 });
|
|
584
|
+
await store.setAttribute(model.getUuid(), "counter", 3);
|
|
585
|
+
await store.setAttribute(model.getUuid(), "status", "TESTED");
|
|
586
|
+
await model.refresh();
|
|
587
|
+
assert.strictEqual(model.counter, 3);
|
|
588
|
+
assert.strictEqual(model.status, "TESTED");
|
|
589
|
+
await assert.rejects(() => store.setAttribute(uuidv4(), "counter", 4), StoreNotFoundError);
|
|
590
|
+
store.on("Store.PatchUpdate", async () => {
|
|
591
|
+
model._lastUpdate = new Date(100);
|
|
592
|
+
await store._update(model, model.getUuid());
|
|
645
593
|
});
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
// Delete with condition
|
|
652
|
-
yield assert.rejects(() => store.delete(model.getUuid(), 4, "counter"), store_1.UpdateConditionFailError);
|
|
653
|
-
yield store.delete(model.getUuid(), 1, "counter");
|
|
654
|
-
// Test without condition
|
|
655
|
-
model = yield store.save({ counter: 2 });
|
|
656
|
-
yield store.delete(model);
|
|
657
|
-
// Deleting a non-existing object should be ignored
|
|
658
|
-
yield store.forceDelete((0, uuid_1.v4)());
|
|
594
|
+
await assert.rejects(() => store.setAttribute(model.getUuid(), "counter", 4), UpdateConditionFailError);
|
|
595
|
+
store.removeAllListeners("Store.PatchUpdate");
|
|
596
|
+
store.on("Store.PatchUpdate", async () => {
|
|
597
|
+
await store._delete(model.getUuid());
|
|
598
|
+
await this.sleep(1);
|
|
659
599
|
});
|
|
600
|
+
await assert.rejects(() => store.setAttribute(model.getUuid(), "counter", 4), err => err instanceof StoreNotFoundError || err instanceof UpdateConditionFailError);
|
|
601
|
+
await assert.rejects(() => store.setAttribute(uuidv4(), "counter", 4), err => err instanceof StoreNotFoundError || err instanceof UpdateConditionFailError);
|
|
660
602
|
}
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
// Deleting a non-existing object should be ignored
|
|
673
|
-
yield store.forceDelete((0, uuid_1.v4)());
|
|
674
|
-
});
|
|
603
|
+
async deleteAsync() {
|
|
604
|
+
let store = this.getIdentStore();
|
|
605
|
+
let model = await store.save({ counter: 1 });
|
|
606
|
+
// Delete with condition
|
|
607
|
+
await assert.rejects(() => store.delete(model.getUuid(), 4, "counter"), UpdateConditionFailError);
|
|
608
|
+
await store.delete(model.getUuid(), 1, "counter");
|
|
609
|
+
// Test without condition
|
|
610
|
+
model = await store.save({ counter: 2 });
|
|
611
|
+
await store.delete(model);
|
|
612
|
+
// Deleting a non-existing object should be ignored
|
|
613
|
+
await store.forceDelete(uuidv4());
|
|
675
614
|
}
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
615
|
+
async delete() {
|
|
616
|
+
// UserStore is not supposed to be async
|
|
617
|
+
let store = this.getUserStore();
|
|
618
|
+
let model = await store.save({ counter: 1 });
|
|
619
|
+
// Delete with condition
|
|
620
|
+
await assert.rejects(() => store.delete(model.getUuid(), 4, "counter"), UpdateConditionFailError);
|
|
621
|
+
await store.delete(model.getUuid(), 1, "counter");
|
|
622
|
+
// Test without condition
|
|
623
|
+
model = await store.save({ counter: 2 });
|
|
624
|
+
await store.delete(model);
|
|
625
|
+
// Deleting a non-existing object should be ignored
|
|
626
|
+
await store.forceDelete(uuidv4());
|
|
687
627
|
}
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
plop: 12,
|
|
694
|
-
counter: 2
|
|
695
|
-
}, "counter", 1));
|
|
696
|
-
assert.strictEqual((yield store.get(model.getUuid())).plop, 12);
|
|
697
|
-
assert.ok(!(yield store.conditionalPatch(model.getUuid(), {
|
|
698
|
-
plop: 13
|
|
699
|
-
}, "counter", 1)));
|
|
700
|
-
assert.strictEqual((yield store.get(model.getUuid())).plop, 12);
|
|
701
|
-
(0, sinon_1.stub)(store, "_patch").callsFake(() => {
|
|
702
|
-
throw new Error("Fake Error");
|
|
703
|
-
});
|
|
704
|
-
yield assert.rejects(() => store.conditionalPatch(model.getUuid(), {
|
|
705
|
-
plop: 12,
|
|
706
|
-
counter: 2
|
|
707
|
-
}, "counter", 1), /Fake Error/);
|
|
628
|
+
async deleteConcurrent() {
|
|
629
|
+
let store = this.getUserStore();
|
|
630
|
+
let model = await store.save({ counter: 1 });
|
|
631
|
+
store.addListener("Store.Delete", async () => {
|
|
632
|
+
await store.incrementAttribute(model.getUuid(), "counter", 1);
|
|
708
633
|
});
|
|
634
|
+
await assert.rejects(() => store.delete(model.getUuid(), 1, "counter"), UpdateConditionFailError);
|
|
635
|
+
store.removeAllListeners();
|
|
636
|
+
await store.delete(model.getUuid(), 2, "counter");
|
|
709
637
|
}
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
store.on("Store.Update", () => __awaiter(this, void 0, void 0, function* () {
|
|
725
|
-
yield store._delete(model.getUuid());
|
|
726
|
-
yield this.sleep(delay);
|
|
727
|
-
}));
|
|
728
|
-
yield assert.rejects(() => store.update(model), err => err instanceof store_1.StoreNotFoundError || err instanceof store_1.UpdateConditionFailError);
|
|
729
|
-
yield assert.rejects(() => store.update({ uuid: (0, uuid_1.v4)(), test: true }), err => err instanceof store_1.StoreNotFoundError || err instanceof store_1.UpdateConditionFailError);
|
|
638
|
+
async conditionUpdate() {
|
|
639
|
+
let store = this.getIdentStore();
|
|
640
|
+
let model = await store.save({ counter: 1 });
|
|
641
|
+
assert.ok(await store.conditionalPatch(model.getUuid(), {
|
|
642
|
+
plop: 12,
|
|
643
|
+
counter: 2
|
|
644
|
+
}, "counter", 1));
|
|
645
|
+
assert.strictEqual((await store.get(model.getUuid())).plop, 12);
|
|
646
|
+
assert.ok(!(await store.conditionalPatch(model.getUuid(), {
|
|
647
|
+
plop: 13
|
|
648
|
+
}, "counter", 1)));
|
|
649
|
+
assert.strictEqual((await store.get(model.getUuid())).plop, 12);
|
|
650
|
+
stub(store, "_patch").callsFake(() => {
|
|
651
|
+
throw new Error("Fake Error");
|
|
730
652
|
});
|
|
653
|
+
await assert.rejects(() => store.conditionalPatch(model.getUuid(), {
|
|
654
|
+
plop: 12,
|
|
655
|
+
counter: 2
|
|
656
|
+
}, "counter", 1), /Fake Error/);
|
|
731
657
|
}
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
for (let i = 0; i < 10; i++) {
|
|
740
|
-
ps.push(store.upsertItemToCollection(model.getUuid(), "logs", `line${i}`));
|
|
741
|
-
}
|
|
742
|
-
yield Promise.all(ps);
|
|
743
|
-
yield model.refresh();
|
|
744
|
-
assert.strictEqual(model.logs.length, 10);
|
|
745
|
-
// Depending on the implementation it can be swallowed by the backend
|
|
746
|
-
this.log("DEBUG", "Upsert on unknown doc");
|
|
747
|
-
yield assert.rejects(() => store.upsertItemToCollection((0, uuid_1.v4)(), "logs", `line`), err => err instanceof store_1.StoreNotFoundError || err instanceof store_1.UpdateConditionFailError);
|
|
748
|
-
this.log("DEBUG", "Delete on unknown doc");
|
|
749
|
-
yield assert.rejects(() => store.deleteItemFromCollection((0, uuid_1.v4)(), "logs", 0, undefined, undefined), err => err instanceof store_1.StoreNotFoundError || err instanceof store_1.UpdateConditionFailError);
|
|
658
|
+
async update(delay = 1) {
|
|
659
|
+
let store = this.getIdentStore();
|
|
660
|
+
let model = await store.save({ counter: 1 });
|
|
661
|
+
let model2 = await store.get(model.getUuid());
|
|
662
|
+
store.on("Store.Update", async () => {
|
|
663
|
+
model2._lastUpdate = new Date(100);
|
|
664
|
+
await store._update(model2, model2.getUuid());
|
|
750
665
|
});
|
|
666
|
+
model.plop = "yop";
|
|
667
|
+
// Delete with condition
|
|
668
|
+
await assert.rejects(() => store.update(model), UpdateConditionFailError);
|
|
669
|
+
store.removeAllListeners("Store.Update");
|
|
670
|
+
store.on("Store.Update", async () => {
|
|
671
|
+
await store._delete(model.getUuid());
|
|
672
|
+
await this.sleep(delay);
|
|
673
|
+
});
|
|
674
|
+
await assert.rejects(() => store.update(model), err => err instanceof StoreNotFoundError || err instanceof UpdateConditionFailError);
|
|
675
|
+
await assert.rejects(() => store.update({ uuid: uuidv4(), test: true }), err => err instanceof StoreNotFoundError || err instanceof UpdateConditionFailError);
|
|
676
|
+
}
|
|
677
|
+
async upsertItem() {
|
|
678
|
+
let store = this.getIdentStore();
|
|
679
|
+
this.log("DEBUG", "Save empty logs array");
|
|
680
|
+
let model = await store.save({ logs: [] });
|
|
681
|
+
let ps = [];
|
|
682
|
+
this.log("DEBUG", "Upsert 10 lines");
|
|
683
|
+
for (let i = 0; i < 10; i++) {
|
|
684
|
+
ps.push(store.upsertItemToCollection(model.getUuid(), "logs", `line${i}`));
|
|
685
|
+
}
|
|
686
|
+
await Promise.all(ps);
|
|
687
|
+
await model.refresh();
|
|
688
|
+
assert.strictEqual(model.logs.length, 10);
|
|
689
|
+
// Depending on the implementation it can be swallowed by the backend
|
|
690
|
+
this.log("DEBUG", "Upsert on unknown doc");
|
|
691
|
+
await assert.rejects(() => store.upsertItemToCollection(uuidv4(), "logs", `line`), err => err instanceof StoreNotFoundError || err instanceof UpdateConditionFailError);
|
|
692
|
+
this.log("DEBUG", "Delete on unknown doc");
|
|
693
|
+
await assert.rejects(() => store.deleteItemFromCollection(uuidv4(), "logs", 0, undefined, undefined), err => err instanceof StoreNotFoundError || err instanceof UpdateConditionFailError);
|
|
694
|
+
}
|
|
695
|
+
async put() {
|
|
696
|
+
const store = this.getIdentStore();
|
|
697
|
+
const uuid = store.getWebda().getUuid();
|
|
698
|
+
if (await store.exists(uuid)) {
|
|
699
|
+
await store.delete(uuid);
|
|
700
|
+
}
|
|
701
|
+
await store.put(uuid, { test: true });
|
|
702
|
+
// Verify put acts like a upsert
|
|
703
|
+
await store.put(uuid, { test: false });
|
|
751
704
|
}
|
|
752
705
|
}
|
|
753
706
|
__decorate([
|
|
754
|
-
|
|
707
|
+
test
|
|
755
708
|
], StoreTest.prototype, "query", null);
|
|
756
709
|
__decorate([
|
|
757
|
-
|
|
710
|
+
test
|
|
758
711
|
], StoreTest.prototype, "queryOrder", null);
|
|
759
712
|
__decorate([
|
|
760
|
-
|
|
713
|
+
test
|
|
761
714
|
], StoreTest.prototype, "mapper", null);
|
|
762
715
|
__decorate([
|
|
763
|
-
|
|
716
|
+
test
|
|
764
717
|
], StoreTest.prototype, "collection", null);
|
|
765
718
|
__decorate([
|
|
766
|
-
|
|
719
|
+
test
|
|
767
720
|
], StoreTest.prototype, "getAll", null);
|
|
768
721
|
__decorate([
|
|
769
|
-
|
|
722
|
+
test
|
|
770
723
|
], StoreTest.prototype, "crud", null);
|
|
771
724
|
__decorate([
|
|
772
|
-
|
|
725
|
+
test
|
|
773
726
|
], StoreTest.prototype, "exists", null);
|
|
774
727
|
__decorate([
|
|
775
|
-
|
|
728
|
+
test
|
|
776
729
|
], StoreTest.prototype, "incrementAttribute", null);
|
|
777
730
|
__decorate([
|
|
778
|
-
|
|
731
|
+
test
|
|
779
732
|
], StoreTest.prototype, "removeAttribute", null);
|
|
780
733
|
__decorate([
|
|
781
|
-
|
|
734
|
+
test
|
|
782
735
|
], StoreTest.prototype, "setAttribute", null);
|
|
783
736
|
__decorate([
|
|
784
|
-
|
|
737
|
+
test
|
|
785
738
|
], StoreTest.prototype, "deleteAsync", null);
|
|
786
739
|
__decorate([
|
|
787
|
-
|
|
740
|
+
test
|
|
788
741
|
], StoreTest.prototype, "delete", null);
|
|
789
742
|
__decorate([
|
|
790
|
-
|
|
743
|
+
test
|
|
791
744
|
], StoreTest.prototype, "conditionUpdate", null);
|
|
792
745
|
__decorate([
|
|
793
|
-
|
|
746
|
+
test
|
|
794
747
|
], StoreTest.prototype, "update", null);
|
|
795
748
|
__decorate([
|
|
796
|
-
|
|
749
|
+
test
|
|
797
750
|
], StoreTest.prototype, "upsertItem", null);
|
|
798
|
-
|
|
751
|
+
__decorate([
|
|
752
|
+
test
|
|
753
|
+
], StoreTest.prototype, "put", null);
|
|
754
|
+
export { StoreTest };
|
|
799
755
|
//# sourceMappingURL=store.spec.js.map
|