@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.
Files changed (69) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +5 -0
  3. package/lib/config/test-config.d.ts +26 -0
  4. package/lib/config/test-config.js +70 -0
  5. package/lib/config/test-config.js.map +1 -0
  6. package/lib/config/testing-asset-preview-strategy.d.ts +13 -0
  7. package/lib/config/testing-asset-preview-strategy.js +21 -0
  8. package/lib/config/testing-asset-preview-strategy.js.map +1 -0
  9. package/lib/config/testing-asset-storage-strategy.d.ts +18 -0
  10. package/lib/config/testing-asset-storage-strategy.js +47 -0
  11. package/lib/config/testing-asset-storage-strategy.js.map +1 -0
  12. package/lib/config/testing-entity-id-strategy.d.ts +11 -0
  13. package/lib/config/testing-entity-id-strategy.js +22 -0
  14. package/lib/config/testing-entity-id-strategy.js.map +1 -0
  15. package/lib/create-test-environment.d.ts +57 -0
  16. package/lib/create-test-environment.js +47 -0
  17. package/lib/create-test-environment.js.map +1 -0
  18. package/lib/data-population/clear-all-tables.d.ts +5 -0
  19. package/lib/data-population/clear-all-tables.js +32 -0
  20. package/lib/data-population/clear-all-tables.js.map +1 -0
  21. package/lib/data-population/mock-data.service.d.ts +21 -0
  22. package/lib/data-population/mock-data.service.js +108 -0
  23. package/lib/data-population/mock-data.service.js.map +1 -0
  24. package/lib/data-population/populate-customers.d.ts +5 -0
  25. package/lib/data-population/populate-customers.js +30 -0
  26. package/lib/data-population/populate-customers.js.map +1 -0
  27. package/lib/data-population/populate-for-testing.d.ts +7 -0
  28. package/lib/data-population/populate-for-testing.js +42 -0
  29. package/lib/data-population/populate-for-testing.js.map +1 -0
  30. package/lib/error-result-guard.d.ts +65 -0
  31. package/lib/error-result-guard.js +85 -0
  32. package/lib/error-result-guard.js.map +1 -0
  33. package/lib/index.d.ts +14 -0
  34. package/lib/index.js +31 -0
  35. package/lib/index.js.map +1 -0
  36. package/lib/initializers/initializers.d.ts +14 -0
  37. package/lib/initializers/initializers.js +24 -0
  38. package/lib/initializers/initializers.js.map +1 -0
  39. package/lib/initializers/mysql-initializer.d.ts +10 -0
  40. package/lib/initializers/mysql-initializer.js +43 -0
  41. package/lib/initializers/mysql-initializer.js.map +1 -0
  42. package/lib/initializers/postgres-initializer.d.ts +10 -0
  43. package/lib/initializers/postgres-initializer.js +41 -0
  44. package/lib/initializers/postgres-initializer.js.map +1 -0
  45. package/lib/initializers/sqljs-initializer.d.ts +19 -0
  46. package/lib/initializers/sqljs-initializer.js +55 -0
  47. package/lib/initializers/sqljs-initializer.js.map +1 -0
  48. package/lib/initializers/test-db-initializer.d.ts +42 -0
  49. package/lib/initializers/test-db-initializer.js +3 -0
  50. package/lib/initializers/test-db-initializer.js.map +1 -0
  51. package/lib/simple-graphql-client.d.ts +86 -0
  52. package/lib/simple-graphql-client.js +229 -0
  53. package/lib/simple-graphql-client.js.map +1 -0
  54. package/lib/test-server.d.ts +45 -0
  55. package/lib/test-server.js +123 -0
  56. package/lib/test-server.js.map +1 -0
  57. package/lib/testing-logger.d.ts +67 -0
  58. package/lib/testing-logger.js +82 -0
  59. package/lib/testing-logger.js.map +1 -0
  60. package/lib/types.d.ts +42 -0
  61. package/lib/types.js +3 -0
  62. package/lib/types.js.map +1 -0
  63. package/lib/utils/create-upload-post-data.d.ts +23 -0
  64. package/lib/utils/create-upload-post-data.js +55 -0
  65. package/lib/utils/create-upload-post-data.js.map +1 -0
  66. package/lib/utils/get-superadmin-context.d.ts +10 -0
  67. package/lib/utils/get-superadmin-context.js +40 -0
  68. package/lib/utils/get-superadmin-context.js.map +1 -0
  69. package/package.json +64 -0
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createUploadPostData = void 0;
4
+ const graphql_1 = require("graphql");
5
+ /**
6
+ * Creates a data structure which can be used to mae a curl request to upload files to a mutation using
7
+ * the Upload type.
8
+ */
9
+ function createUploadPostData(mutation, filePaths, mapVariables) {
10
+ const operationDef = mutation.definitions.find((d) => d.kind === graphql_1.Kind.OPERATION_DEFINITION);
11
+ const filePathsArray = Array.isArray(filePaths)
12
+ ? filePaths
13
+ : [filePaths];
14
+ const variables = mapVariables(filePaths);
15
+ const postData = {
16
+ operations: {
17
+ operationName: operationDef.name
18
+ ? operationDef.name.value
19
+ : "AnonymousMutation",
20
+ variables,
21
+ query: (0, graphql_1.print)(mutation),
22
+ },
23
+ map: filePathsArray.reduce((output, filePath, i) => {
24
+ return Object.assign(Object.assign({}, output), { [i.toString()]: objectPath(variables, i).join(".") });
25
+ }, {}),
26
+ filePaths: filePathsArray.map((filePath, i) => ({
27
+ name: i.toString(),
28
+ file: filePath,
29
+ })),
30
+ };
31
+ return postData;
32
+ }
33
+ exports.createUploadPostData = createUploadPostData;
34
+ function objectPath(variables, i) {
35
+ const path = ["variables"];
36
+ let current = variables;
37
+ while (current !== null) {
38
+ const props = Object.getOwnPropertyNames(current);
39
+ if (props) {
40
+ const firstProp = props[0];
41
+ const val = current[firstProp];
42
+ if (Array.isArray(val)) {
43
+ path.push(firstProp);
44
+ path.push(i);
45
+ current = val[0];
46
+ }
47
+ else {
48
+ path.push(firstProp);
49
+ current = val;
50
+ }
51
+ }
52
+ }
53
+ return path;
54
+ }
55
+ //# sourceMappingURL=create-upload-post-data.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-upload-post-data.js","sourceRoot":"","sources":["../../src/utils/create-upload-post-data.ts"],"names":[],"mappings":";;;AAAA,qCAA6E;AAqB7E;;;GAGG;AACH,SAAgB,oBAAoB,CAClC,QAAsB,EACtB,SAAY,EACZ,YAAiC;IAEjC,MAAM,YAAY,GAAG,QAAQ,CAAC,WAAW,CAAC,IAAI,CAC5C,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,cAAI,CAAC,oBAAoB,CACjB,CAAC;IAE7B,MAAM,cAAc,GAAa,KAAK,CAAC,OAAO,CAAC,SAAS,CA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IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;gBACvB,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;gBACrB,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;gBACb,OAAO,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;YACnB,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;gBACrB,OAAO,GAAG,GAAG,CAAC;YAChB,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { INestApplicationContext } from "@nestjs/common";
2
+ import { RequestContext } from "@deenruv/core";
3
+ /**
4
+ * @description
5
+ * Creates a {@link RequestContext} configured for the default Channel with the activeUser set
6
+ * as the superadmin user. Useful for populating data.
7
+ *
8
+ * @docsCategory testing
9
+ */
10
+ export declare function getSuperadminContext(app: INestApplicationContext): Promise<RequestContext>;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSuperadminContext = void 0;
4
+ const core_1 = require("@deenruv/core");
5
+ /**
6
+ * @description
7
+ * Creates a {@link RequestContext} configured for the default Channel with the activeUser set
8
+ * as the superadmin user. Useful for populating data.
9
+ *
10
+ * @docsCategory testing
11
+ */
12
+ async function getSuperadminContext(app) {
13
+ const defaultChannel = await app.get(core_1.ChannelService).getDefaultChannel();
14
+ const connection = app.get(core_1.TransactionalConnection);
15
+ const configService = app.get(core_1.ConfigService);
16
+ const { superadminCredentials } = configService.authOptions;
17
+ const superAdminUser = await connection
18
+ .getRepository(core_1.User)
19
+ .findOneOrFail({ where: { identifier: superadminCredentials.identifier } });
20
+ return new core_1.RequestContext({
21
+ channel: defaultChannel,
22
+ apiType: "admin",
23
+ isAuthorized: true,
24
+ authorizedAsOwnerOnly: false,
25
+ session: {
26
+ id: "",
27
+ token: "",
28
+ expires: new Date(),
29
+ cacheExpiry: 999999,
30
+ user: {
31
+ id: superAdminUser.id,
32
+ identifier: superAdminUser.identifier,
33
+ verified: true,
34
+ channelPermissions: [],
35
+ },
36
+ },
37
+ });
38
+ }
39
+ exports.getSuperadminContext = getSuperadminContext;
40
+ //# sourceMappingURL=get-superadmin-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-superadmin-context.js","sourceRoot":"","sources":["../../src/utils/get-superadmin-context.ts"],"names":[],"mappings":";;;AACA,wCAMuB;AAEvB;;;;;;GAMG;AACI,KAAK,UAAU,oBAAoB,CACxC,GAA4B;IAE5B,MAAM,cAAc,GAAG,MAAM,GAAG,CAAC,GAAG,CAAC,qBAAc,CAAC,CAAC,iBAAiB,EAAE,CAAC;IACzE,MAAM,UAAU,GAAG,GAAG,CAAC,GAAG,CAAC,8BAAuB,CAAC,CAAC;IACpD,MAAM,aAAa,GAAG,GAAG,CAAC,GAAG,CAAC,oBAAa,CAAC,CAAC;IAC7C,MAAM,EAAE,qBAAqB,EAAE,GAAG,aAAa,CAAC,WAAW,CAAC;IAC5D,MAAM,cAAc,GAAG,MAAM,UAAU;SACpC,aAAa,CAAC,WAAI,CAAC;SACnB,aAAa,CAAC,EAAE,KAAK,EAAE,EAAE,UAAU,EAAE,qBAAqB,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IAC9E,OAAO,IAAI,qBAAc,CAAC;QACxB,OAAO,EAAE,cAAc;QACvB,OAAO,EAAE,OAAO;QAChB,YAAY,EAAE,IAAI;QAClB,qBAAqB,EAAE,KAAK;QAC5B,OAAO,EAAE;YACP,EAAE,EAAE,EAAE;YACN,KAAK,EAAE,EAAE;YACT,OAAO,EAAE,IAAI,IAAI,EAAE;YACnB,WAAW,EAAE,MAAM;YACnB,IAAI,EAAE;gBACJ,EAAE,EAAE,cAAc,CAAC,EAAE;gBACrB,UAAU,EAAE,cAAc,CAAC,UAAU;gBACrC,QAAQ,EAAE,IAAI;gBACd,kBAAkB,EAAE,EAAE;aACvB;SACF;KACF,CAAC,CAAC;AACL,CAAC;AA5BD,oDA4BC"}
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@deenruv/testing",
3
+ "version": "1.0.0",
4
+ "description": "End-to-end testing tools for deenruv projects",
5
+ "keywords": [
6
+ "deenruv",
7
+ "testing",
8
+ "e2e"
9
+ ],
10
+ "homepage": "https://deenruv.com/",
11
+ "license": "MIT",
12
+ "directories": {
13
+ "lib": "lib"
14
+ },
15
+ "files": [
16
+ "lib"
17
+ ],
18
+ "publishConfig": {
19
+ "access": "public"
20
+ },
21
+ "main": "lib/index.js",
22
+ "types": "lib/index.d.ts",
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/deenruv-ecommerce/deenruv.git"
26
+ },
27
+ "bugs": {
28
+ "url": "https://github.com/deenruv-ecommerce/deenruv/issues"
29
+ },
30
+ "peerDependencies": {
31
+ "typeorm": "^0.3.20",
32
+ "@deenruv/core": "^0.1.0"
33
+ },
34
+ "dependencies": {
35
+ "@graphql-typed-document-node/core": "^3.2.0",
36
+ "@nestjs/common": "^10.3.10",
37
+ "@nestjs/core": "^10.3.10",
38
+ "express": "^4.21.0",
39
+ "faker": "^4.1.0",
40
+ "form-data": "^4.0.0",
41
+ "node-fetch": "^2.7.0",
42
+ "sql.js": "1.8.0",
43
+ "@deenruv/common": "1.0.0"
44
+ },
45
+ "devDependencies": {
46
+ "@types/express": "^4.17.21",
47
+ "@types/faker": "^5.5.9",
48
+ "@types/mysql": "^2.15.26",
49
+ "@types/node-fetch": "^2.6.4",
50
+ "@types/pg": "^8.11.2",
51
+ "mysql": "^2.18.1",
52
+ "pg": "^8.11.3",
53
+ "rimraf": "^5.0.5",
54
+ "typescript": "5.3.3",
55
+ "@deenruv/core": "1.0.0"
56
+ },
57
+ "scripts": {
58
+ "build": "tsc -p ./tsconfig.build.json",
59
+ "watch": "tsc -p ./tsconfig.build.json -w",
60
+ "lint": "eslint .",
61
+ "lint:fix": "eslint --fix .",
62
+ "ci": "npm run build"
63
+ }
64
+ }