@webda/core 2.0.0-beta.3 → 2.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/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 +20 -24
- package/lib/core.js +222 -315
- package/lib/core.js.map +1 -1
- package/lib/core.spec.js +332 -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 +127 -152
- package/lib/models/aclmodel.spec.js.map +1 -1
- package/lib/models/coremodel.d.ts +7 -6
- package/lib/models/coremodel.js +65 -113
- package/lib/models/coremodel.js.map +1 -1
- package/lib/models/coremodel.spec.js +88 -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 +3 -3
- 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 +537 -563
- 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 +7 -5
- package/lib/services/binary.js +211 -244
- 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 +7 -7
- package/lib/services/invitationservice.js +274 -314
- package/lib/services/invitationservice.js.map +1 -1
- package/lib/services/invitationservice.spec.js +442 -448
- 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 +261 -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 +131 -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 +17 -13
- package/lib/stores/store.js +819 -847
- package/lib/stores/store.js.map +1 -1
- package/lib/stores/store.spec.d.ts +5 -4
- package/lib/stores/store.spec.js +624 -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 +25 -31
- 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 +17 -12
- 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 +956 -189
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,583 @@ 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
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
assert.
|
|
339
|
-
assert.strictEqual(
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
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
|
|
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
|
|
396
284
|
});
|
|
285
|
+
// Add a second ident and check it is on the user aswell
|
|
286
|
+
user = await userStore.get(user1);
|
|
287
|
+
assert.strictEqual(user.idents.length, 2);
|
|
288
|
+
// Check index
|
|
289
|
+
if (index) {
|
|
290
|
+
await index.refresh();
|
|
291
|
+
assert.notStrictEqual(index[ident2.uuid], undefined);
|
|
292
|
+
}
|
|
293
|
+
ident2.type = "google2";
|
|
294
|
+
// Update ident2 to check mapper update
|
|
295
|
+
let res = await identStore.patch({
|
|
296
|
+
uuid: ident2.uuid,
|
|
297
|
+
type: "google2"
|
|
298
|
+
});
|
|
299
|
+
assert.strictEqual(res.type, "google2");
|
|
300
|
+
assert.strictEqual(res._user, user1);
|
|
301
|
+
// Check index
|
|
302
|
+
if (index) {
|
|
303
|
+
await index.refresh();
|
|
304
|
+
assert.strictEqual(index[ident2.uuid].type, "google2");
|
|
305
|
+
}
|
|
306
|
+
user = await userStore.get(user1);
|
|
307
|
+
assert.strictEqual(user.idents.length, 2);
|
|
308
|
+
assert.strictEqual(user.idents[1].type, "google2");
|
|
309
|
+
assert.strictEqual(user.idents[1] instanceof this.getModelClass(), true);
|
|
310
|
+
await identStore.delete(ident1.uuid);
|
|
311
|
+
user = await userStore.get(user1);
|
|
312
|
+
assert.strictEqual(user.idents.length, 1);
|
|
313
|
+
assert.strictEqual(user.idents[0].type, "google2");
|
|
314
|
+
// Add a second user to play
|
|
315
|
+
user = await userStore.save({
|
|
316
|
+
name: "test2"
|
|
317
|
+
});
|
|
318
|
+
user2 = user.uuid;
|
|
319
|
+
// Move ident2 from user1 to user2
|
|
320
|
+
await identStore.patch({
|
|
321
|
+
_user: user.uuid,
|
|
322
|
+
uuid: ident2.uuid
|
|
323
|
+
});
|
|
324
|
+
// Check user1 has no more ident
|
|
325
|
+
user = await userStore.get(user1);
|
|
326
|
+
assert.strictEqual(user.idents.length, 0);
|
|
327
|
+
// Check user2 has one ident
|
|
328
|
+
user = await userStore.get(user2);
|
|
329
|
+
assert.strictEqual(user.idents.length, 1);
|
|
330
|
+
assert.strictEqual(user.idents[0].type, "google2");
|
|
331
|
+
// Verify you cannot update a collection from patch
|
|
332
|
+
await userStore.patch({
|
|
333
|
+
idents: []
|
|
334
|
+
}, user2);
|
|
335
|
+
user = await userStore.get(user2);
|
|
336
|
+
assert.strictEqual(user.idents.length, 1);
|
|
337
|
+
// Verify you cannot update a collection from update
|
|
338
|
+
await userStore.update({
|
|
339
|
+
idents: []
|
|
340
|
+
}, user2);
|
|
341
|
+
user = await userStore.get(user2);
|
|
342
|
+
assert.strictEqual(user.idents.length, 1);
|
|
343
|
+
assert.strictEqual(user.idents[0].type, "google2");
|
|
344
|
+
// Verify delete cascade with empty collection
|
|
345
|
+
await userStore.delete(user1);
|
|
346
|
+
user = await userStore.get(user2);
|
|
347
|
+
assert.strictEqual(user.idents.length, 1);
|
|
348
|
+
assert.strictEqual(user.idents[0].type, "google2");
|
|
349
|
+
// Verify delete cascade
|
|
350
|
+
await userStore.delete(user2);
|
|
351
|
+
let ident = await identStore.get(ident2.uuid);
|
|
352
|
+
assert.strictEqual(ident.__deleted, true);
|
|
353
|
+
// Check index
|
|
354
|
+
if (index) {
|
|
355
|
+
await index.refresh();
|
|
356
|
+
assert.strictEqual(index[ident2.uuid], undefined);
|
|
357
|
+
assert.strictEqual(index[ident1.uuid], undefined);
|
|
358
|
+
}
|
|
359
|
+
assert.strictEqual(eventFired, 9);
|
|
360
|
+
// Force sync delete - overriding the asyncDelete parameter
|
|
361
|
+
await identStore.forceDelete(ident2.uuid);
|
|
362
|
+
ident = await identStore.get(ident2.uuid);
|
|
363
|
+
assert.strictEqual(ident, undefined);
|
|
364
|
+
assert.strictEqual(eventFired, 11);
|
|
397
365
|
}
|
|
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");
|
|
366
|
+
async collection() {
|
|
367
|
+
let identStore = this.getIdentStore();
|
|
368
|
+
var ident;
|
|
369
|
+
ident = await identStore.save({
|
|
370
|
+
test: "plop"
|
|
371
|
+
});
|
|
372
|
+
await identStore.upsertItemToCollection(ident.uuid, "actions", {
|
|
373
|
+
uuid: "action_1",
|
|
374
|
+
type: "plop",
|
|
375
|
+
date: new Date()
|
|
459
376
|
});
|
|
377
|
+
await ident.refresh();
|
|
378
|
+
assert.notStrictEqual(ident.actions, undefined);
|
|
379
|
+
assert.strictEqual(ident.actions.length, 1);
|
|
380
|
+
await identStore.upsertItemToCollection(ident.uuid, "actions", {
|
|
381
|
+
uuid: "action_2",
|
|
382
|
+
type: "plop",
|
|
383
|
+
date: new Date()
|
|
384
|
+
});
|
|
385
|
+
await ident.refresh();
|
|
386
|
+
assert.notStrictEqual(ident.actions, undefined);
|
|
387
|
+
assert.strictEqual(ident.actions.length, 2);
|
|
388
|
+
await identStore.upsertItemToCollection(ident.uuid, "actions", {
|
|
389
|
+
uuid: "action_1",
|
|
390
|
+
type: "plop2",
|
|
391
|
+
date: new Date()
|
|
392
|
+
}, 0);
|
|
393
|
+
await ident.refresh();
|
|
394
|
+
this.log("DEBUG", "Action", ident.actions);
|
|
395
|
+
assert.notStrictEqual(ident.actions, undefined);
|
|
396
|
+
assert.strictEqual(ident.actions.length, 2);
|
|
397
|
+
assert.strictEqual(ident.actions[0].type, "plop2");
|
|
398
|
+
assert.strictEqual(ident.actions[0].uuid, "action_1");
|
|
399
|
+
await assert.rejects(() => identStore.upsertItemToCollection(ident.uuid, "actions", {
|
|
400
|
+
uuid: "action_1",
|
|
401
|
+
type: "plop2",
|
|
402
|
+
date: new Date()
|
|
403
|
+
}, 0, "plop", "type"), err => true);
|
|
404
|
+
await assert.rejects(() => identStore.deleteItemFromCollection(ident.uuid, "actions", 0, "action_2"), err => true);
|
|
405
|
+
await ident.refresh();
|
|
406
|
+
assert.strictEqual(ident.actions.length, 2);
|
|
407
|
+
assert.strictEqual(ident.actions[0].type, "plop2");
|
|
408
|
+
let lastUpdate = ident._lastUpdate;
|
|
409
|
+
await this.sleep(10);
|
|
410
|
+
await identStore.upsertItemToCollection(ident.uuid, "actions", {
|
|
411
|
+
uuid: "action_1",
|
|
412
|
+
type: "plop",
|
|
413
|
+
date: new Date()
|
|
414
|
+
}, 0, "plop2", "type");
|
|
415
|
+
await ident.refresh();
|
|
416
|
+
this.assertLastUpdateNotEqual(ident._lastUpdate, lastUpdate, "lastUpdate after upsertItemToColletion failed");
|
|
417
|
+
lastUpdate = ident._lastUpdate;
|
|
418
|
+
await this.sleep(10);
|
|
419
|
+
await identStore.deleteItemFromCollection(ident.uuid, "actions", 0, "plop", "type");
|
|
420
|
+
ident = await identStore.get(ident.uuid);
|
|
421
|
+
this.assertLastUpdateNotEqual(ident._lastUpdate, lastUpdate, "lastUpdate after deleteItemToColletion failed");
|
|
422
|
+
assert.notStrictEqual(ident.actions, undefined);
|
|
423
|
+
assert.strictEqual(ident.actions.length, 1);
|
|
424
|
+
assert.strictEqual(ident.actions[0].type, "plop");
|
|
425
|
+
assert.strictEqual(ident.actions[0].uuid, "action_2");
|
|
460
426
|
}
|
|
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);
|
|
427
|
+
async getAll() {
|
|
428
|
+
let userStore = this.getUserStore();
|
|
429
|
+
var user1;
|
|
430
|
+
var user3;
|
|
431
|
+
user1 = await userStore.save({
|
|
432
|
+
name: "test1"
|
|
433
|
+
});
|
|
434
|
+
await userStore.save({
|
|
435
|
+
name: "test2"
|
|
436
|
+
});
|
|
437
|
+
user3 = await userStore.save({
|
|
438
|
+
name: "test3"
|
|
484
439
|
});
|
|
440
|
+
let users = await userStore.getAll();
|
|
441
|
+
assert.strictEqual(users.length, 3);
|
|
442
|
+
assert.strictEqual(users[0] instanceof userStore._model, true);
|
|
443
|
+
assert.strictEqual(users[1] instanceof userStore._model, true);
|
|
444
|
+
assert.strictEqual(users[2] instanceof userStore._model, true);
|
|
445
|
+
users = await userStore.getAll([user1.uuid, user3.uuid, uuidv4()]);
|
|
446
|
+
assert.strictEqual(users.length, 2);
|
|
447
|
+
assert.strictEqual(users[0] instanceof userStore._model, true);
|
|
448
|
+
assert.strictEqual(users[1] instanceof userStore._model, true);
|
|
485
449
|
}
|
|
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
|
-
}
|
|
450
|
+
async crud() {
|
|
451
|
+
let identStore = this.getIdentStore();
|
|
452
|
+
var eventFired = 0;
|
|
453
|
+
var events = [
|
|
454
|
+
"Store.Save",
|
|
455
|
+
"Store.Saved",
|
|
456
|
+
"Store.Get",
|
|
457
|
+
"Store.Delete",
|
|
458
|
+
"Store.Deleted",
|
|
459
|
+
"Store.Update",
|
|
460
|
+
"Store.Updated",
|
|
461
|
+
"Store.PatchUpdate",
|
|
462
|
+
"Store.PatchUpdated",
|
|
463
|
+
"Store.PartialUpdated",
|
|
464
|
+
"Store.Query",
|
|
465
|
+
"Store.Queried"
|
|
466
|
+
];
|
|
467
|
+
for (let evt in events) {
|
|
468
|
+
identStore.on(events[evt], function (e) {
|
|
469
|
+
eventFired++;
|
|
521
470
|
});
|
|
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);
|
|
471
|
+
}
|
|
472
|
+
this.log("DEBUG", "Save ident");
|
|
473
|
+
// Check CREATE - READ
|
|
474
|
+
let ident1 = await identStore.save({
|
|
475
|
+
test: "plop",
|
|
476
|
+
cool: "",
|
|
477
|
+
lastUsed: new Date(),
|
|
478
|
+
arr: [],
|
|
479
|
+
details: {
|
|
480
|
+
plop: "plop1",
|
|
481
|
+
clean: undefined,
|
|
482
|
+
yop: "pouf"
|
|
483
|
+
}
|
|
584
484
|
});
|
|
485
|
+
assert.strictEqual(eventFired, 2);
|
|
486
|
+
assert.notStrictEqual(ident1, undefined);
|
|
487
|
+
eventFired = 0;
|
|
488
|
+
this.log("DEBUG", "Get ident");
|
|
489
|
+
let getter = await identStore.get(ident1.uuid);
|
|
490
|
+
assert.strictEqual(eventFired, 1);
|
|
491
|
+
eventFired = 0;
|
|
492
|
+
assert.notStrictEqual(getter, undefined);
|
|
493
|
+
assert.notStrictEqual(getter.lastUsed, undefined);
|
|
494
|
+
assert.notStrictEqual(getter._lastUpdate, undefined);
|
|
495
|
+
assert.strictEqual(getter.uuid, ident1.uuid);
|
|
496
|
+
assert.strictEqual(getter.test, ident1.test);
|
|
497
|
+
// Check UPDATE
|
|
498
|
+
getter.test = "plop2";
|
|
499
|
+
getter.details.plop = "plop2";
|
|
500
|
+
getter.details.blank = "";
|
|
501
|
+
getter.details.bouzouf = undefined;
|
|
502
|
+
getter.empty = [];
|
|
503
|
+
let object;
|
|
504
|
+
this.log("DEBUG", "Update ident");
|
|
505
|
+
await identStore.update(getter);
|
|
506
|
+
assert.strictEqual(eventFired, 2);
|
|
507
|
+
eventFired = 0;
|
|
508
|
+
getter = {};
|
|
509
|
+
getter.uuid = ident1.uuid;
|
|
510
|
+
getter.bouzouf = "test";
|
|
511
|
+
this.log("DEBUG", "Patch ident");
|
|
512
|
+
await identStore.patch(getter);
|
|
513
|
+
assert.strictEqual(eventFired, 2);
|
|
514
|
+
eventFired = 0;
|
|
515
|
+
this.log("DEBUG", "Get ident to check update");
|
|
516
|
+
object = await identStore.get(ident1.uuid);
|
|
517
|
+
this.log("DEBUG", "Retrieved object", object);
|
|
518
|
+
assert.strictEqual(object.test, "plop2");
|
|
519
|
+
assert.strictEqual(object.details.plop, "plop2");
|
|
520
|
+
getter = await identStore.get(object.uuid);
|
|
521
|
+
assert.strictEqual(eventFired, 2);
|
|
522
|
+
assert.strictEqual(getter.test, "plop2");
|
|
523
|
+
await this.sleep(10);
|
|
524
|
+
this.log("DEBUG", "Increment attribute");
|
|
525
|
+
await identStore.incrementAttribute(ident1.uuid, "counter", 1);
|
|
526
|
+
let ident = await identStore.get(ident1.uuid);
|
|
527
|
+
// Verify lastUpdate is updated too
|
|
528
|
+
this.assertLastUpdateNotEqual(ident._lastUpdate, ident1._lastUpdate, "lastUpdate after incrementAttribute failed");
|
|
529
|
+
assert.strictEqual(ident.counter, 1);
|
|
530
|
+
await identStore.incrementAttribute(ident1.uuid, "counter", 3);
|
|
531
|
+
ident1 = await identStore.get(ident1.uuid);
|
|
532
|
+
assert.strictEqual(ident1.counter, 4);
|
|
533
|
+
await identStore.incrementAttribute(ident1.uuid, "counter", -6);
|
|
534
|
+
let res = await identStore.exists(ident1.uuid);
|
|
535
|
+
assert.strictEqual(res, true);
|
|
536
|
+
ident1 = await identStore.get(ident1.uuid);
|
|
537
|
+
assert.strictEqual(ident1.counter, -2);
|
|
538
|
+
// Check DELETE
|
|
539
|
+
eventFired = 0;
|
|
540
|
+
await identStore.forceDelete(ident1.uuid);
|
|
541
|
+
assert.strictEqual(eventFired, 2);
|
|
542
|
+
eventFired = 0;
|
|
543
|
+
ident = await identStore.get(ident1.uuid);
|
|
544
|
+
assert.strictEqual(ident, undefined);
|
|
545
|
+
res = await identStore.exists(ident1.uuid);
|
|
546
|
+
assert.strictEqual(res, false);
|
|
585
547
|
}
|
|
586
548
|
assertLastUpdateNotEqual(d1, d2, msg) {
|
|
587
549
|
assert.notStrictEqual(d1, d2, msg);
|
|
588
550
|
}
|
|
589
|
-
exists() {
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
assert.ok(!(yield store.exists((0, uuid_1.v4)())));
|
|
595
|
-
});
|
|
551
|
+
async exists() {
|
|
552
|
+
let store = this.getIdentStore();
|
|
553
|
+
let model = await store.save({});
|
|
554
|
+
assert.ok(await store.exists(model.getUuid()));
|
|
555
|
+
assert.ok(!(await store.exists(uuidv4())));
|
|
596
556
|
}
|
|
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
|
-
});
|
|
557
|
+
async incrementAttribute() {
|
|
558
|
+
let store = this.getIdentStore();
|
|
559
|
+
let model = await store.save({ counter: 0 });
|
|
560
|
+
await store.incrementAttribute(model.getUuid(), "counter", 3);
|
|
561
|
+
await store.incrementAttribute(model.getUuid(), "counter2", 2);
|
|
562
|
+
await model.refresh();
|
|
563
|
+
assert.strictEqual(model.counter, 3);
|
|
564
|
+
assert.strictEqual(model.counter2, 2);
|
|
565
|
+
await assert.rejects(() => store.incrementAttribute(uuidv4(), "counter", 1), StoreNotFoundError);
|
|
608
566
|
}
|
|
609
|
-
removeAttribute() {
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
assert.strictEqual(model.counter2, 12);
|
|
620
|
-
});
|
|
567
|
+
async removeAttribute() {
|
|
568
|
+
let store = this.getIdentStore();
|
|
569
|
+
let model = await store.save({ counter: 0, counter2: 12, counter3: 13 });
|
|
570
|
+
await store.removeAttribute(model.getUuid(), "counter");
|
|
571
|
+
await model.refresh();
|
|
572
|
+
assert.strictEqual(model.counter, undefined);
|
|
573
|
+
await assert.rejects(() => store.removeAttribute(uuidv4(), "counter"), StoreNotFoundError);
|
|
574
|
+
await assert.rejects(() => store.removeAttribute(model.getUuid(), "counter2", 10, "counter3"), UpdateConditionFailError);
|
|
575
|
+
await model.refresh();
|
|
576
|
+
assert.strictEqual(model.counter2, 12);
|
|
621
577
|
}
|
|
622
|
-
setAttribute() {
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
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);
|
|
578
|
+
async setAttribute() {
|
|
579
|
+
let store = this.getIdentStore();
|
|
580
|
+
let model = await store.save({ counter: 0 });
|
|
581
|
+
await store.setAttribute(model.getUuid(), "counter", 3);
|
|
582
|
+
await store.setAttribute(model.getUuid(), "status", "TESTED");
|
|
583
|
+
await model.refresh();
|
|
584
|
+
assert.strictEqual(model.counter, 3);
|
|
585
|
+
assert.strictEqual(model.status, "TESTED");
|
|
586
|
+
await assert.rejects(() => store.setAttribute(uuidv4(), "counter", 4), StoreNotFoundError);
|
|
587
|
+
store.on("Store.PatchUpdate", async () => {
|
|
588
|
+
model._lastUpdate = new Date();
|
|
589
|
+
await store._update(model, model.getUuid());
|
|
590
|
+
await this.sleep(1);
|
|
645
591
|
});
|
|
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)());
|
|
592
|
+
await assert.rejects(() => store.setAttribute(model.getUuid(), "counter", 4), UpdateConditionFailError);
|
|
593
|
+
store.removeAllListeners("Store.PatchUpdate");
|
|
594
|
+
store.on("Store.PatchUpdate", async () => {
|
|
595
|
+
await store._delete(model.getUuid());
|
|
596
|
+
await this.sleep(1);
|
|
659
597
|
});
|
|
598
|
+
await assert.rejects(() => store.setAttribute(model.getUuid(), "counter", 4), err => err instanceof StoreNotFoundError || err instanceof UpdateConditionFailError);
|
|
599
|
+
await assert.rejects(() => store.setAttribute(uuidv4(), "counter", 4), err => err instanceof StoreNotFoundError || err instanceof UpdateConditionFailError);
|
|
660
600
|
}
|
|
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
|
-
});
|
|
601
|
+
async deleteAsync() {
|
|
602
|
+
let store = this.getIdentStore();
|
|
603
|
+
let model = await store.save({ counter: 1 });
|
|
604
|
+
// Delete with condition
|
|
605
|
+
await assert.rejects(() => store.delete(model.getUuid(), 4, "counter"), UpdateConditionFailError);
|
|
606
|
+
await store.delete(model.getUuid(), 1, "counter");
|
|
607
|
+
// Test without condition
|
|
608
|
+
model = await store.save({ counter: 2 });
|
|
609
|
+
await store.delete(model);
|
|
610
|
+
// Deleting a non-existing object should be ignored
|
|
611
|
+
await store.forceDelete(uuidv4());
|
|
675
612
|
}
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
613
|
+
async delete() {
|
|
614
|
+
// UserStore is not supposed to be async
|
|
615
|
+
let store = this.getUserStore();
|
|
616
|
+
let model = await store.save({ counter: 1 });
|
|
617
|
+
// Delete with condition
|
|
618
|
+
await assert.rejects(() => store.delete(model.getUuid(), 4, "counter"), UpdateConditionFailError);
|
|
619
|
+
await store.delete(model.getUuid(), 1, "counter");
|
|
620
|
+
// Test without condition
|
|
621
|
+
model = await store.save({ counter: 2 });
|
|
622
|
+
await store.delete(model);
|
|
623
|
+
// Deleting a non-existing object should be ignored
|
|
624
|
+
await store.forceDelete(uuidv4());
|
|
687
625
|
}
|
|
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/);
|
|
626
|
+
async deleteConcurrent() {
|
|
627
|
+
let store = this.getUserStore();
|
|
628
|
+
let model = await store.save({ counter: 1 });
|
|
629
|
+
store.addListener("Store.Delete", async () => {
|
|
630
|
+
await store.incrementAttribute(model.getUuid(), "counter", 1);
|
|
708
631
|
});
|
|
632
|
+
await assert.rejects(() => store.delete(model.getUuid(), 1, "counter"), UpdateConditionFailError);
|
|
633
|
+
store.removeAllListeners();
|
|
634
|
+
await store.delete(model.getUuid(), 2, "counter");
|
|
709
635
|
}
|
|
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);
|
|
636
|
+
async conditionUpdate() {
|
|
637
|
+
let store = this.getIdentStore();
|
|
638
|
+
let model = await store.save({ counter: 1 });
|
|
639
|
+
assert.ok(await store.conditionalPatch(model.getUuid(), {
|
|
640
|
+
plop: 12,
|
|
641
|
+
counter: 2
|
|
642
|
+
}, "counter", 1));
|
|
643
|
+
assert.strictEqual((await store.get(model.getUuid())).plop, 12);
|
|
644
|
+
assert.ok(!(await store.conditionalPatch(model.getUuid(), {
|
|
645
|
+
plop: 13
|
|
646
|
+
}, "counter", 1)));
|
|
647
|
+
assert.strictEqual((await store.get(model.getUuid())).plop, 12);
|
|
648
|
+
stub(store, "_patch").callsFake(() => {
|
|
649
|
+
throw new Error("Fake Error");
|
|
730
650
|
});
|
|
651
|
+
await assert.rejects(() => store.conditionalPatch(model.getUuid(), {
|
|
652
|
+
plop: 12,
|
|
653
|
+
counter: 2
|
|
654
|
+
}, "counter", 1), /Fake Error/);
|
|
731
655
|
}
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
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);
|
|
656
|
+
async update(delay = 1) {
|
|
657
|
+
let store = this.getIdentStore();
|
|
658
|
+
let model = await store.save({ counter: 1 });
|
|
659
|
+
let model2 = await store.get(model.getUuid());
|
|
660
|
+
store.on("Store.Update", async () => {
|
|
661
|
+
model2._lastUpdate = new Date();
|
|
662
|
+
await store._update(model2, model2.getUuid());
|
|
663
|
+
await this.sleep(delay);
|
|
750
664
|
});
|
|
665
|
+
model.plop = "yop";
|
|
666
|
+
// Delete with condition
|
|
667
|
+
await assert.rejects(() => store.update(model), UpdateConditionFailError);
|
|
668
|
+
store.removeAllListeners("Store.Update");
|
|
669
|
+
store.on("Store.Update", async () => {
|
|
670
|
+
await store._delete(model.getUuid());
|
|
671
|
+
await this.sleep(delay);
|
|
672
|
+
});
|
|
673
|
+
await assert.rejects(() => store.update(model), err => err instanceof StoreNotFoundError || err instanceof UpdateConditionFailError);
|
|
674
|
+
await assert.rejects(() => store.update({ uuid: uuidv4(), test: true }), err => err instanceof StoreNotFoundError || err instanceof UpdateConditionFailError);
|
|
675
|
+
}
|
|
676
|
+
async upsertItem() {
|
|
677
|
+
let store = this.getIdentStore();
|
|
678
|
+
this.log("DEBUG", "Save empty logs array");
|
|
679
|
+
let model = await store.save({ logs: [] });
|
|
680
|
+
let ps = [];
|
|
681
|
+
this.log("DEBUG", "Upsert 10 lines");
|
|
682
|
+
for (let i = 0; i < 10; i++) {
|
|
683
|
+
ps.push(store.upsertItemToCollection(model.getUuid(), "logs", `line${i}`));
|
|
684
|
+
}
|
|
685
|
+
await Promise.all(ps);
|
|
686
|
+
await model.refresh();
|
|
687
|
+
assert.strictEqual(model.logs.length, 10);
|
|
688
|
+
// Depending on the implementation it can be swallowed by the backend
|
|
689
|
+
this.log("DEBUG", "Upsert on unknown doc");
|
|
690
|
+
await assert.rejects(() => store.upsertItemToCollection(uuidv4(), "logs", `line`), err => err instanceof StoreNotFoundError || err instanceof UpdateConditionFailError);
|
|
691
|
+
this.log("DEBUG", "Delete on unknown doc");
|
|
692
|
+
await assert.rejects(() => store.deleteItemFromCollection(uuidv4(), "logs", 0, undefined, undefined), err => err instanceof StoreNotFoundError || err instanceof UpdateConditionFailError);
|
|
693
|
+
}
|
|
694
|
+
async put() {
|
|
695
|
+
const store = this.getIdentStore();
|
|
696
|
+
const uuid = store.getWebda().getUuid();
|
|
697
|
+
if (await store.exists(uuid)) {
|
|
698
|
+
await store.delete(uuid);
|
|
699
|
+
}
|
|
700
|
+
await store.put(uuid, { test: true });
|
|
701
|
+
// Verify put acts like a upsert
|
|
702
|
+
await store.put(uuid, { test: false });
|
|
751
703
|
}
|
|
752
704
|
}
|
|
753
705
|
__decorate([
|
|
754
|
-
|
|
706
|
+
test
|
|
755
707
|
], StoreTest.prototype, "query", null);
|
|
756
708
|
__decorate([
|
|
757
|
-
|
|
709
|
+
test
|
|
758
710
|
], StoreTest.prototype, "queryOrder", null);
|
|
759
711
|
__decorate([
|
|
760
|
-
|
|
712
|
+
test
|
|
761
713
|
], StoreTest.prototype, "mapper", null);
|
|
762
714
|
__decorate([
|
|
763
|
-
|
|
715
|
+
test
|
|
764
716
|
], StoreTest.prototype, "collection", null);
|
|
765
717
|
__decorate([
|
|
766
|
-
|
|
718
|
+
test
|
|
767
719
|
], StoreTest.prototype, "getAll", null);
|
|
768
720
|
__decorate([
|
|
769
|
-
|
|
721
|
+
test
|
|
770
722
|
], StoreTest.prototype, "crud", null);
|
|
771
723
|
__decorate([
|
|
772
|
-
|
|
724
|
+
test
|
|
773
725
|
], StoreTest.prototype, "exists", null);
|
|
774
726
|
__decorate([
|
|
775
|
-
|
|
727
|
+
test
|
|
776
728
|
], StoreTest.prototype, "incrementAttribute", null);
|
|
777
729
|
__decorate([
|
|
778
|
-
|
|
730
|
+
test
|
|
779
731
|
], StoreTest.prototype, "removeAttribute", null);
|
|
780
732
|
__decorate([
|
|
781
|
-
|
|
733
|
+
test
|
|
782
734
|
], StoreTest.prototype, "setAttribute", null);
|
|
783
735
|
__decorate([
|
|
784
|
-
|
|
736
|
+
test
|
|
785
737
|
], StoreTest.prototype, "deleteAsync", null);
|
|
786
738
|
__decorate([
|
|
787
|
-
|
|
739
|
+
test
|
|
788
740
|
], StoreTest.prototype, "delete", null);
|
|
789
741
|
__decorate([
|
|
790
|
-
|
|
742
|
+
test
|
|
791
743
|
], StoreTest.prototype, "conditionUpdate", null);
|
|
792
744
|
__decorate([
|
|
793
|
-
|
|
745
|
+
test
|
|
794
746
|
], StoreTest.prototype, "update", null);
|
|
795
747
|
__decorate([
|
|
796
|
-
|
|
748
|
+
test
|
|
797
749
|
], StoreTest.prototype, "upsertItem", null);
|
|
798
|
-
|
|
750
|
+
__decorate([
|
|
751
|
+
test
|
|
752
|
+
], StoreTest.prototype, "put", null);
|
|
753
|
+
export { StoreTest };
|
|
799
754
|
//# sourceMappingURL=store.spec.js.map
|