@ludeo/cloud-common 1.0.9 → 1.0.11

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.
@@ -0,0 +1,163 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const class_validator_1 = require("class-validator");
4
+ const crypto_1 = require("crypto");
5
+ const cloud_1 = require("../types/cloud");
6
+ const cloud_session_context_1 = require("./cloud-session-context");
7
+ describe("CloudSessionContext Validation", () => {
8
+ it("should succeed with valid data", async () => {
9
+ const context = new cloud_session_context_1.CloudSessionContext();
10
+ context.allocationRequestId = (0, crypto_1.randomUUID)();
11
+ context.clientRequestId = (0, crypto_1.randomUUID)();
12
+ context.cloudSessionId = (0, crypto_1.randomUUID)();
13
+ context.userId = (0, crypto_1.randomUUID)();
14
+ context.gameId = (0, crypto_1.randomUUID)();
15
+ context.ludeoId = (0, crypto_1.randomUUID)();
16
+ context.poolId = (0, crypto_1.randomUUID)();
17
+ context.cloudProvider = cloud_1.CloudProvider.AWS;
18
+ context.resourceId = (0, crypto_1.randomUUID)();
19
+ const errors = await (0, class_validator_1.validate)(context);
20
+ expect(errors.length).toBe(0);
21
+ });
22
+ it("should fail if allocationRequestId is not a valid UUID", async () => {
23
+ const context = new cloud_session_context_1.CloudSessionContext();
24
+ context.allocationRequestId = "invalid-uuid";
25
+ context.clientRequestId = (0, crypto_1.randomUUID)();
26
+ context.cloudSessionId = (0, crypto_1.randomUUID)();
27
+ context.userId = (0, crypto_1.randomUUID)();
28
+ context.gameId = (0, crypto_1.randomUUID)();
29
+ context.ludeoId = (0, crypto_1.randomUUID)();
30
+ context.poolId = (0, crypto_1.randomUUID)();
31
+ context.cloudProvider = cloud_1.CloudProvider.AWS;
32
+ const errors = await (0, class_validator_1.validate)(context);
33
+ expect(errors.length).toBeGreaterThan(0);
34
+ expect(errors.some((err) => err.property === "allocationRequestId")).toBeTruthy();
35
+ });
36
+ it("should fail if clientRequestId is not a valid UUID", async () => {
37
+ const context = new cloud_session_context_1.CloudSessionContext();
38
+ context.allocationRequestId = (0, crypto_1.randomUUID)();
39
+ context.clientRequestId = "invalid-uuid";
40
+ context.cloudSessionId = (0, crypto_1.randomUUID)();
41
+ context.userId = (0, crypto_1.randomUUID)();
42
+ context.gameId = (0, crypto_1.randomUUID)();
43
+ context.ludeoId = (0, crypto_1.randomUUID)();
44
+ context.poolId = (0, crypto_1.randomUUID)();
45
+ context.cloudProvider = cloud_1.CloudProvider.AWS;
46
+ const errors = await (0, class_validator_1.validate)(context);
47
+ expect(errors.length).toBeGreaterThan(0);
48
+ expect(errors.some((err) => err.property === "clientRequestId")).toBeTruthy();
49
+ });
50
+ it("should fail if cloudSessionId is not a valid UUID", async () => {
51
+ const context = new cloud_session_context_1.CloudSessionContext();
52
+ context.allocationRequestId = (0, crypto_1.randomUUID)();
53
+ context.clientRequestId = (0, crypto_1.randomUUID)();
54
+ context.cloudSessionId = "invalid-uuid";
55
+ context.userId = (0, crypto_1.randomUUID)();
56
+ context.gameId = (0, crypto_1.randomUUID)();
57
+ context.ludeoId = (0, crypto_1.randomUUID)();
58
+ context.poolId = (0, crypto_1.randomUUID)();
59
+ context.cloudProvider = cloud_1.CloudProvider.AWS;
60
+ const errors = await (0, class_validator_1.validate)(context);
61
+ expect(errors.length).toBeGreaterThan(0);
62
+ expect(errors.some((err) => err.property === "cloudSessionId")).toBeTruthy();
63
+ });
64
+ it("should fail if userId is not a valid UUID", async () => {
65
+ const context = new cloud_session_context_1.CloudSessionContext();
66
+ context.allocationRequestId = (0, crypto_1.randomUUID)();
67
+ context.clientRequestId = (0, crypto_1.randomUUID)();
68
+ context.cloudSessionId = (0, crypto_1.randomUUID)();
69
+ context.userId = "invalid-uuid";
70
+ context.gameId = (0, crypto_1.randomUUID)();
71
+ context.ludeoId = (0, crypto_1.randomUUID)();
72
+ context.poolId = (0, crypto_1.randomUUID)();
73
+ context.cloudProvider = cloud_1.CloudProvider.AWS;
74
+ const errors = await (0, class_validator_1.validate)(context);
75
+ expect(errors.length).toBeGreaterThan(0);
76
+ expect(errors.some((err) => err.property === "userId")).toBeTruthy();
77
+ });
78
+ it("should fail if gameId is not a valid UUID", async () => {
79
+ const context = new cloud_session_context_1.CloudSessionContext();
80
+ context.allocationRequestId = (0, crypto_1.randomUUID)();
81
+ context.clientRequestId = (0, crypto_1.randomUUID)();
82
+ context.cloudSessionId = (0, crypto_1.randomUUID)();
83
+ context.userId = (0, crypto_1.randomUUID)();
84
+ context.gameId = "invalid-uuid";
85
+ context.ludeoId = (0, crypto_1.randomUUID)();
86
+ context.poolId = (0, crypto_1.randomUUID)();
87
+ context.cloudProvider = cloud_1.CloudProvider.AWS;
88
+ const errors = await (0, class_validator_1.validate)(context);
89
+ expect(errors.length).toBeGreaterThan(0);
90
+ expect(errors.some((err) => err.property === "gameId")).toBeTruthy();
91
+ });
92
+ it("should fail if ludeoId is not a valid UUID", async () => {
93
+ const context = new cloud_session_context_1.CloudSessionContext();
94
+ context.allocationRequestId = (0, crypto_1.randomUUID)();
95
+ context.clientRequestId = (0, crypto_1.randomUUID)();
96
+ context.cloudSessionId = (0, crypto_1.randomUUID)();
97
+ context.userId = (0, crypto_1.randomUUID)();
98
+ context.gameId = (0, crypto_1.randomUUID)();
99
+ context.ludeoId = "invalid-uuid";
100
+ context.poolId = (0, crypto_1.randomUUID)();
101
+ context.cloudProvider = cloud_1.CloudProvider.AWS;
102
+ const errors = await (0, class_validator_1.validate)(context);
103
+ expect(errors.length).toBeGreaterThan(0);
104
+ expect(errors.some((err) => err.property === "ludeoId")).toBeTruthy();
105
+ });
106
+ it("should fail if poolId is not a valid UUID", async () => {
107
+ const context = new cloud_session_context_1.CloudSessionContext();
108
+ context.allocationRequestId = (0, crypto_1.randomUUID)();
109
+ context.clientRequestId = (0, crypto_1.randomUUID)();
110
+ context.cloudSessionId = (0, crypto_1.randomUUID)();
111
+ context.userId = (0, crypto_1.randomUUID)();
112
+ context.gameId = (0, crypto_1.randomUUID)();
113
+ context.ludeoId = (0, crypto_1.randomUUID)();
114
+ context.poolId = "invalid-uuid";
115
+ context.cloudProvider = cloud_1.CloudProvider.AWS;
116
+ const errors = await (0, class_validator_1.validate)(context);
117
+ expect(errors.length).toBeGreaterThan(0);
118
+ expect(errors.some((err) => err.property === "poolId")).toBeTruthy();
119
+ });
120
+ it("should fail if cloudProvider is not a string", async () => {
121
+ const context = new cloud_session_context_1.CloudSessionContext();
122
+ context.allocationRequestId = (0, crypto_1.randomUUID)();
123
+ context.clientRequestId = (0, crypto_1.randomUUID)();
124
+ context.cloudSessionId = (0, crypto_1.randomUUID)();
125
+ context.userId = (0, crypto_1.randomUUID)();
126
+ context.gameId = (0, crypto_1.randomUUID)();
127
+ context.ludeoId = (0, crypto_1.randomUUID)();
128
+ context.poolId = (0, crypto_1.randomUUID)();
129
+ context.cloudProvider = 123;
130
+ const errors = await (0, class_validator_1.validate)(context);
131
+ expect(errors.length).toBeGreaterThan(0);
132
+ expect(errors.some((err) => err.property === "cloudProvider")).toBeTruthy();
133
+ });
134
+ it("should fail if resourceId is not a valid UUID when provided", async () => {
135
+ const context = new cloud_session_context_1.CloudSessionContext();
136
+ context.allocationRequestId = (0, crypto_1.randomUUID)();
137
+ context.clientRequestId = (0, crypto_1.randomUUID)();
138
+ context.cloudSessionId = (0, crypto_1.randomUUID)();
139
+ context.userId = (0, crypto_1.randomUUID)();
140
+ context.gameId = (0, crypto_1.randomUUID)();
141
+ context.ludeoId = (0, crypto_1.randomUUID)();
142
+ context.poolId = (0, crypto_1.randomUUID)();
143
+ context.cloudProvider = cloud_1.CloudProvider.AWS;
144
+ context.resourceId = "invalid-uuid";
145
+ const errors = await (0, class_validator_1.validate)(context);
146
+ expect(errors.length).toBeGreaterThan(0);
147
+ expect(errors.some((err) => err.property === "resourceId")).toBeTruthy();
148
+ });
149
+ it("should succeed when resourceId is not provided", async () => {
150
+ const context = new cloud_session_context_1.CloudSessionContext();
151
+ context.allocationRequestId = (0, crypto_1.randomUUID)();
152
+ context.clientRequestId = (0, crypto_1.randomUUID)();
153
+ context.cloudSessionId = (0, crypto_1.randomUUID)();
154
+ context.userId = (0, crypto_1.randomUUID)();
155
+ context.gameId = (0, crypto_1.randomUUID)();
156
+ context.ludeoId = (0, crypto_1.randomUUID)();
157
+ context.poolId = (0, crypto_1.randomUUID)();
158
+ context.cloudProvider = cloud_1.CloudProvider.AWS;
159
+ const errors = await (0, class_validator_1.validate)(context);
160
+ expect(errors.length).toBe(0);
161
+ });
162
+ });
163
+ //# sourceMappingURL=cloud-session-context.validation.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloud-session-context.validation.spec.js","sourceRoot":"","sources":["../../../src/v2/contexts/cloud-session-context.validation.spec.ts"],"names":[],"mappings":";;AAAA,qDAA2C;AAC3C,mCAAoC;AACpC,0CAA+C;AAC/C,mEAA8D;AAE9D,QAAQ,CAAC,gCAAgC,EAAE,GAAG,EAAE;IAC9C,EAAE,CAAC,gCAAgC,EAAE,KAAK,IAAI,EAAE;QAC9C,MAAM,OAAO,GAAG,IAAI,2CAAmB,EAAE,CAAC;QAC1C,OAAO,CAAC,mBAAmB,GAAG,IAAA,mBAAU,GAAE,CAAC;QAC3C,OAAO,CAAC,eAAe,GAAG,IAAA,mBAAU,GAAE,CAAC;QACvC,OAAO,CAAC,cAAc,GAAG,IAAA,mBAAU,GAAE,CAAC;QACtC,OAAO,CAAC,MAAM,GAAG,IAAA,mBAAU,GAAE,CAAC;QAC9B,OAAO,CAAC,MAAM,GAAG,IAAA,mBAAU,GAAE,CAAC;QAC9B,OAAO,CAAC,OAAO,GAAG,IAAA,mBAAU,GAAE,CAAC;QAC/B,OAAO,CAAC,MAAM,GAAG,IAAA,mBAAU,GAAE,CAAC;QAC9B,OAAO,CAAC,aAAa,GAAG,qBAAa,CAAC,GAAG,CAAC;QAC1C,OAAO,CAAC,UAAU,GAAG,IAAA,mBAAU,GAAE,CAAC;QAElC,MAAM,MAAM,GAAG,MAAM,IAAA,0BAAQ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 +31,13 @@ __decorate([
31
31
  __metadata("design:type", String)
32
32
  ], CloudResourceCreatedPayload.prototype, "cloudProvider", void 0);
33
33
  __decorate([
34
- (0, class_validator_1.IsString)(),
34
+ (0, class_validator_1.IsUUID)(),
35
35
  (0, class_validator_1.IsOptional)(),
36
36
  __metadata("design:type", String)
37
37
  ], CloudResourceCreatedPayload.prototype, "clientRequestId", void 0);
38
38
  __decorate([
39
39
  (0, class_validator_1.IsOptional)(),
40
- (0, class_validator_1.IsString)(),
40
+ (0, class_validator_1.IsUUID)(),
41
41
  __metadata("design:type", String)
42
42
  ], CloudResourceCreatedPayload.prototype, "cloudSessionId", void 0);
43
43
  __decorate([
@@ -1 +1 @@
1
- {"version":3,"file":"cloud-resource-created.event.js","sourceRoot":"","sources":["../../../src/v2/events/cloud-resource-created.event.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yDAAqD;AACrD,oCAAgF;AAChF,6EAAwE;AACxE,qDAAuE;AACvE,oGAAqF;AAErF,MAAa,2BAA2B;CAoBvC;AApBD,kEAoBC;AAlBC;IADC,IAAA,wBAAM,GAAE;;+DACU;AAGnB;IADC,IAAA,wBAAM,GAAE;;2DACM;AAGf;IADC,IAAA,wBAAM,EAAC,qBAAa,CAAC;;kEACO;AAI7B;IAFC,IAAA,0BAAQ,GAAE;IACV,IAAA,4BAAU,GAAE;;oEACY;AAIzB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;mEACa;AAGxB;IADC,IAAA,mDAAkB,EAAC,GAAG,EAAE,CAAC,2BAAmB,CAAC;;qEACX;AAGrC,MAAa,oBAAqB,SAAQ,wBAAU;IAGlD,YAAY,EAAE,OAAO,GAAG,IAAI,EAAE,OAAO,GAAG,IAAI,EAAE;QAC5C,KAAK,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC;QACvC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;;AAPH,oDAcC;AAbiB,+BAAU,GAAG,wCAAwC,CAAC;AAStE;IADC,IAAA,mDAAkB,EAAC,GAAG,EAAE,CAAC,2BAA2B,CAAC;8BAC7C,2BAA2B;qDAAC;AAGrC;IADC,IAAA,mDAAkB,EAAC,GAAG,EAAE,CAAC,2CAAmB,CAAC;8BACrC,2CAAmB;qDAAC"}
1
+ {"version":3,"file":"cloud-resource-created.event.js","sourceRoot":"","sources":["../../../src/v2/events/cloud-resource-created.event.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yDAAqD;AACrD,oCAAgF;AAChF,6EAAwE;AACxE,qDAAuE;AACvE,oGAAqF;AAErF,MAAa,2BAA2B;CAoBvC;AApBD,kEAoBC;AAlBC;IADC,IAAA,wBAAM,GAAE;;+DACU;AAGnB;IADC,IAAA,wBAAM,GAAE;;2DACM;AAGf;IADC,IAAA,wBAAM,EAAC,qBAAa,CAAC;;kEACO;AAI7B;IAFC,IAAA,wBAAM,GAAE;IACR,IAAA,4BAAU,GAAE;;oEACY;AAIzB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,wBAAM,GAAE;;mEACe;AAGxB;IADC,IAAA,mDAAkB,EAAC,GAAG,EAAE,CAAC,2BAAmB,CAAC;;qEACX;AAGrC,MAAa,oBAAqB,SAAQ,wBAAU;IAGlD,YAAY,EAAE,OAAO,GAAG,IAAI,EAAE,OAAO,GAAG,IAAI,EAAE;QAC5C,KAAK,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC;QACvC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;;AAPH,oDAcC;AAbiB,+BAAU,GAAG,wCAAwC,CAAC;AAStE;IADC,IAAA,mDAAkB,EAAC,GAAG,EAAE,CAAC,2BAA2B,CAAC;8BAC7C,2BAA2B;qDAAC;AAGrC;IADC,IAAA,mDAAkB,EAAC,GAAG,EAAE,CAAC,2CAAmB,CAAC;8BACrC,2CAAmB;qDAAC"}
package/jest.config.ts ADDED
@@ -0,0 +1,12 @@
1
+ export default {
2
+ displayName: "cloud-commom",
3
+ preset: "ts-jest",
4
+ clearMocks: true,
5
+ testEnvironment: "node",
6
+ transform: {
7
+ "^.+\\.[tj]s$": "ts-jest",
8
+ },
9
+ moduleFileExtensions: ["ts", "js", "html"],
10
+ coverageDirectory: "",
11
+ coverageReporters: ["json-summary", "cobertura", "lcov", "text"],
12
+ };
package/package.json CHANGED
@@ -1,19 +1,24 @@
1
1
  {
2
2
  "name": "@ludeo/cloud-common",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "author": "Yahil Didi",
7
7
  "scripts": {
8
- "build": "tsc"
8
+ "build": "tsc",
9
+ "test": "jest"
9
10
  },
10
11
  "dependencies": {
11
12
  "@ludeo/aws-gamecast-sdk": "^2.1626.4",
12
13
  "@nestjs/common": "^10.3.10",
13
14
  "class-transformer": "^0.5.1",
14
- "class-validator": "^0.14.1"
15
+ "class-validator": "^0.14.1",
16
+ "jest": "^29.7.0"
15
17
  },
16
18
  "devDependencies": {
19
+ "@types/jest": "^29.5.12",
20
+ "ts-jest": "^29.1.5",
21
+ "ts-node": "^10.9.2",
17
22
  "typescript": "^5.5.3"
18
23
  }
19
24
  }
@@ -0,0 +1,70 @@
1
+ import { validate } from "class-validator";
2
+ import { LudeoEvent } from "./ludeo-event";
3
+
4
+ describe("LudeoEvent Validation", () => {
5
+ it("should succeed with valid data", async () => {
6
+ const event = new LudeoEvent("TestEvent");
7
+
8
+ const errors = await validate(event);
9
+ expect(errors.length).toBe(0);
10
+ });
11
+
12
+ it("should fail if eventId is not a valid UUID", async () => {
13
+ const event = new LudeoEvent("TestEvent");
14
+ event.eventId = "invalid-uuid";
15
+
16
+ const errors = await validate(event);
17
+ expect(errors.length).toBe(1);
18
+ expect(errors[0].constraints).toHaveProperty("isUuid");
19
+ });
20
+
21
+ it("should fail if eventName is empty", async () => {
22
+ const event = new LudeoEvent("");
23
+
24
+ const errors = await validate(event);
25
+ expect(errors.length).toBe(1);
26
+ expect(errors[0].constraints).toHaveProperty("isNotEmpty");
27
+ });
28
+
29
+ it("should fail if eventName is not a string", async () => {
30
+ const event = new LudeoEvent("TestEvent");
31
+ (event as any).eventName = 12345;
32
+
33
+ const errors = await validate(event);
34
+ expect(errors.length).toBe(1);
35
+ expect(errors[0].constraints).toHaveProperty("isString");
36
+ });
37
+
38
+ it("should fail if timestamp is not an integer", async () => {
39
+ const event = new LudeoEvent("TestEvent");
40
+ (event as any).timestamp = "not-an-integer";
41
+
42
+ const errors = await validate(event);
43
+ expect(errors.length).toBe(1);
44
+ expect(errors[0].constraints).toHaveProperty("isInt");
45
+ });
46
+
47
+ it("should fail if timestamp is missing", async () => {
48
+ const event = new LudeoEvent("TestEvent");
49
+ delete (event as any).timestamp;
50
+
51
+ const errors = await validate(event);
52
+ expect(errors.length).toBe(1);
53
+ expect(errors[0].constraints).toHaveProperty("isInt");
54
+ });
55
+
56
+ it("should fail if eventVersion is not 3.0", async () => {
57
+ const event = new LudeoEvent("TestEvent");
58
+ const errors = await validate(event);
59
+ expect(errors.length).toBe(0);
60
+ expect(event.eventVersion).toBe("3.0");
61
+ });
62
+
63
+ it("should fail if missing eventVersion", async () => {
64
+ const event = new LudeoEvent("TestEvent");
65
+ delete (event as any).eventVersion;
66
+
67
+ const errors = await validate(event);
68
+ expect(errors.length).toBe(1);
69
+ });
70
+ });
@@ -0,0 +1,190 @@
1
+ import { validate } from "class-validator";
2
+ import { randomUUID } from "crypto";
3
+ import { CloudProvider } from "../types/cloud";
4
+ import { CloudSessionContext } from "./cloud-session-context";
5
+
6
+ describe("CloudSessionContext Validation", () => {
7
+ it("should succeed with valid data", async () => {
8
+ const context = new CloudSessionContext();
9
+ context.allocationRequestId = randomUUID();
10
+ context.clientRequestId = randomUUID();
11
+ context.cloudSessionId = randomUUID();
12
+ context.userId = randomUUID();
13
+ context.gameId = randomUUID();
14
+ context.ludeoId = randomUUID();
15
+ context.poolId = randomUUID();
16
+ context.cloudProvider = CloudProvider.AWS;
17
+ context.resourceId = randomUUID();
18
+
19
+ const errors = await validate(context);
20
+ expect(errors.length).toBe(0);
21
+ });
22
+
23
+ it("should fail if allocationRequestId is not a valid UUID", async () => {
24
+ const context = new CloudSessionContext();
25
+ context.allocationRequestId = "invalid-uuid";
26
+ context.clientRequestId = randomUUID();
27
+ context.cloudSessionId = randomUUID();
28
+ context.userId = randomUUID();
29
+ context.gameId = randomUUID();
30
+ context.ludeoId = randomUUID();
31
+ context.poolId = randomUUID();
32
+ context.cloudProvider = CloudProvider.AWS;
33
+
34
+ const errors = await validate(context);
35
+ expect(errors.length).toBeGreaterThan(0);
36
+ expect(
37
+ errors.some((err) => err.property === "allocationRequestId")
38
+ ).toBeTruthy();
39
+ });
40
+
41
+ it("should fail if clientRequestId is not a valid UUID", async () => {
42
+ const context = new CloudSessionContext();
43
+ context.allocationRequestId = randomUUID();
44
+ context.clientRequestId = "invalid-uuid";
45
+ context.cloudSessionId = randomUUID();
46
+ context.userId = randomUUID();
47
+ context.gameId = randomUUID();
48
+ context.ludeoId = randomUUID();
49
+ context.poolId = randomUUID();
50
+ context.cloudProvider = CloudProvider.AWS;
51
+
52
+ const errors = await validate(context);
53
+ expect(errors.length).toBeGreaterThan(0);
54
+ expect(
55
+ errors.some((err) => err.property === "clientRequestId")
56
+ ).toBeTruthy();
57
+ });
58
+
59
+ it("should fail if cloudSessionId is not a valid UUID", async () => {
60
+ const context = new CloudSessionContext();
61
+ context.allocationRequestId = randomUUID();
62
+ context.clientRequestId = randomUUID();
63
+ context.cloudSessionId = "invalid-uuid";
64
+ context.userId = randomUUID();
65
+ context.gameId = randomUUID();
66
+ context.ludeoId = randomUUID();
67
+ context.poolId = randomUUID();
68
+ context.cloudProvider = CloudProvider.AWS;
69
+
70
+ const errors = await validate(context);
71
+ expect(errors.length).toBeGreaterThan(0);
72
+ expect(
73
+ errors.some((err) => err.property === "cloudSessionId")
74
+ ).toBeTruthy();
75
+ });
76
+
77
+ it("should fail if userId is not a valid UUID", async () => {
78
+ const context = new CloudSessionContext();
79
+ context.allocationRequestId = randomUUID();
80
+ context.clientRequestId = randomUUID();
81
+ context.cloudSessionId = randomUUID();
82
+ context.userId = "invalid-uuid";
83
+ context.gameId = randomUUID();
84
+ context.ludeoId = randomUUID();
85
+ context.poolId = randomUUID();
86
+ context.cloudProvider = CloudProvider.AWS;
87
+
88
+ const errors = await validate(context);
89
+ expect(errors.length).toBeGreaterThan(0);
90
+ expect(errors.some((err) => err.property === "userId")).toBeTruthy();
91
+ });
92
+
93
+ it("should fail if gameId is not a valid UUID", async () => {
94
+ const context = new CloudSessionContext();
95
+ context.allocationRequestId = randomUUID();
96
+ context.clientRequestId = randomUUID();
97
+ context.cloudSessionId = randomUUID();
98
+ context.userId = randomUUID();
99
+ context.gameId = "invalid-uuid";
100
+ context.ludeoId = randomUUID();
101
+ context.poolId = randomUUID();
102
+ context.cloudProvider = CloudProvider.AWS;
103
+
104
+ const errors = await validate(context);
105
+ expect(errors.length).toBeGreaterThan(0);
106
+ expect(errors.some((err) => err.property === "gameId")).toBeTruthy();
107
+ });
108
+
109
+ it("should fail if ludeoId is not a valid UUID", async () => {
110
+ const context = new CloudSessionContext();
111
+ context.allocationRequestId = randomUUID();
112
+ context.clientRequestId = randomUUID();
113
+ context.cloudSessionId = randomUUID();
114
+ context.userId = randomUUID();
115
+ context.gameId = randomUUID();
116
+ context.ludeoId = "invalid-uuid";
117
+ context.poolId = randomUUID();
118
+ context.cloudProvider = CloudProvider.AWS;
119
+
120
+ const errors = await validate(context);
121
+ expect(errors.length).toBeGreaterThan(0);
122
+ expect(errors.some((err) => err.property === "ludeoId")).toBeTruthy();
123
+ });
124
+
125
+ it("should fail if poolId is not a valid UUID", async () => {
126
+ const context = new CloudSessionContext();
127
+ context.allocationRequestId = randomUUID();
128
+ context.clientRequestId = randomUUID();
129
+ context.cloudSessionId = randomUUID();
130
+ context.userId = randomUUID();
131
+ context.gameId = randomUUID();
132
+ context.ludeoId = randomUUID();
133
+ context.poolId = "invalid-uuid";
134
+ context.cloudProvider = CloudProvider.AWS;
135
+
136
+ const errors = await validate(context);
137
+ expect(errors.length).toBeGreaterThan(0);
138
+ expect(errors.some((err) => err.property === "poolId")).toBeTruthy();
139
+ });
140
+
141
+ it("should fail if cloudProvider is not a string", async () => {
142
+ const context = new CloudSessionContext();
143
+ context.allocationRequestId = randomUUID();
144
+ context.clientRequestId = randomUUID();
145
+ context.cloudSessionId = randomUUID();
146
+ context.userId = randomUUID();
147
+ context.gameId = randomUUID();
148
+ context.ludeoId = randomUUID();
149
+ context.poolId = randomUUID();
150
+ context.cloudProvider = 123 as any; // Invalid cloudProvider
151
+
152
+ const errors = await validate(context);
153
+ expect(errors.length).toBeGreaterThan(0);
154
+ expect(errors.some((err) => err.property === "cloudProvider")).toBeTruthy();
155
+ });
156
+
157
+ it("should fail if resourceId is not a valid UUID when provided", async () => {
158
+ const context = new CloudSessionContext();
159
+ context.allocationRequestId = randomUUID();
160
+ context.clientRequestId = randomUUID();
161
+ context.cloudSessionId = randomUUID();
162
+ context.userId = randomUUID();
163
+ context.gameId = randomUUID();
164
+ context.ludeoId = randomUUID();
165
+ context.poolId = randomUUID();
166
+ context.cloudProvider = CloudProvider.AWS;
167
+ context.resourceId = "invalid-uuid";
168
+
169
+ const errors = await validate(context);
170
+ expect(errors.length).toBeGreaterThan(0);
171
+ expect(errors.some((err) => err.property === "resourceId")).toBeTruthy();
172
+ });
173
+
174
+ it("should succeed when resourceId is not provided", async () => {
175
+ const context = new CloudSessionContext();
176
+ context.allocationRequestId = randomUUID();
177
+ context.clientRequestId = randomUUID();
178
+ context.cloudSessionId = randomUUID();
179
+ context.userId = randomUUID();
180
+ context.gameId = randomUUID();
181
+ context.ludeoId = randomUUID();
182
+ context.poolId = randomUUID();
183
+ context.cloudProvider = CloudProvider.AWS;
184
+
185
+ // resourceId is not set
186
+
187
+ const errors = await validate(context);
188
+ expect(errors.length).toBe(0);
189
+ });
190
+ });
@@ -14,12 +14,12 @@ export class CloudResourceCreatedPayload {
14
14
  @IsEnum(CloudProvider)
15
15
  cloudProvider: CloudProvider;
16
16
 
17
- @IsString()
17
+ @IsUUID()
18
18
  @IsOptional()
19
19
  clientRequestId?: string;
20
20
 
21
21
  @IsOptional()
22
- @IsString()
22
+ @IsUUID()
23
23
  cloudSessionId?: string;
24
24
 
25
25
  @ValidateNestedType(() => AWSCreationResponse)
package/tsconfig.json CHANGED
@@ -18,6 +18,7 @@
18
18
  "forceConsistentCasingInFileNames": false,
19
19
  "noFallthroughCasesInSwitch": false,
20
20
  "typeRoots": ["src/common/aerospike", "./node_modules/@types"],
21
+ "types": ["node", "jest"],
21
22
  "paths": {
22
23
  "*": ["src/types/*"]
23
24
  }