@deenruv/testing 1.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/LICENSE +23 -0
- package/README.md +5 -0
- package/lib/config/test-config.d.ts +26 -0
- package/lib/config/test-config.js +70 -0
- package/lib/config/test-config.js.map +1 -0
- package/lib/config/testing-asset-preview-strategy.d.ts +13 -0
- package/lib/config/testing-asset-preview-strategy.js +21 -0
- package/lib/config/testing-asset-preview-strategy.js.map +1 -0
- package/lib/config/testing-asset-storage-strategy.d.ts +18 -0
- package/lib/config/testing-asset-storage-strategy.js +47 -0
- package/lib/config/testing-asset-storage-strategy.js.map +1 -0
- package/lib/config/testing-entity-id-strategy.d.ts +11 -0
- package/lib/config/testing-entity-id-strategy.js +22 -0
- package/lib/config/testing-entity-id-strategy.js.map +1 -0
- package/lib/create-test-environment.d.ts +57 -0
- package/lib/create-test-environment.js +47 -0
- package/lib/create-test-environment.js.map +1 -0
- package/lib/data-population/clear-all-tables.d.ts +5 -0
- package/lib/data-population/clear-all-tables.js +32 -0
- package/lib/data-population/clear-all-tables.js.map +1 -0
- package/lib/data-population/mock-data.service.d.ts +21 -0
- package/lib/data-population/mock-data.service.js +108 -0
- package/lib/data-population/mock-data.service.js.map +1 -0
- package/lib/data-population/populate-customers.d.ts +5 -0
- package/lib/data-population/populate-customers.js +30 -0
- package/lib/data-population/populate-customers.js.map +1 -0
- package/lib/data-population/populate-for-testing.d.ts +7 -0
- package/lib/data-population/populate-for-testing.js +42 -0
- package/lib/data-population/populate-for-testing.js.map +1 -0
- package/lib/error-result-guard.d.ts +65 -0
- package/lib/error-result-guard.js +85 -0
- package/lib/error-result-guard.js.map +1 -0
- package/lib/index.d.ts +14 -0
- package/lib/index.js +31 -0
- package/lib/index.js.map +1 -0
- package/lib/initializers/initializers.d.ts +14 -0
- package/lib/initializers/initializers.js +24 -0
- package/lib/initializers/initializers.js.map +1 -0
- package/lib/initializers/mysql-initializer.d.ts +10 -0
- package/lib/initializers/mysql-initializer.js +43 -0
- package/lib/initializers/mysql-initializer.js.map +1 -0
- package/lib/initializers/postgres-initializer.d.ts +10 -0
- package/lib/initializers/postgres-initializer.js +41 -0
- package/lib/initializers/postgres-initializer.js.map +1 -0
- package/lib/initializers/sqljs-initializer.d.ts +19 -0
- package/lib/initializers/sqljs-initializer.js +55 -0
- package/lib/initializers/sqljs-initializer.js.map +1 -0
- package/lib/initializers/test-db-initializer.d.ts +42 -0
- package/lib/initializers/test-db-initializer.js +3 -0
- package/lib/initializers/test-db-initializer.js.map +1 -0
- package/lib/simple-graphql-client.d.ts +86 -0
- package/lib/simple-graphql-client.js +229 -0
- package/lib/simple-graphql-client.js.map +1 -0
- package/lib/test-server.d.ts +45 -0
- package/lib/test-server.js +123 -0
- package/lib/test-server.js.map +1 -0
- package/lib/testing-logger.d.ts +67 -0
- package/lib/testing-logger.js +82 -0
- package/lib/testing-logger.js.map +1 -0
- package/lib/types.d.ts +42 -0
- package/lib/types.js +3 -0
- package/lib/types.js.map +1 -0
- package/lib/utils/create-upload-post-data.d.ts +23 -0
- package/lib/utils/create-upload-post-data.js +55 -0
- package/lib/utils/create-upload-post-data.js.map +1 -0
- package/lib/utils/get-superadmin-context.d.ts +10 -0
- package/lib/utils/get-superadmin-context.js +40 -0
- package/lib/utils/get-superadmin-context.js.map +1 -0
- package/package.json +64 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# License 1
|
|
2
|
+
|
|
3
|
+
The MIT License
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2025-present Aexol
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
8
|
+
|
|
9
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
10
|
+
|
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
12
|
+
|
|
13
|
+
# License 2
|
|
14
|
+
|
|
15
|
+
The MIT License
|
|
16
|
+
|
|
17
|
+
Copyright (c) 2018-2025 Michael Bromley
|
|
18
|
+
|
|
19
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
20
|
+
|
|
21
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
22
|
+
|
|
23
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { DeenruvConfig } from "@deenruv/core";
|
|
2
|
+
export declare const E2E_DEFAULT_CHANNEL_TOKEN = "e2e-default-channel";
|
|
3
|
+
/**
|
|
4
|
+
* @description
|
|
5
|
+
* A {@link DeenruvConfig} object used for e2e tests. This configuration uses sqljs as the database
|
|
6
|
+
* and configures some special settings which are optimized for e2e tests:
|
|
7
|
+
*
|
|
8
|
+
* * `entityIdStrategy: new TestingEntityIdStrategy()` This ID strategy uses auto-increment IDs but encodes all IDs
|
|
9
|
+
* to be prepended with the string `'T_'`, so ID `1` becomes `'T_1'`.
|
|
10
|
+
* * `logger: new NoopLogger()` Do no output logs by default
|
|
11
|
+
* * `assetStorageStrategy: new TestingAssetStorageStrategy()` This strategy does not actually persist any binary data to disk.
|
|
12
|
+
* * `assetPreviewStrategy: new TestingAssetPreviewStrategy()` This strategy is a no-op.
|
|
13
|
+
*
|
|
14
|
+
* ## Logging
|
|
15
|
+
* By default, the testConfig does not output any log messages. This is most desirable to keep a clean CI output.
|
|
16
|
+
* However, for debugging purposes, it can make it hard to figure out why tests fail.
|
|
17
|
+
*
|
|
18
|
+
* You can enable default logging behaviour with the environment variable `LOG`:
|
|
19
|
+
*
|
|
20
|
+
* ```
|
|
21
|
+
* LOG=true yarn e2e
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @docsCategory testing
|
|
25
|
+
*/
|
|
26
|
+
export declare const testConfig: Required<DeenruvConfig>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.testConfig = exports.E2E_DEFAULT_CHANNEL_TOKEN = void 0;
|
|
4
|
+
const shared_constants_1 = require("@deenruv/common/lib/shared-constants");
|
|
5
|
+
const core_1 = require("@deenruv/core");
|
|
6
|
+
const testing_asset_preview_strategy_1 = require("./testing-asset-preview-strategy");
|
|
7
|
+
const testing_asset_storage_strategy_1 = require("./testing-asset-storage-strategy");
|
|
8
|
+
const testing_entity_id_strategy_1 = require("./testing-entity-id-strategy");
|
|
9
|
+
exports.E2E_DEFAULT_CHANNEL_TOKEN = "e2e-default-channel";
|
|
10
|
+
const logger = process.env.LOG ? new core_1.DefaultLogger() : new core_1.NoopLogger();
|
|
11
|
+
/**
|
|
12
|
+
* @description
|
|
13
|
+
* A {@link DeenruvConfig} object used for e2e tests. This configuration uses sqljs as the database
|
|
14
|
+
* and configures some special settings which are optimized for e2e tests:
|
|
15
|
+
*
|
|
16
|
+
* * `entityIdStrategy: new TestingEntityIdStrategy()` This ID strategy uses auto-increment IDs but encodes all IDs
|
|
17
|
+
* to be prepended with the string `'T_'`, so ID `1` becomes `'T_1'`.
|
|
18
|
+
* * `logger: new NoopLogger()` Do no output logs by default
|
|
19
|
+
* * `assetStorageStrategy: new TestingAssetStorageStrategy()` This strategy does not actually persist any binary data to disk.
|
|
20
|
+
* * `assetPreviewStrategy: new TestingAssetPreviewStrategy()` This strategy is a no-op.
|
|
21
|
+
*
|
|
22
|
+
* ## Logging
|
|
23
|
+
* By default, the testConfig does not output any log messages. This is most desirable to keep a clean CI output.
|
|
24
|
+
* However, for debugging purposes, it can make it hard to figure out why tests fail.
|
|
25
|
+
*
|
|
26
|
+
* You can enable default logging behaviour with the environment variable `LOG`:
|
|
27
|
+
*
|
|
28
|
+
* ```
|
|
29
|
+
* LOG=true yarn e2e
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @docsCategory testing
|
|
33
|
+
*/
|
|
34
|
+
exports.testConfig = (0, core_1.mergeConfig)(core_1.defaultConfig, {
|
|
35
|
+
apiOptions: {
|
|
36
|
+
port: 3050,
|
|
37
|
+
adminApiPath: shared_constants_1.ADMIN_API_PATH,
|
|
38
|
+
shopApiPath: shared_constants_1.SHOP_API_PATH,
|
|
39
|
+
cors: true,
|
|
40
|
+
},
|
|
41
|
+
defaultChannelToken: exports.E2E_DEFAULT_CHANNEL_TOKEN,
|
|
42
|
+
authOptions: {
|
|
43
|
+
tokenMethod: "bearer",
|
|
44
|
+
requireVerification: true,
|
|
45
|
+
cookieOptions: {
|
|
46
|
+
secret: "some-secret",
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
dbConnectionOptions: {
|
|
50
|
+
type: "sqljs",
|
|
51
|
+
database: new Uint8Array([]),
|
|
52
|
+
location: "",
|
|
53
|
+
autoSave: false,
|
|
54
|
+
logging: false,
|
|
55
|
+
},
|
|
56
|
+
promotionOptions: {},
|
|
57
|
+
customFields: {},
|
|
58
|
+
entityOptions: { entityIdStrategy: new testing_entity_id_strategy_1.TestingEntityIdStrategy() },
|
|
59
|
+
paymentOptions: {
|
|
60
|
+
paymentMethodHandlers: [],
|
|
61
|
+
},
|
|
62
|
+
logger,
|
|
63
|
+
importExportOptions: {},
|
|
64
|
+
assetOptions: {
|
|
65
|
+
assetNamingStrategy: new core_1.DefaultAssetNamingStrategy(),
|
|
66
|
+
assetStorageStrategy: new testing_asset_storage_strategy_1.TestingAssetStorageStrategy(),
|
|
67
|
+
assetPreviewStrategy: new testing_asset_preview_strategy_1.TestingAssetPreviewStrategy(),
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
//# sourceMappingURL=test-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-config.js","sourceRoot":"","sources":["../../src/config/test-config.ts"],"names":[],"mappings":";;;AAAA,2EAG8C;AAC9C,wCAOuB;AAEvB,qFAA+E;AAC/E,qFAA+E;AAC/E,6EAAuE;AAE1D,QAAA,yBAAyB,GAAG,qBAAqB,CAAC;AAE/D,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,oBAAa,EAAE,CAAC,CAAC,CAAC,IAAI,iBAAU,EAAE,CAAC;AAExE;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACU,QAAA,UAAU,GAA4B,IAAA,kBAAW,EAAC,oBAAa,EAAE;IAC5E,UAAU,EAAE;QACV,IAAI,EAAE,IAAI;QACV,YAAY,EAAE,iCAAc;QAC5B,WAAW,EAAE,gCAAa;QAC1B,IAAI,EAAE,IAAI;KACX;IACD,mBAAmB,EAAE,iCAAyB;IAC9C,WAAW,EAAE;QACX,WAAW,EAAE,QAAQ;QACrB,mBAAmB,EAAE,IAAI;QACzB,aAAa,EAAE;YACb,MAAM,EAAE,aAAa;SACtB;KACF;IACD,mBAAmB,EAAE;QACnB,IAAI,EAAE,OAAO;QACb,QAAQ,EAAE,IAAI,UAAU,CAAC,EAAE,CAAC;QAC5B,QAAQ,EAAE,EAAE;QACZ,QAAQ,EAAE,KAAK;QACf,OAAO,EAAE,KAAK;KACf;IACD,gBAAgB,EAAE,EAAE;IACpB,YAAY,EAAE,EAAE;IAChB,aAAa,EAAE,EAAE,gBAAgB,EAAE,IAAI,oDAAuB,EAAE,EAAE;IAClE,cAAc,EAAE;QACd,qBAAqB,EAAE,EAAE;KAC1B;IACD,MAAM;IACN,mBAAmB,EAAE,EAAE;IACvB,YAAY,EAAE;QACZ,mBAAmB,EAAE,IAAI,iCAA0B,EAAE;QACrD,oBAAoB,EAAE,IAAI,4DAA2B,EAAE;QACvD,oBAAoB,EAAE,IAAI,4DAA2B,EAAE;KACxD;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { AssetPreviewStrategy, RequestContext } from "@deenruv/core";
|
|
4
|
+
/**
|
|
5
|
+
* Returns a buffer of a small 48x48 placeholder image
|
|
6
|
+
*/
|
|
7
|
+
export declare function getTestImageBuffer(): Buffer;
|
|
8
|
+
/**
|
|
9
|
+
* A mock preview strategy which returns a new Buffer without doing any actual work.
|
|
10
|
+
*/
|
|
11
|
+
export declare class TestingAssetPreviewStrategy implements AssetPreviewStrategy {
|
|
12
|
+
generatePreviewImage(ctx: RequestContext, mimeType: string, data: Buffer): Promise<Buffer>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TestingAssetPreviewStrategy = exports.getTestImageBuffer = void 0;
|
|
4
|
+
const TEST_IMAGE_BASE_64 = "iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyppVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0NjcyOSwgMjAxMi8wNS8wMy0xMzo0MDowMyAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIEVsZW1lbnRzIDEyLjAgV2luZG93cyIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDowQzYyREUzNEM1QTcxMUU5OEJCNUU3Qzg2NjgyOTVFOSIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDowQzYyREUzNUM1QTcxMUU5OEJCNUU3Qzg2NjgyOTVFOSI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOjBDNjJERTMyQzVBNzExRTk4QkI1RTdDODY2ODI5NUU5IiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOjBDNjJERTMzQzVBNzExRTk4QkI1RTdDODY2ODI5NUU5Ii8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+1hstBAAAAvxJREFUeNrsmslu4zAQRGlZ8u7DXPL/HzZfMAcH8G7Ly7iEeUKboR0pkWIIQwKMrI2s6i52N4X0FovFb+fcL9fN9p7e/rzd+ryjBLLk9id33W154jreIoFIIBKIBCKB/5tA+qqJe73e3fn1en0NASYWoBAoe41nL5eLO5/PZU+SxI1Gow/vt0pAk202G3c8HgsAOtex3+8XnWsCLZCn06kATtd1SzDLsqLX9UT6VfCaSKB0tIDsM4DzrxcTp2kBWGPICBoj9HxjBACNRfM8LyaVpWez2R0RKxGsDCgrI43BfZFQw4ONEtAE+/3eHQ6HEiBNk8maobVhuyVliTKWCCBHjSejNOoBWUvuFmC5nmtYy7pdvwXk2eLmCCEIIic/AHybAIAULcbjsdvtdqXFACoA2+22OOq54XD4VNN6B2PotwyiMQkCVdZCUpcALhdIe11NEhMATSyCVmqh2O9LjTVTZw1UJsCgVr++PCCDhOw9/SZqPWq67xulEQlhFXWshEYtaEkGcvqNDAC/Wq3cZDIpn/NbyCiNrgENzGLDyr5WtT78TKx3lPR0LpkNBoOHUqrrgaROHgCszQF2Mr9sIP6v1+uCNJ7Q+2paJ/Y5O2bVZFYrE0tChFM/VFIucJ1IIsvrOuR0JIKp20iFVFsjQMJisQFKSQ5rhiTnaxoZ2gxNPgjJq7H9gB9ZZC1NKl2HFiSh9llpAhGerVuRVvaADY3olj6fz+9KA8DbyvNRQsObtkZqrRoVWNYB5TSkCLPURv6Cxtq2yLMEkRpld1VPfJkAiQ0wLGDrGbtHILpI4/a+b3mVFq3kAbsONKmsPJ1O7ypMSmSb7Ci9/Z0bxDjXuzpXomt1Q4NkiOc64na7J7C5w+YLu/mhbiq/lf8r7FolgNVk2eVy+QGsPGO3ltbKoVLaeg/5tLIjs5GIraCO6Nvug0MbeR8UpbRv9R/ZE0v7NhN/BvazLxov+S5U19Xxy1wkEAlEApFAJBAJPCCQdRh/plLij+vuP3y8/xVgAAkZCFP/heS9AAAAAElFTkSuQmCC";
|
|
5
|
+
/**
|
|
6
|
+
* Returns a buffer of a small 48x48 placeholder image
|
|
7
|
+
*/
|
|
8
|
+
function getTestImageBuffer() {
|
|
9
|
+
return Buffer.from(TEST_IMAGE_BASE_64, "base64");
|
|
10
|
+
}
|
|
11
|
+
exports.getTestImageBuffer = getTestImageBuffer;
|
|
12
|
+
/**
|
|
13
|
+
* A mock preview strategy which returns a new Buffer without doing any actual work.
|
|
14
|
+
*/
|
|
15
|
+
class TestingAssetPreviewStrategy {
|
|
16
|
+
generatePreviewImage(ctx, mimeType, data) {
|
|
17
|
+
return Promise.resolve(getTestImageBuffer());
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.TestingAssetPreviewStrategy = TestingAssetPreviewStrategy;
|
|
21
|
+
//# sourceMappingURL=testing-asset-preview-strategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing-asset-preview-strategy.js","sourceRoot":"","sources":["../../src/config/testing-asset-preview-strategy.ts"],"names":[],"mappings":";;;AAEA,MAAM,kBAAkB,GACtB,ksEAAksE,CAAC;AAErsE;;GAEG;AACH,SAAgB,kBAAkB;IAChC,OAAO,MAAM,CAAC,IAAI,CAAC,kBAAkB,EAAE,QAAQ,CAAC,CAAC;AACnD,CAAC;AAFD,gDAEC;AAED;;GAEG;AACH,MAAa,2BAA2B;IACtC,oBAAoB,CAClB,GAAmB,EACnB,QAAgB,EAChB,IAAY;QAEZ,OAAO,OAAO,CAAC,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAAC;IAC/C,CAAC;CACF;AARD,kEAQC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
4
|
+
import { AssetStorageStrategy } from "@deenruv/core";
|
|
5
|
+
import { Request } from "express";
|
|
6
|
+
import { Stream } from "stream";
|
|
7
|
+
/**
|
|
8
|
+
* A mock storage strategy which does not actually persist the assets anywhere.
|
|
9
|
+
*/
|
|
10
|
+
export declare class TestingAssetStorageStrategy implements AssetStorageStrategy {
|
|
11
|
+
readFileToBuffer(identifier: string): Promise<Buffer>;
|
|
12
|
+
readFileToStream(identifier: string): Promise<Stream>;
|
|
13
|
+
toAbsoluteUrl(reqest: Request, identifier: string): string;
|
|
14
|
+
writeFileFromBuffer(fileName: string, data: Buffer): Promise<string>;
|
|
15
|
+
writeFileFromStream(fileName: string, data: Stream): Promise<string>;
|
|
16
|
+
fileExists(fileName: string): Promise<boolean>;
|
|
17
|
+
deleteFile(identifier: string): Promise<void>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TestingAssetStorageStrategy = void 0;
|
|
4
|
+
const stream_1 = require("stream");
|
|
5
|
+
const testing_asset_preview_strategy_1 = require("./testing-asset-preview-strategy");
|
|
6
|
+
/**
|
|
7
|
+
* A mock storage strategy which does not actually persist the assets anywhere.
|
|
8
|
+
*/
|
|
9
|
+
class TestingAssetStorageStrategy {
|
|
10
|
+
readFileToBuffer(identifier) {
|
|
11
|
+
return Promise.resolve((0, testing_asset_preview_strategy_1.getTestImageBuffer)());
|
|
12
|
+
}
|
|
13
|
+
readFileToStream(identifier) {
|
|
14
|
+
const s = new stream_1.Readable();
|
|
15
|
+
s.push(identifier);
|
|
16
|
+
s.push(null);
|
|
17
|
+
return Promise.resolve(s);
|
|
18
|
+
}
|
|
19
|
+
toAbsoluteUrl(reqest, identifier) {
|
|
20
|
+
const prefix = "test-url/";
|
|
21
|
+
return identifier.startsWith(prefix)
|
|
22
|
+
? identifier
|
|
23
|
+
: `${prefix}${identifier}`;
|
|
24
|
+
}
|
|
25
|
+
writeFileFromBuffer(fileName, data) {
|
|
26
|
+
return Promise.resolve(`test-assets/${fileName}`);
|
|
27
|
+
}
|
|
28
|
+
writeFileFromStream(fileName, data) {
|
|
29
|
+
const writable = new stream_1.Writable();
|
|
30
|
+
writable._write = (chunk, encoding, done) => {
|
|
31
|
+
done();
|
|
32
|
+
};
|
|
33
|
+
return new Promise((resolve, reject) => {
|
|
34
|
+
data.pipe(writable);
|
|
35
|
+
writable.on("finish", () => resolve(`test-assets/${fileName}`));
|
|
36
|
+
writable.on("error", reject);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
fileExists(fileName) {
|
|
40
|
+
return Promise.resolve(false);
|
|
41
|
+
}
|
|
42
|
+
deleteFile(identifier) {
|
|
43
|
+
return Promise.resolve();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.TestingAssetStorageStrategy = TestingAssetStorageStrategy;
|
|
47
|
+
//# sourceMappingURL=testing-asset-storage-strategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing-asset-storage-strategy.js","sourceRoot":"","sources":["../../src/config/testing-asset-storage-strategy.ts"],"names":[],"mappings":";;;AAEA,mCAAoD;AAEpD,qFAAsE;AAEtE;;GAEG;AACH,MAAa,2BAA2B;IACtC,gBAAgB,CAAC,UAAkB;QACjC,OAAO,OAAO,CAAC,OAAO,CAAC,IAAA,mDAAkB,GAAE,CAAC,CAAC;IAC/C,CAAC;IAED,gBAAgB,CAAC,UAAkB;QACjC,MAAM,CAAC,GAAG,IAAI,iBAAQ,EAAE,CAAC;QACzB,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACnB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACb,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAC5B,CAAC;IAED,aAAa,CAAC,MAAe,EAAE,UAAkB;QAC/C,MAAM,MAAM,GAAG,WAAW,CAAC;QAC3B,OAAO,UAAU,CAAC,UAAU,CAAC,MAAM,CAAC;YAClC,CAAC,CAAC,UAAU;YACZ,CAAC,CAAC,GAAG,MAAM,GAAG,UAAU,EAAE,CAAC;IAC/B,CAAC;IAED,mBAAmB,CAAC,QAAgB,EAAE,IAAY;QAChD,OAAO,OAAO,CAAC,OAAO,CAAC,eAAe,QAAQ,EAAE,CAAC,CAAC;IACpD,CAAC;IAED,mBAAmB,CAAC,QAAgB,EAAE,IAAY;QAChD,MAAM,QAAQ,GAAG,IAAI,iBAAQ,EAAE,CAAC;QAChC,QAAQ,CAAC,MAAM,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE;YAC1C,IAAI,EAAE,CAAC;QACT,CAAC,CAAC;QACF,OAAO,IAAI,OAAO,CAAS,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC7C,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACpB,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,eAAe,QAAQ,EAAE,CAAC,CAAC,CAAC;YAChE,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC/B,CAAC,CAAC,CAAC;IACL,CAAC;IAED,UAAU,CAAC,QAAgB;QACzB,OAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC;IAED,UAAU,CAAC,UAAkB;QAC3B,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;CACF;AA1CD,kEA0CC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { EntityIdStrategy } from "@deenruv/core";
|
|
2
|
+
/**
|
|
3
|
+
* A testing entity id strategy which prefixes all IDs with a constant string. This is used in the
|
|
4
|
+
* e2e tests to ensure that all ID properties in arguments are being
|
|
5
|
+
* correctly decoded.
|
|
6
|
+
*/
|
|
7
|
+
export declare class TestingEntityIdStrategy implements EntityIdStrategy<"increment"> {
|
|
8
|
+
readonly primaryKeyType = "increment";
|
|
9
|
+
decodeId(id: string): number;
|
|
10
|
+
encodeId(primaryKey: number): string;
|
|
11
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TestingEntityIdStrategy = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* A testing entity id strategy which prefixes all IDs with a constant string. This is used in the
|
|
6
|
+
* e2e tests to ensure that all ID properties in arguments are being
|
|
7
|
+
* correctly decoded.
|
|
8
|
+
*/
|
|
9
|
+
class TestingEntityIdStrategy {
|
|
10
|
+
constructor() {
|
|
11
|
+
this.primaryKeyType = "increment";
|
|
12
|
+
}
|
|
13
|
+
decodeId(id) {
|
|
14
|
+
const asNumber = parseInt(id.replace("T_", ""), 10);
|
|
15
|
+
return Number.isNaN(asNumber) ? -1 : asNumber;
|
|
16
|
+
}
|
|
17
|
+
encodeId(primaryKey) {
|
|
18
|
+
return "T_" + primaryKey.toString();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.TestingEntityIdStrategy = TestingEntityIdStrategy;
|
|
22
|
+
//# sourceMappingURL=testing-entity-id-strategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing-entity-id-strategy.js","sourceRoot":"","sources":["../../src/config/testing-entity-id-strategy.ts"],"names":[],"mappings":";;;AAEA;;;;GAIG;AACH,MAAa,uBAAuB;IAApC;QACW,mBAAc,GAAG,WAAW,CAAC;IAQxC,CAAC;IAPC,QAAQ,CAAC,EAAU;QACjB,MAAM,QAAQ,GAAG,QAAQ,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;QACpD,OAAO,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;IAChD,CAAC;IACD,QAAQ,CAAC,UAAkB;QACzB,OAAO,IAAI,GAAG,UAAU,CAAC,QAAQ,EAAE,CAAC;IACtC,CAAC;CACF;AATD,0DASC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { DeenruvConfig } from "@deenruv/core";
|
|
2
|
+
import { SimpleGraphQLClient } from "./simple-graphql-client";
|
|
3
|
+
import { TestServer } from "./test-server";
|
|
4
|
+
/**
|
|
5
|
+
* @description
|
|
6
|
+
* The return value of {@link createTestEnvironment}, containing the test server
|
|
7
|
+
* and clients for the Shop API and Admin API.
|
|
8
|
+
*
|
|
9
|
+
* @docsCategory testing
|
|
10
|
+
*/
|
|
11
|
+
export interface TestEnvironment {
|
|
12
|
+
/**
|
|
13
|
+
* @description
|
|
14
|
+
* A Deenruv server instance against which GraphQL requests can be made.
|
|
15
|
+
*/
|
|
16
|
+
server: TestServer;
|
|
17
|
+
/**
|
|
18
|
+
* @description
|
|
19
|
+
* A GraphQL client configured for the Admin API.
|
|
20
|
+
*/
|
|
21
|
+
adminClient: SimpleGraphQLClient;
|
|
22
|
+
/**
|
|
23
|
+
* @description
|
|
24
|
+
* A GraphQL client configured for the Shop API.
|
|
25
|
+
*/
|
|
26
|
+
shopClient: SimpleGraphQLClient;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* @description
|
|
30
|
+
* Configures a {@link TestServer} and a {@link SimpleGraphQLClient} for each of the GraphQL APIs
|
|
31
|
+
* for use in end-to-end tests. Returns a {@link TestEnvironment} object.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* import { createTestEnvironment, testConfig } from '\@deenruv/testing';
|
|
36
|
+
*
|
|
37
|
+
* describe('some feature to test', () => {
|
|
38
|
+
*
|
|
39
|
+
* const { server, adminClient, shopClient } = createTestEnvironment(testConfig);
|
|
40
|
+
*
|
|
41
|
+
* beforeAll(async () => {
|
|
42
|
+
* await server.init({
|
|
43
|
+
* // ... server options
|
|
44
|
+
* });
|
|
45
|
+
* await adminClient.asSuperAdmin();
|
|
46
|
+
* });
|
|
47
|
+
*
|
|
48
|
+
* afterAll(async () => {
|
|
49
|
+
* await server.destroy();
|
|
50
|
+
* });
|
|
51
|
+
*
|
|
52
|
+
* // ... end-to-end tests here
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
* @docsCategory testing
|
|
56
|
+
*/
|
|
57
|
+
export declare function createTestEnvironment(config: Required<DeenruvConfig>): TestEnvironment;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createTestEnvironment = void 0;
|
|
4
|
+
const simple_graphql_client_1 = require("./simple-graphql-client");
|
|
5
|
+
const test_server_1 = require("./test-server");
|
|
6
|
+
/**
|
|
7
|
+
* @description
|
|
8
|
+
* Configures a {@link TestServer} and a {@link SimpleGraphQLClient} for each of the GraphQL APIs
|
|
9
|
+
* for use in end-to-end tests. Returns a {@link TestEnvironment} object.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { createTestEnvironment, testConfig } from '\@deenruv/testing';
|
|
14
|
+
*
|
|
15
|
+
* describe('some feature to test', () => {
|
|
16
|
+
*
|
|
17
|
+
* const { server, adminClient, shopClient } = createTestEnvironment(testConfig);
|
|
18
|
+
*
|
|
19
|
+
* beforeAll(async () => {
|
|
20
|
+
* await server.init({
|
|
21
|
+
* // ... server options
|
|
22
|
+
* });
|
|
23
|
+
* await adminClient.asSuperAdmin();
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* afterAll(async () => {
|
|
27
|
+
* await server.destroy();
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* // ... end-to-end tests here
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
33
|
+
* @docsCategory testing
|
|
34
|
+
*/
|
|
35
|
+
function createTestEnvironment(config) {
|
|
36
|
+
const server = new test_server_1.TestServer(config);
|
|
37
|
+
const { port, adminApiPath, shopApiPath } = config.apiOptions;
|
|
38
|
+
const adminClient = new simple_graphql_client_1.SimpleGraphQLClient(config, `http://localhost:${port}/${adminApiPath}`);
|
|
39
|
+
const shopClient = new simple_graphql_client_1.SimpleGraphQLClient(config, `http://localhost:${port}/${shopApiPath}`);
|
|
40
|
+
return {
|
|
41
|
+
server,
|
|
42
|
+
adminClient,
|
|
43
|
+
shopClient,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
exports.createTestEnvironment = createTestEnvironment;
|
|
47
|
+
//# sourceMappingURL=create-test-environment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-test-environment.js","sourceRoot":"","sources":["../src/create-test-environment.ts"],"names":[],"mappings":";;;AAEA,mEAA8D;AAC9D,+CAA2C;AA2B3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,SAAgB,qBAAqB,CACnC,MAA+B;IAE/B,MAAM,MAAM,GAAG,IAAI,wBAAU,CAAC,MAAM,CAAC,CAAC;IACtC,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,WAAW,EAAE,GAAG,MAAM,CAAC,UAAU,CAAC;IAE9D,MAAM,WAAW,GAAG,IAAI,2CAAmB,CACzC,MAAM,EACN,oBAAoB,IAAI,IAAI,YAAa,EAAE,CAC5C,CAAC;IAEF,MAAM,UAAU,GAAG,IAAI,2CAAmB,CACxC,MAAM,EACN,oBAAoB,IAAI,IAAI,WAAY,EAAE,CAC3C,CAAC;IACF,OAAO;QACL,MAAM;QACN,WAAW;QACX,UAAU;KACX,CAAC;AACJ,CAAC;AApBD,sDAoBC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.clearAllTables = void 0;
|
|
4
|
+
const bootstrap_1 = require("@deenruv/core/dist/bootstrap");
|
|
5
|
+
const typeorm_1 = require("typeorm");
|
|
6
|
+
/**
|
|
7
|
+
* Clears all tables in the database specified by the connectionOptions
|
|
8
|
+
*/
|
|
9
|
+
async function clearAllTables(config, logging = true) {
|
|
10
|
+
var _a, _b;
|
|
11
|
+
if (logging) {
|
|
12
|
+
console.log("Clearing all tables...");
|
|
13
|
+
}
|
|
14
|
+
config = await (0, bootstrap_1.preBootstrapConfig)(config);
|
|
15
|
+
const entityIdStrategy = (_a = config.entityIdStrategy) !== null && _a !== void 0 ? _a : (_b = config.entityOptions) === null || _b === void 0 ? void 0 : _b.entityIdStrategy;
|
|
16
|
+
const connection = await (0, typeorm_1.createConnection)(Object.assign({}, config.dbConnectionOptions));
|
|
17
|
+
try {
|
|
18
|
+
await connection.synchronize(true);
|
|
19
|
+
}
|
|
20
|
+
catch (err) {
|
|
21
|
+
console.error("Error occurred when attempting to clear tables!");
|
|
22
|
+
console.log(err);
|
|
23
|
+
}
|
|
24
|
+
finally {
|
|
25
|
+
await connection.close();
|
|
26
|
+
}
|
|
27
|
+
if (logging) {
|
|
28
|
+
console.log("Done!");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.clearAllTables = clearAllTables;
|
|
32
|
+
//# sourceMappingURL=clear-all-tables.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clear-all-tables.js","sourceRoot":"","sources":["../../src/data-population/clear-all-tables.ts"],"names":[],"mappings":";;;AACA,4DAAkE;AAClE,qCAA2C;AAE3C;;GAEG;AACI,KAAK,UAAU,cAAc,CAAC,MAAqB,EAAE,OAAO,GAAG,IAAI;;IACxE,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;IACxC,CAAC;IACD,MAAM,GAAG,MAAM,IAAA,8BAAkB,EAAC,MAAM,CAAC,CAAC;IAC1C,MAAM,gBAAgB,GACpB,MAAA,MAAM,CAAC,gBAAgB,mCAAI,MAAA,MAAM,CAAC,aAAa,0CAAE,gBAAgB,CAAC;IACpE,MAAM,UAAU,GAAG,MAAM,IAAA,0BAAgB,oBAAM,MAAM,CAAC,mBAAmB,EAAG,CAAC;IAC7E,IAAI,CAAC;QACH,MAAM,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;IAAC,OAAO,GAAQ,EAAE,CAAC;QAClB,OAAO,CAAC,KAAK,CAAC,iDAAiD,CAAC,CAAC;QACjE,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACnB,CAAC;YAAS,CAAC;QACT,MAAM,UAAU,CAAC,KAAK,EAAE,CAAC;IAC3B,CAAC;IACD,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACvB,CAAC;AACH,CAAC;AAnBD,wCAmBC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CreateAddressInput, CreateCustomerInput } from "@deenruv/common/lib/generated-types";
|
|
2
|
+
import { SimpleGraphQLClient } from "../simple-graphql-client";
|
|
3
|
+
/**
|
|
4
|
+
* A service for creating mock data via the GraphQL API.
|
|
5
|
+
*/
|
|
6
|
+
export declare class MockDataService {
|
|
7
|
+
private client;
|
|
8
|
+
private logging;
|
|
9
|
+
apiUrl: string;
|
|
10
|
+
constructor(client: SimpleGraphQLClient, logging?: boolean);
|
|
11
|
+
static getCustomers(count: number): Array<{
|
|
12
|
+
customer: CreateCustomerInput;
|
|
13
|
+
address: CreateAddressInput;
|
|
14
|
+
}>;
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated
|
|
17
|
+
* Use `MockDataService.getCustomers()` and create customers directly with CustomerService.
|
|
18
|
+
*/
|
|
19
|
+
populateCustomers(count?: number): Promise<any>;
|
|
20
|
+
private log;
|
|
21
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.MockDataService = void 0;
|
|
7
|
+
const en_GB_1 = __importDefault(require("faker/locale/en_GB"));
|
|
8
|
+
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
9
|
+
/**
|
|
10
|
+
* A service for creating mock data via the GraphQL API.
|
|
11
|
+
*/
|
|
12
|
+
class MockDataService {
|
|
13
|
+
constructor(client, logging = true) {
|
|
14
|
+
this.client = client;
|
|
15
|
+
this.logging = logging;
|
|
16
|
+
// make the generated results deterministic
|
|
17
|
+
en_GB_1.default.seed(1);
|
|
18
|
+
}
|
|
19
|
+
static getCustomers(count) {
|
|
20
|
+
en_GB_1.default.seed(1);
|
|
21
|
+
const results = [];
|
|
22
|
+
for (let i = 0; i < count; i++) {
|
|
23
|
+
const firstName = en_GB_1.default.name.firstName();
|
|
24
|
+
const lastName = en_GB_1.default.name.lastName();
|
|
25
|
+
const customer = {
|
|
26
|
+
firstName,
|
|
27
|
+
lastName,
|
|
28
|
+
emailAddress: en_GB_1.default.internet.email(firstName, lastName),
|
|
29
|
+
phoneNumber: en_GB_1.default.phone.phoneNumber(),
|
|
30
|
+
};
|
|
31
|
+
const address = {
|
|
32
|
+
fullName: `${firstName} ${lastName}`,
|
|
33
|
+
streetLine1: en_GB_1.default.address.streetAddress(),
|
|
34
|
+
city: en_GB_1.default.address.city(),
|
|
35
|
+
province: en_GB_1.default.address.county(),
|
|
36
|
+
postalCode: en_GB_1.default.address.zipCode(),
|
|
37
|
+
countryCode: "GB",
|
|
38
|
+
};
|
|
39
|
+
results.push({ customer, address });
|
|
40
|
+
}
|
|
41
|
+
return results;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* @deprecated
|
|
45
|
+
* Use `MockDataService.getCustomers()` and create customers directly with CustomerService.
|
|
46
|
+
*/
|
|
47
|
+
async populateCustomers(count = 5) {
|
|
48
|
+
for (let i = 0; i < count; i++) {
|
|
49
|
+
const firstName = en_GB_1.default.name.firstName();
|
|
50
|
+
const lastName = en_GB_1.default.name.lastName();
|
|
51
|
+
const query1 = (0, graphql_tag_1.default) `
|
|
52
|
+
mutation CreateCustomer(
|
|
53
|
+
$input: CreateCustomerInput!
|
|
54
|
+
$password: String
|
|
55
|
+
) {
|
|
56
|
+
createCustomer(input: $input, password: $password) {
|
|
57
|
+
... on Customer {
|
|
58
|
+
id
|
|
59
|
+
emailAddress
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
`;
|
|
64
|
+
const variables1 = {
|
|
65
|
+
input: {
|
|
66
|
+
firstName,
|
|
67
|
+
lastName,
|
|
68
|
+
emailAddress: en_GB_1.default.internet.email(firstName, lastName),
|
|
69
|
+
phoneNumber: en_GB_1.default.phone.phoneNumber(),
|
|
70
|
+
},
|
|
71
|
+
password: "test",
|
|
72
|
+
};
|
|
73
|
+
const customer = await this.client.query(query1, variables1).then((data) => data.createCustomer, (err) => this.log(err));
|
|
74
|
+
if (customer) {
|
|
75
|
+
const query2 = (0, graphql_tag_1.default) `
|
|
76
|
+
mutation ($customerId: ID!, $input: CreateAddressInput!) {
|
|
77
|
+
createCustomerAddress(customerId: $customerId, input: $input) {
|
|
78
|
+
id
|
|
79
|
+
streetLine1
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
`;
|
|
83
|
+
const variables2 = {
|
|
84
|
+
input: {
|
|
85
|
+
fullName: `${firstName} ${lastName}`,
|
|
86
|
+
streetLine1: en_GB_1.default.address.streetAddress(),
|
|
87
|
+
city: en_GB_1.default.address.city(),
|
|
88
|
+
province: en_GB_1.default.address.county(),
|
|
89
|
+
postalCode: en_GB_1.default.address.zipCode(),
|
|
90
|
+
countryCode: "GB",
|
|
91
|
+
},
|
|
92
|
+
customerId: customer.id,
|
|
93
|
+
};
|
|
94
|
+
await this.client
|
|
95
|
+
.query(query2, variables2)
|
|
96
|
+
.catch((err) => this.log(err));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
this.log(`Created ${count} Customers`);
|
|
100
|
+
}
|
|
101
|
+
log(...args) {
|
|
102
|
+
if (this.logging) {
|
|
103
|
+
console.log(...args);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
exports.MockDataService = MockDataService;
|
|
108
|
+
//# sourceMappingURL=mock-data.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mock-data.service.js","sourceRoot":"","sources":["../../src/data-population/mock-data.service.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { INestApplicationContext } from "@nestjs/common";
|
|
2
|
+
/**
|
|
3
|
+
* Creates customers with addresses by making API calls to the Admin API.
|
|
4
|
+
*/
|
|
5
|
+
export declare function populateCustomers(app: INestApplicationContext, count: number, loggingFn: (message: string) => void): Promise<void>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.populateCustomers = void 0;
|
|
4
|
+
const core_1 = require("@deenruv/core");
|
|
5
|
+
const get_superadmin_context_1 = require("../utils/get-superadmin-context");
|
|
6
|
+
const mock_data_service_1 = require("./mock-data.service");
|
|
7
|
+
/**
|
|
8
|
+
* Creates customers with addresses by making API calls to the Admin API.
|
|
9
|
+
*/
|
|
10
|
+
async function populateCustomers(app, count, loggingFn) {
|
|
11
|
+
const customerService = app.get(core_1.CustomerService);
|
|
12
|
+
const customerData = mock_data_service_1.MockDataService.getCustomers(count);
|
|
13
|
+
const ctx = await (0, get_superadmin_context_1.getSuperadminContext)(app);
|
|
14
|
+
const password = "test";
|
|
15
|
+
for (const { customer, address } of customerData) {
|
|
16
|
+
try {
|
|
17
|
+
const createdCustomer = await customerService.create(ctx, customer, password);
|
|
18
|
+
if ((0, core_1.isGraphQlErrorResult)(createdCustomer)) {
|
|
19
|
+
loggingFn(`Failed to create customer: ${createdCustomer.message}`);
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
await customerService.createAddress(ctx, createdCustomer.id, address);
|
|
23
|
+
}
|
|
24
|
+
catch (e) {
|
|
25
|
+
loggingFn(`Failed to create customer: ${JSON.stringify(e.message)}`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.populateCustomers = populateCustomers;
|
|
30
|
+
//# sourceMappingURL=populate-customers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"populate-customers.js","sourceRoot":"","sources":["../../src/data-population/populate-customers.ts"],"names":[],"mappings":";;;AACA,wCAIuB;AAEvB,4EAAuE;AAEvE,2DAAsD;AAEtD;;GAEG;AACI,KAAK,UAAU,iBAAiB,CACrC,GAA4B,EAC5B,KAAa,EACb,SAAoC;IAEpC,MAAM,eAAe,GAAG,GAAG,CAAC,GAAG,CAAC,sBAAe,CAAC,CAAC;IACjD,MAAM,YAAY,GAAG,mCAAe,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IACzD,MAAM,GAAG,GAAG,MAAM,IAAA,6CAAoB,EAAC,GAAG,CAAC,CAAC;IAC5C,MAAM,QAAQ,GAAG,MAAM,CAAC;IACxB,KAAK,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,YAAY,EAAE,CAAC;QACjD,IAAI,CAAC;YACH,MAAM,eAAe,GAAG,MAAM,eAAe,CAAC,MAAM,CAClD,GAAG,EACH,QAAQ,EACR,QAAQ,CACT,CAAC;YACF,IAAI,IAAA,2BAAoB,EAAC,eAAe,CAAC,EAAE,CAAC;gBAC1C,SAAS,CAAC,8BAA8B,eAAe,CAAC,OAAO,EAAE,CAAC,CAAC;gBACnE,SAAS;YACX,CAAC;YACD,MAAM,eAAe,CAAC,aAAa,CAAC,GAAG,EAAE,eAAe,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;QACxE,CAAC;QAAC,OAAO,CAAM,EAAE,CAAC;YAChB,SAAS,CAAC,8BAA8B,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QACvE,CAAC;IACH,CAAC;AACH,CAAC;AAzBD,8CAyBC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { INestApplicationContext } from "@nestjs/common";
|
|
2
|
+
import { DeenruvConfig } from "@deenruv/core";
|
|
3
|
+
import { TestServerOptions } from "../types";
|
|
4
|
+
/**
|
|
5
|
+
* Clears all tables from the database and populates with (deterministic) random data.
|
|
6
|
+
*/
|
|
7
|
+
export declare function populateForTesting<T extends INestApplicationContext>(config: Required<DeenruvConfig>, bootstrapFn: (config: DeenruvConfig) => Promise<T>, options: TestServerOptions): Promise<T>;
|