@applicaster/zapp-react-native-utils 15.0.0-rc.94 → 15.0.0-rc.96
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/adsUtils/__tests__/createVMAP.test.ts +419 -0
- package/appDataUtils/__tests__/urlScheme.test.ts +678 -0
- package/appUtils/HooksManager/__tests__/__snapshots__/hooksManager.test.js.snap +0 -188
- package/appUtils/HooksManager/__tests__/hooksManager.test.js +16 -2
- package/cloudEventsUtils/__tests__/index.test.ts +529 -0
- package/cloudEventsUtils/index.ts +65 -1
- package/dateUtils/__tests__/dayjs.test.ts +330 -0
- package/enumUtils/__tests__/getEnumKeyByEnumValue.test.ts +207 -0
- package/errorUtils/__tests__/GeneralError.test.ts +97 -0
- package/errorUtils/__tests__/HttpStatusCode.test.ts +344 -0
- package/errorUtils/__tests__/MissingPluginError.test.ts +113 -0
- package/errorUtils/__tests__/NetworkError.test.ts +202 -0
- package/errorUtils/__tests__/getParsedResponse.test.ts +188 -0
- package/errorUtils/__tests__/invariant.test.ts +112 -0
- package/package.json +2 -2
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { getParsedResponse } from "../index";
|
|
2
|
+
import { RESPONSES } from "../errorCodes";
|
|
3
|
+
|
|
4
|
+
describe("getParsedResponse", () => {
|
|
5
|
+
it("should parse error with response status code from response.data", () => {
|
|
6
|
+
const err = {
|
|
7
|
+
response: {
|
|
8
|
+
data: {
|
|
9
|
+
statusCode: 404,
|
|
10
|
+
message: "Resource not found",
|
|
11
|
+
},
|
|
12
|
+
config: {
|
|
13
|
+
url: "https://api.example.com/data",
|
|
14
|
+
params: { id: 123 },
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
name: "AxiosError",
|
|
18
|
+
context: { userId: "user123" },
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const result = getParsedResponse(err);
|
|
22
|
+
|
|
23
|
+
expect(result.message).toBe("Error: Resource not found");
|
|
24
|
+
expect(result.data.statusCode).toBe("404");
|
|
25
|
+
expect(result.data.url).toBe("https://api.example.com/data");
|
|
26
|
+
expect(result.data.params).toEqual({ id: 123 });
|
|
27
|
+
expect(result.data.context).toEqual({ userId: "user123" });
|
|
28
|
+
expect(result.data.name).toBe("AxiosError");
|
|
29
|
+
expect(result.jsOnly).toBe(false);
|
|
30
|
+
expect(result.exception).toBe(result.message);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("should parse error with response status code from response.status", () => {
|
|
34
|
+
const err = {
|
|
35
|
+
response: {
|
|
36
|
+
status: 500,
|
|
37
|
+
config: {
|
|
38
|
+
url: "https://api.example.com/data",
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const result = getParsedResponse(err);
|
|
44
|
+
|
|
45
|
+
expect(result.message).toBe(`Error: ${RESPONSES[500]}`);
|
|
46
|
+
expect(result.data.statusCode).toBe("500");
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("should handle error with request but no response", () => {
|
|
50
|
+
const err = {
|
|
51
|
+
request: {},
|
|
52
|
+
message: "Network timeout",
|
|
53
|
+
config: {
|
|
54
|
+
url: "https://api.example.com/data",
|
|
55
|
+
params: { test: "value" },
|
|
56
|
+
},
|
|
57
|
+
name: "NetworkError",
|
|
58
|
+
context: { app: "test" },
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const result = getParsedResponse(err);
|
|
62
|
+
|
|
63
|
+
expect(result.message).toBe("Error: Network timeout");
|
|
64
|
+
expect(result.data.url).toBe("https://api.example.com/data");
|
|
65
|
+
expect(result.data.params).toEqual({ test: "value" });
|
|
66
|
+
expect(result.data.name).toBe("NetworkError");
|
|
67
|
+
expect(result.data.context).toEqual({ app: "test" });
|
|
68
|
+
expect(result.jsOnly).toBe(false);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("should handle error with request but no response and no message", () => {
|
|
72
|
+
const err = {
|
|
73
|
+
request: {},
|
|
74
|
+
config: {
|
|
75
|
+
url: "https://api.example.com/data",
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const result = getParsedResponse(err);
|
|
80
|
+
|
|
81
|
+
expect(result.message).toBe(`Error: ${RESPONSES.noResponse}`);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("should handle error with neither response nor request", () => {
|
|
85
|
+
const err = {
|
|
86
|
+
message: "Failed to set up request",
|
|
87
|
+
config: {
|
|
88
|
+
url: "https://api.example.com/data",
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const result = getParsedResponse(err);
|
|
93
|
+
|
|
94
|
+
expect(result.message).toBe("Error: Failed to set up request");
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("should handle error with neither response nor request and no message", () => {
|
|
98
|
+
const err = {
|
|
99
|
+
config: {
|
|
100
|
+
url: "https://api.example.com/data",
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const result = getParsedResponse(err);
|
|
105
|
+
|
|
106
|
+
expect(result.message).toBe(`Error: ${RESPONSES.unknown}`);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("should handle null error", () => {
|
|
110
|
+
const err = null;
|
|
111
|
+
|
|
112
|
+
const result = getParsedResponse(err);
|
|
113
|
+
|
|
114
|
+
expect(result.message).toBe(`Error: ${RESPONSES.unknown}`);
|
|
115
|
+
|
|
116
|
+
expect(result.data).toEqual({
|
|
117
|
+
context: undefined,
|
|
118
|
+
name: undefined,
|
|
119
|
+
params: undefined,
|
|
120
|
+
url: undefined,
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("should handle undefined error", () => {
|
|
125
|
+
const err = undefined;
|
|
126
|
+
|
|
127
|
+
const result = getParsedResponse(err);
|
|
128
|
+
|
|
129
|
+
expect(result.message).toBe(`Error: ${RESPONSES.unknown}`);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it("should extract params from err.config when response is not present", () => {
|
|
133
|
+
const err = {
|
|
134
|
+
request: {},
|
|
135
|
+
message: "Request failed",
|
|
136
|
+
config: {
|
|
137
|
+
url: "https://api.example.com/data",
|
|
138
|
+
params: { key: "value" },
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const result = getParsedResponse(err);
|
|
143
|
+
|
|
144
|
+
expect(result.data.params).toEqual({ key: "value" });
|
|
145
|
+
expect(result.data.url).toBe("https://api.example.com/data");
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it("should prioritize response config over error config", () => {
|
|
149
|
+
const err = {
|
|
150
|
+
response: {
|
|
151
|
+
status: 404,
|
|
152
|
+
config: {
|
|
153
|
+
url: "https://api.example.com/response-url",
|
|
154
|
+
params: { from: "response" },
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
config: {
|
|
158
|
+
url: "https://api.example.com/error-url",
|
|
159
|
+
params: { from: "error" },
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const result = getParsedResponse(err);
|
|
164
|
+
|
|
165
|
+
expect(result.data.url).toBe("https://api.example.com/response-url");
|
|
166
|
+
expect(result.data.params).toEqual({ from: "response" });
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it("should handle response with custom status codes", () => {
|
|
170
|
+
const err = {
|
|
171
|
+
response: {
|
|
172
|
+
data: {
|
|
173
|
+
statusCode: 418,
|
|
174
|
+
message: "I'm a teapot",
|
|
175
|
+
},
|
|
176
|
+
status: 418,
|
|
177
|
+
config: {
|
|
178
|
+
url: "https://api.example.com/coffee",
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
const result = getParsedResponse(err);
|
|
184
|
+
|
|
185
|
+
expect(result.message).toBe("Error: I'm a teapot");
|
|
186
|
+
expect(result.data.statusCode).toBe("418");
|
|
187
|
+
});
|
|
188
|
+
});
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { invariant } from "../index";
|
|
2
|
+
|
|
3
|
+
// Mock __DEV__ global
|
|
4
|
+
declare global {
|
|
5
|
+
var __DEV__: boolean;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
describe("invariant", () => {
|
|
9
|
+
const originalDev = global.__DEV__;
|
|
10
|
+
|
|
11
|
+
afterEach(() => {
|
|
12
|
+
global.__DEV__ = originalDev;
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
describe("in development mode", () => {
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
global.__DEV__ = true;
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("should not throw when condition is true", () => {
|
|
21
|
+
expect(() => {
|
|
22
|
+
invariant(true, "This should not throw");
|
|
23
|
+
}).not.toThrow();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("should throw when condition is false", () => {
|
|
27
|
+
expect(() => {
|
|
28
|
+
invariant(false, "This should throw");
|
|
29
|
+
}).toThrow("This should throw");
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("should throw with correct error message", () => {
|
|
33
|
+
const errorMessage = "Custom error message";
|
|
34
|
+
|
|
35
|
+
expect(() => {
|
|
36
|
+
invariant(false, errorMessage);
|
|
37
|
+
}).toThrow(errorMessage);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("should not throw when condition is truthy value", () => {
|
|
41
|
+
expect(() => {
|
|
42
|
+
invariant(1 as any, "Should not throw");
|
|
43
|
+
}).not.toThrow();
|
|
44
|
+
|
|
45
|
+
expect(() => {
|
|
46
|
+
invariant("string" as any, "Should not throw");
|
|
47
|
+
}).not.toThrow();
|
|
48
|
+
|
|
49
|
+
expect(() => {
|
|
50
|
+
invariant({} as any, "Should not throw");
|
|
51
|
+
}).not.toThrow();
|
|
52
|
+
|
|
53
|
+
expect(() => {
|
|
54
|
+
invariant([] as any, "Should not throw");
|
|
55
|
+
}).not.toThrow();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("should throw when condition is falsy value", () => {
|
|
59
|
+
expect(() => {
|
|
60
|
+
invariant(0 as any, "Should throw for 0");
|
|
61
|
+
}).toThrow("Should throw for 0");
|
|
62
|
+
|
|
63
|
+
expect(() => {
|
|
64
|
+
invariant("" as any, "Should throw for empty string");
|
|
65
|
+
}).toThrow("Should throw for empty string");
|
|
66
|
+
|
|
67
|
+
expect(() => {
|
|
68
|
+
invariant(null as any, "Should throw for null");
|
|
69
|
+
}).toThrow("Should throw for null");
|
|
70
|
+
|
|
71
|
+
expect(() => {
|
|
72
|
+
invariant(undefined as any, "Should throw for undefined");
|
|
73
|
+
}).toThrow("Should throw for undefined");
|
|
74
|
+
|
|
75
|
+
expect(() => {
|
|
76
|
+
invariant(NaN as any, "Should throw for NaN");
|
|
77
|
+
}).toThrow("Should throw for NaN");
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
describe("in production mode", () => {
|
|
82
|
+
beforeEach(() => {
|
|
83
|
+
global.__DEV__ = false;
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("should not throw when condition is true", () => {
|
|
87
|
+
expect(() => {
|
|
88
|
+
invariant(true, "This should not throw");
|
|
89
|
+
}).not.toThrow();
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("should not throw when condition is false", () => {
|
|
93
|
+
expect(() => {
|
|
94
|
+
invariant(false, "This should not throw in production");
|
|
95
|
+
}).not.toThrow();
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("should not throw for any condition", () => {
|
|
99
|
+
expect(() => {
|
|
100
|
+
invariant(0 as any, "Should not throw in production");
|
|
101
|
+
}).not.toThrow();
|
|
102
|
+
|
|
103
|
+
expect(() => {
|
|
104
|
+
invariant(null as any, "Should not throw in production");
|
|
105
|
+
}).not.toThrow();
|
|
106
|
+
|
|
107
|
+
expect(() => {
|
|
108
|
+
invariant(undefined as any, "Should not throw in production");
|
|
109
|
+
}).not.toThrow();
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/zapp-react-native-utils",
|
|
3
|
-
"version": "15.0.0-rc.
|
|
3
|
+
"version": "15.0.0-rc.96",
|
|
4
4
|
"description": "Applicaster Zapp React Native utilities package",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"homepage": "https://github.com/applicaster/quickbrick#readme",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@applicaster/applicaster-types": "15.0.0-rc.
|
|
30
|
+
"@applicaster/applicaster-types": "15.0.0-rc.96",
|
|
31
31
|
"buffer": "^5.2.1",
|
|
32
32
|
"camelize": "^1.0.0",
|
|
33
33
|
"dayjs": "^1.11.10",
|