@moreapp/common-nodejs 0.12.2 → 0.12.4
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/dist/__tests__/MoreAppClient.test.js +85 -0
- package/dist/__tests__/dateUtil.test.js +42 -0
- package/dist/{logger.test.js → __tests__/logger.test.js} +23 -10
- package/dist/__tests__/utils.test.js +124 -0
- package/dist/dateUtil.js +38 -8
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/logger.js +2 -1
- package/dist/observability/TerminationHandler.js +5 -1
- package/dist/observability/{ExpressRequestTracker.test.js → __tests__/ExpressRequestTracker.test.js} +16 -15
- package/dist/observability/{ObservabilityServer.test.js → __tests__/ObservabilityServer.test.js} +30 -23
- package/dist/observability/__tests__/TerminationHandler.test.js +171 -0
- package/dist/observability/index.d.ts +2 -1
- package/dist/observability/index.js +3 -1
- package/dist/observability/tracer.d.ts +12 -0
- package/dist/{tracer.js → observability/tracer.js} +15 -7
- package/package.json +12 -12
- package/dist/MoreAppClient.test.js +0 -79
- package/dist/dateUtil.test.js +0 -41
- package/dist/observability/TerminationHandler.test.js +0 -160
- package/dist/testUtils.d.ts +0 -1
- package/dist/testUtils.js +0 -13
- package/dist/tracer.d.ts +0 -8
- package/dist/utils.test.js +0 -123
- /package/dist/{MoreAppClient.test.d.ts → __tests__/MoreAppClient.test.d.ts} +0 -0
- /package/dist/{dateUtil.test.d.ts → __tests__/dateUtil.test.d.ts} +0 -0
- /package/dist/{logger.test.d.ts → __tests__/logger.test.d.ts} +0 -0
- /package/dist/{utils.test.d.ts → __tests__/utils.test.d.ts} +0 -0
- /package/dist/observability/{ExpressRequestTracker.test.d.ts → __tests__/ExpressRequestTracker.test.d.ts} +0 -0
- /package/dist/observability/{ObservabilityServer.test.d.ts → __tests__/ObservabilityServer.test.d.ts} +0 -0
- /package/dist/observability/{TerminationHandler.test.d.ts → __tests__/TerminationHandler.test.d.ts} +0 -0
package/dist/utils.test.js
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const utils_1 = require("./utils");
|
|
4
|
-
describe("environmentVariable", () => {
|
|
5
|
-
test("Should throw when environment variable does not exist", () => {
|
|
6
|
-
expect(() => (0, utils_1.environmentVariable)("COMMONS_NODEJS_TEST_NON_EXISTING")).toThrow("Missing environment variable 'COMMONS_NODEJS_TEST_NON_EXISTING'");
|
|
7
|
-
});
|
|
8
|
-
test("Should return fallback value when environment variable does not exist (string)", () => {
|
|
9
|
-
expect((0, utils_1.environmentVariable)("COMMONS_NODEJS_TEST_NON_EXISTING", "my-fallback")).toBe("my-fallback");
|
|
10
|
-
});
|
|
11
|
-
test("Should return fallback value when environment variable does not exist (number)", () => {
|
|
12
|
-
expect((0, utils_1.environmentVariable)("COMMONS_NODEJS_TEST_NON_EXISTING", 1)).toBe(1);
|
|
13
|
-
});
|
|
14
|
-
test("Should return fallback value when environment variable does not exist (boolean)", () => {
|
|
15
|
-
expect((0, utils_1.environmentVariable)("COMMONS_NODEJS_TEST_NON_EXISTING", false)).toBe(false);
|
|
16
|
-
});
|
|
17
|
-
test("Should return actual value when environment variable exists (string)", () => {
|
|
18
|
-
process.env["COMMONS_NODEJS_TEST_EXISTING"] = "actual-value";
|
|
19
|
-
expect((0, utils_1.environmentVariable)("COMMONS_NODEJS_TEST_EXISTING", "my-fallback")).toBe("actual-value");
|
|
20
|
-
});
|
|
21
|
-
test("Should return actual value when environment variable exists (number)", () => {
|
|
22
|
-
process.env["COMMONS_NODEJS_TEST_EXISTING"] = "2";
|
|
23
|
-
expect((0, utils_1.environmentVariable)("COMMONS_NODEJS_TEST_EXISTING", 1)).toBe(2);
|
|
24
|
-
});
|
|
25
|
-
test("Should return actual value when environment variable exists (boolean)", () => {
|
|
26
|
-
process.env["COMMONS_NODEJS_TEST_EXISTING"] = "true";
|
|
27
|
-
expect((0, utils_1.environmentVariable)("COMMONS_NODEJS_TEST_EXISTING", false)).toBe(true);
|
|
28
|
-
});
|
|
29
|
-
test("should throw when environment variable contains an invalid type (number)", () => {
|
|
30
|
-
process.env["COMMONS_NODEJS_TEST_EXISTING"] = "not-a-number";
|
|
31
|
-
expect(() => (0, utils_1.environmentVariable)("COMMONS_NODEJS_TEST_EXISTING", 1)).toThrow("Wrong type for environment variable 'COMMONS_NODEJS_TEST_EXISTING'");
|
|
32
|
-
});
|
|
33
|
-
test("should throw when environment variable contains an invalid type (boolean)", () => {
|
|
34
|
-
process.env["COMMONS_NODEJS_TEST_EXISTING"] = "not-a-boolean";
|
|
35
|
-
expect(() => (0, utils_1.environmentVariable)("COMMONS_NODEJS_TEST_EXISTING", false)).toThrow("Wrong type for environment variable 'COMMONS_NODEJS_TEST_EXISTING'");
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
describe("isValidEmail", () => {
|
|
39
|
-
describe("Valid email addresses", () => {
|
|
40
|
-
test("Standard email address", () => expect((0, utils_1.isValidEmail)("a@moreapp.dev")).toBeTruthy());
|
|
41
|
-
test("Non-alphanumeric characters", () => expect((0, utils_1.isValidEmail)("a+-._&%'@moreapp.dev")).toBeTruthy());
|
|
42
|
-
test("Shortest email address", () => expect((0, utils_1.isValidEmail)("a@b.co")).toBeTruthy());
|
|
43
|
-
test("Subdomain", () => expect((0, utils_1.isValidEmail)("a@sub.domain.dev")).toBeTruthy());
|
|
44
|
-
test("Subdomain with a dash", () => expect((0, utils_1.isValidEmail)("a@sub.dom-ain.dev")).toBeTruthy());
|
|
45
|
-
test("Long TLD", () => expect((0, utils_1.isValidEmail)("a@b.business")).toBeTruthy());
|
|
46
|
-
test("Diacritics", () => expect((0, utils_1.isValidEmail)("ẞçäöü@möręæppß.dev")).toBeTruthy());
|
|
47
|
-
test("Casing", () => expect((0, utils_1.isValidEmail)("TØmÂs@mŒREÄPp.cOm")).toBeTruthy());
|
|
48
|
-
});
|
|
49
|
-
describe("Invalid email addresses", () => {
|
|
50
|
-
test("Missing '@' character and domain", () => expect((0, utils_1.isValidEmail)("john")).toBeFalsy());
|
|
51
|
-
test("Multiple '@' characters", () => expect((0, utils_1.isValidEmail)("a@b@moreapp.dev")).toBeFalsy());
|
|
52
|
-
test("Ends with a '@' character", () => expect((0, utils_1.isValidEmail)("a@moreapp.dev@")).toBeFalsy());
|
|
53
|
-
test("Empty", () => expect((0, utils_1.isValidEmail)("")).toBeFalsy());
|
|
54
|
-
test("Whitespace before/after", () => expect((0, utils_1.isValidEmail)(" a@moreapp.dev ")).toBeFalsy());
|
|
55
|
-
test("Newlines, tabs, ..., before/after", () => expect((0, utils_1.isValidEmail)("\n \ta@moreapp.dev\n ")).toBeFalsy());
|
|
56
|
-
test("Missing '@' character", () => expect((0, utils_1.isValidEmail)("ab.com")).toBeFalsy());
|
|
57
|
-
test("Double dot in domain", () => expect((0, utils_1.isValidEmail)("a@moreapp..com")).toBeFalsy());
|
|
58
|
-
test("Too short TLD", () => expect((0, utils_1.isValidEmail)("a@b.c")).toBeFalsy());
|
|
59
|
-
test("Missing local part", () => expect((0, utils_1.isValidEmail)("@moreapp.dev")).toBeFalsy());
|
|
60
|
-
test("Too long", () => expect((0, utils_1.isValidEmail)("abcdefghijklmnopqrstuvwxyz-abcdefghijklmnopqrstuvwxyz-abcdefghijklmnopqrstuvwxyz-abcdefghijklmnopqrstuvwxyz-abcdefghijklmnopqrstuvwxyz-abcdefghijklmnopqrstuvwxyz-abcdefghijklmnopqrstuvwxyz-abcdefghijklmnopqrstuvwxyz-abcdefghijklmnopqrstuvwxyz-@moreapp.dev")).toBeFalsy());
|
|
61
|
-
test("Starts with '.'", () => expect((0, utils_1.isValidEmail)(".a@moreapp.dev")).toBeFalsy());
|
|
62
|
-
test("Ends with a '.'", () => expect((0, utils_1.isValidEmail)("a.@moreapp.dev")).toBeFalsy());
|
|
63
|
-
test("Local part contains whitespace", () => expect((0, utils_1.isValidEmail)("a b@moreapp.dev")).toBeFalsy());
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
describe("parseDynamicRecipients", () => {
|
|
67
|
-
test("should parse all type of data (root, object, array)", () => {
|
|
68
|
-
const fields = [
|
|
69
|
-
{ uid: "UID-root", properties: { data_name: "customer" } },
|
|
70
|
-
{ uid: "UID-object", properties: { data_name: "vendor" } },
|
|
71
|
-
{ uid: "UID-array", properties: { data_name: "contacts" } },
|
|
72
|
-
];
|
|
73
|
-
expect((0, utils_1.parseDynamicRecipients)(["UID-root", "UID-object.email", "UID-array"], fields, {
|
|
74
|
-
customer: "customer@example.com",
|
|
75
|
-
vendor: { id: 1, email: "vendor@example.com" },
|
|
76
|
-
contacts: ["contact1@example.com", "contact2@example.com"],
|
|
77
|
-
})).toEqual([
|
|
78
|
-
"customer@example.com",
|
|
79
|
-
"vendor@example.com",
|
|
80
|
-
"contact1@example.com",
|
|
81
|
-
"contact2@example.com",
|
|
82
|
-
]);
|
|
83
|
-
});
|
|
84
|
-
test("should skip invalid emails", () => {
|
|
85
|
-
const fields = [
|
|
86
|
-
{ uid: "UID-root", properties: { data_name: "customer" } },
|
|
87
|
-
{ uid: "UID-object", properties: { data_name: "vendor" } },
|
|
88
|
-
{ uid: "UID-array", properties: { data_name: "contacts" } },
|
|
89
|
-
];
|
|
90
|
-
expect((0, utils_1.parseDynamicRecipients)(["UID-root", "UID-object.email", "UID-array"], fields, {
|
|
91
|
-
customer: "invalid1",
|
|
92
|
-
vendor: { id: 1, email: "invalid2" },
|
|
93
|
-
contacts: ["invalid3", "invalid4"],
|
|
94
|
-
})).toEqual([]);
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
describe("getDataForDataName", () => {
|
|
98
|
-
test("should return (nested) values in objects based on dataName", () => {
|
|
99
|
-
const data = {
|
|
100
|
-
name: "John",
|
|
101
|
-
age: 10,
|
|
102
|
-
address: {
|
|
103
|
-
street: "Main Street",
|
|
104
|
-
city: "New York",
|
|
105
|
-
location: {
|
|
106
|
-
longitude: 10,
|
|
107
|
-
latitude: 10,
|
|
108
|
-
},
|
|
109
|
-
},
|
|
110
|
-
"flat.test": "hi",
|
|
111
|
-
};
|
|
112
|
-
expect((0, utils_1.getDataForDataName)(data, "name")).toBe("John");
|
|
113
|
-
expect((0, utils_1.getDataForDataName)(data, "age")).toBe(10);
|
|
114
|
-
expect((0, utils_1.getDataForDataName)(data, "address.city")).toBe("New York");
|
|
115
|
-
expect((0, utils_1.getDataForDataName)(data, "address.location.longitude")).toBe(10);
|
|
116
|
-
expect((0, utils_1.getDataForDataName)(data, "flat.test")).toBe("hi");
|
|
117
|
-
expect((0, utils_1.getDataForDataName)(data, "unknown")).toBe(undefined);
|
|
118
|
-
expect((0, utils_1.getDataForDataName)(data, "unknown.nested")).toBe(undefined);
|
|
119
|
-
expect((0, utils_1.getDataForDataName)(data, "address.unknown")).toBe(undefined);
|
|
120
|
-
expect((0, utils_1.getDataForDataName)(data, "flat..")).toBe(undefined);
|
|
121
|
-
expect((0, utils_1.getDataForDataName)(data, ".")).toBe(undefined);
|
|
122
|
-
});
|
|
123
|
-
});
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/dist/observability/{TerminationHandler.test.d.ts → __tests__/TerminationHandler.test.d.ts}
RENAMED
|
File without changes
|