@open-dpp/dto 2.7.0 → 2.9.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/dist/aas/asset-administration-shell-json-schema.d.ts +1 -0
- package/dist/aas/asset-administration-shell-json-schema.d.ts.map +1 -1
- package/dist/aas/submodel-base/create-group-from-column-schema.d.ts +61 -0
- package/dist/aas/submodel-base/create-group-from-column-schema.d.ts.map +1 -0
- package/dist/aas/submodel-base/create-group-from-column-schema.js +9 -0
- package/dist/aas/submodel-base/submodel-element-schema.d.ts +1 -0
- package/dist/aas/submodel-base/submodel-element-schema.d.ts.map +1 -1
- package/dist/aas/submodel-base/submodel-json-schema.d.ts +1 -0
- package/dist/aas/submodel-base/submodel-json-schema.d.ts.map +1 -1
- package/dist/activity-history/activity-history.dto.d.ts +48 -28
- package/dist/activity-history/activity-history.dto.d.ts.map +1 -1
- package/dist/activity-history/activity-types.dto.d.ts +10 -8
- package/dist/activity-history/activity-types.dto.d.ts.map +1 -1
- package/dist/activity-history/activity-types.dto.js +5 -4
- package/dist/activity-history/change-event-types.dto.d.ts +8 -0
- package/dist/activity-history/change-event-types.dto.d.ts.map +1 -1
- package/dist/activity-history/change-event-types.dto.js +4 -0
- package/dist/digital-product-document/digital-product-document.dto.d.ts +11 -0
- package/dist/digital-product-document/digital-product-document.dto.d.ts.map +1 -0
- package/dist/digital-product-document/digital-product-document.dto.js +9 -0
- package/dist/digital-product-document/digital-product-document.schemas.d.ts.map +1 -0
- package/dist/index.d.ts +15 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -1
- package/dist/organizations/member.dto.d.ts +8 -2
- package/dist/organizations/member.dto.d.ts.map +1 -1
- package/dist/organizations/member.dto.js +7 -1
- package/dist/passports/passport.dto.d.ts +1 -0
- package/dist/passports/passport.dto.d.ts.map +1 -1
- package/dist/passports/passport.dto.js +1 -1
- package/dist/permalinks/permalink.dto.js +1 -1
- package/dist/presentation-configurations/presentation-configuration.dto.d.ts +0 -9
- package/dist/presentation-configurations/presentation-configuration.dto.d.ts.map +1 -1
- package/dist/presentation-configurations/presentation-configuration.dto.js +5 -9
- package/dist/shared/filter.dto.js +1 -1
- package/dist/shared/pagination.dto.d.ts +1 -0
- package/dist/shared/pagination.dto.d.ts.map +1 -1
- package/dist/shared/pagination.dto.js +3 -0
- package/dist/templates/template.dto.d.ts +1 -0
- package/dist/templates/template.dto.d.ts.map +1 -1
- package/dist/templates/template.dto.js +1 -1
- package/dist/unique-product-identifiers/gs1/gs1-ai-constants.d.ts +574 -0
- package/dist/unique-product-identifiers/gs1/gs1-ai-constants.d.ts.map +1 -0
- package/dist/unique-product-identifiers/gs1/gs1-ai-constants.js +570 -0
- package/dist/unique-product-identifiers/gs1/gs1-ai-description.d.ts +15 -0
- package/dist/unique-product-identifiers/gs1/gs1-ai-description.d.ts.map +1 -0
- package/dist/unique-product-identifiers/gs1/gs1-ai-description.js +47 -0
- package/dist/unique-product-identifiers/gs1/gs1-ai-i18n.d.ts +27 -0
- package/dist/unique-product-identifiers/gs1/gs1-ai-i18n.d.ts.map +1 -0
- package/dist/unique-product-identifiers/gs1/gs1-ai-i18n.js +523 -0
- package/dist/unique-product-identifiers/gs1/gs1-ai-table.d.ts +47 -0
- package/dist/unique-product-identifiers/gs1/gs1-ai-table.d.ts.map +1 -0
- package/dist/unique-product-identifiers/gs1/gs1-ai-table.js +4363 -0
- package/dist/unique-product-identifiers/gs1/gs1-data-attributes.dto.d.ts +540 -0
- package/dist/unique-product-identifiers/gs1/gs1-data-attributes.dto.d.ts.map +1 -0
- package/dist/unique-product-identifiers/gs1/gs1-data-attributes.dto.js +62 -0
- package/dist/unique-product-identifiers/gs1/gs1-digital-link.d.ts +158 -0
- package/dist/unique-product-identifiers/gs1/gs1-digital-link.d.ts.map +1 -0
- package/dist/unique-product-identifiers/gs1/gs1-digital-link.js +321 -0
- package/dist/unique-product-identifiers/gs1/gs1-identity.dto.d.ts +39 -0
- package/dist/unique-product-identifiers/gs1/gs1-identity.dto.d.ts.map +1 -0
- package/dist/unique-product-identifiers/gs1/gs1-identity.dto.js +40 -0
- package/dist/unique-product-identifiers/unique-product-identifier-type.d.ts +36 -0
- package/dist/unique-product-identifiers/unique-product-identifier-type.d.ts.map +1 -0
- package/dist/unique-product-identifiers/unique-product-identifier-type.js +27 -0
- package/dist/users/create-user.dto.d.ts +2 -2
- package/dist/users/create-user.dto.js +2 -2
- package/dist/users/me.dto.d.ts +24 -0
- package/dist/users/me.dto.d.ts.map +1 -0
- package/dist/users/me.dto.js +10 -0
- package/dist/users/pending-email-change.dto.d.ts +7 -0
- package/dist/users/pending-email-change.dto.d.ts.map +1 -0
- package/dist/users/pending-email-change.dto.js +8 -0
- package/dist/users/request-email-change.dto.d.ts +7 -0
- package/dist/users/request-email-change.dto.d.ts.map +1 -0
- package/dist/users/request-email-change.dto.js +8 -0
- package/dist/users/update-profile.dto.d.ts +11 -0
- package/dist/users/update-profile.dto.d.ts.map +1 -0
- package/dist/users/update-profile.dto.js +12 -0
- package/dist/users/user.dto.d.ts +16 -9
- package/dist/users/user.dto.d.ts.map +1 -1
- package/dist/users/user.dto.js +14 -1
- package/package.json +7 -5
- package/src/aas/submodel-base/create-group-from-column-schema.ts +9 -0
- package/src/activity-history/activity-types.dto.ts +5 -4
- package/src/activity-history/change-event-types.dto.ts +4 -0
- package/src/digital-product-document/digital-product-document.dto.ts +8 -0
- package/src/index.ts +15 -1
- package/src/organizations/member.dto.ts +11 -2
- package/src/passports/passport.dto.ts +1 -1
- package/src/permalinks/permalink.dto.ts +1 -1
- package/src/presentation-configurations/presentation-configuration.dto.spec.ts +2 -2
- package/src/presentation-configurations/presentation-configuration.dto.ts +4 -11
- package/src/shared/filter.dto.ts +1 -1
- package/src/shared/pagination.dto.ts +3 -0
- package/src/templates/template.dto.ts +1 -1
- package/src/unique-product-identifiers/gs1/gs1-ai-constants.spec.ts +99 -0
- package/src/unique-product-identifiers/gs1/gs1-ai-constants.ts +581 -0
- package/src/unique-product-identifiers/gs1/gs1-ai-description.spec.ts +64 -0
- package/src/unique-product-identifiers/gs1/gs1-ai-description.ts +47 -0
- package/src/unique-product-identifiers/gs1/gs1-ai-i18n.ts +530 -0
- package/src/unique-product-identifiers/gs1/gs1-ai-table.spec.ts +86 -0
- package/src/unique-product-identifiers/gs1/gs1-ai-table.ts +4389 -0
- package/src/unique-product-identifiers/gs1/gs1-data-attributes.dto.spec.ts +28 -0
- package/src/unique-product-identifiers/gs1/gs1-data-attributes.dto.ts +67 -0
- package/src/unique-product-identifiers/gs1/gs1-digital-link.spec.ts +126 -0
- package/src/unique-product-identifiers/gs1/gs1-digital-link.ts +368 -0
- package/src/unique-product-identifiers/gs1/gs1-identity.dto.ts +51 -0
- package/src/unique-product-identifiers/unique-product-identifier-type.ts +31 -0
- package/src/users/create-user.dto.spec.ts +80 -0
- package/src/users/create-user.dto.ts +2 -2
- package/src/users/me.dto.spec.ts +76 -0
- package/src/users/me.dto.ts +10 -0
- package/src/users/pending-email-change.dto.spec.ts +47 -0
- package/src/users/pending-email-change.dto.ts +8 -0
- package/src/users/request-email-change.dto.spec.ts +60 -0
- package/src/users/request-email-change.dto.ts +8 -0
- package/src/users/update-profile.dto.spec.ts +93 -0
- package/src/users/update-profile.dto.ts +12 -0
- package/src/users/user.dto.spec.ts +70 -0
- package/src/users/user.dto.ts +15 -9
- package/dist/shared/digital-product-document.schemas.d.ts.map +0 -1
- /package/dist/{shared → digital-product-document}/digital-product-document.schemas.d.ts +0 -0
- /package/dist/{shared → digital-product-document}/digital-product-document.schemas.js +0 -0
- /package/src/{shared → digital-product-document}/digital-product-document.schemas.ts +0 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { expect } from "@jest/globals";
|
|
2
|
+
import { CreateUserDtoSchema } from "./create-user.dto";
|
|
3
|
+
|
|
4
|
+
const validInput = {
|
|
5
|
+
email: "jane@example.com",
|
|
6
|
+
firstName: "Jane",
|
|
7
|
+
lastName: "Doe",
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
describe("CreateUserDtoSchema", () => {
|
|
11
|
+
it("parses a valid input", () => {
|
|
12
|
+
const result = CreateUserDtoSchema.safeParse(validInput);
|
|
13
|
+
expect(result.success).toBe(true);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("accepts an empty firstName (names are optional for admin invites)", () => {
|
|
17
|
+
const result = CreateUserDtoSchema.safeParse({ ...validInput, firstName: "" });
|
|
18
|
+
expect(result.success).toBe(true);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("rejects a firstName longer than 100 characters", () => {
|
|
22
|
+
const result = CreateUserDtoSchema.safeParse({ ...validInput, firstName: "a".repeat(101) });
|
|
23
|
+
expect(result.success).toBe(false);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("accepts a whitespace-only firstName and trims it to an empty string", () => {
|
|
27
|
+
const parsed = CreateUserDtoSchema.parse({ ...validInput, firstName: " " });
|
|
28
|
+
expect(parsed.firstName).toBe("");
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("accepts a firstName of exactly 100 characters", () => {
|
|
32
|
+
const result = CreateUserDtoSchema.safeParse({ ...validInput, firstName: "a".repeat(100) });
|
|
33
|
+
expect(result.success).toBe(true);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("trims surrounding whitespace from firstName", () => {
|
|
37
|
+
const parsed = CreateUserDtoSchema.parse({ ...validInput, firstName: " Florian " });
|
|
38
|
+
expect(parsed.firstName).toBe("Florian");
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("accepts an empty lastName (names are optional for admin invites)", () => {
|
|
42
|
+
const result = CreateUserDtoSchema.safeParse({ ...validInput, lastName: "" });
|
|
43
|
+
expect(result.success).toBe(true);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("rejects a lastName longer than 100 characters", () => {
|
|
47
|
+
const result = CreateUserDtoSchema.safeParse({ ...validInput, lastName: "a".repeat(101) });
|
|
48
|
+
expect(result.success).toBe(false);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("accepts a whitespace-only lastName and trims it to an empty string", () => {
|
|
52
|
+
const parsed = CreateUserDtoSchema.parse({ ...validInput, lastName: " " });
|
|
53
|
+
expect(parsed.lastName).toBe("");
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("accepts a lastName of exactly 100 characters", () => {
|
|
57
|
+
const result = CreateUserDtoSchema.safeParse({ ...validInput, lastName: "a".repeat(100) });
|
|
58
|
+
expect(result.success).toBe(true);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("trims surrounding whitespace from lastName", () => {
|
|
62
|
+
const parsed = CreateUserDtoSchema.parse({ ...validInput, lastName: " Bieck " });
|
|
63
|
+
expect(parsed.lastName).toBe("Bieck");
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("accepts input with only an email (names omitted)", () => {
|
|
67
|
+
const result = CreateUserDtoSchema.safeParse({ email: "jane@example.com" });
|
|
68
|
+
expect(result.success).toBe(true);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("rejects an invalid email", () => {
|
|
72
|
+
const result = CreateUserDtoSchema.safeParse({ ...validInput, email: "not-an-email" });
|
|
73
|
+
expect(result.success).toBe(false);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("rejects a missing field", () => {
|
|
77
|
+
const result = CreateUserDtoSchema.safeParse({ firstName: "Jane", lastName: "Doe" });
|
|
78
|
+
expect(result.success).toBe(false);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
@@ -2,8 +2,8 @@ import { z } from "zod";
|
|
|
2
2
|
|
|
3
3
|
export const CreateUserDtoSchema = z.object({
|
|
4
4
|
email: z.email(),
|
|
5
|
-
firstName: z.string(),
|
|
6
|
-
lastName: z.string(),
|
|
5
|
+
firstName: z.string().trim().max(100).optional(),
|
|
6
|
+
lastName: z.string().trim().max(100).optional(),
|
|
7
7
|
});
|
|
8
8
|
|
|
9
9
|
export type CreateUserDto = z.infer<typeof CreateUserDtoSchema>;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { expect } from "@jest/globals";
|
|
2
|
+
import { Language } from "../aas/enums/language-enum";
|
|
3
|
+
import { MeDtoSchema } from "./me.dto";
|
|
4
|
+
|
|
5
|
+
const validUser = {
|
|
6
|
+
id: "user-1",
|
|
7
|
+
email: "u@example.com",
|
|
8
|
+
firstName: "U",
|
|
9
|
+
lastName: "Ser",
|
|
10
|
+
name: "U Ser",
|
|
11
|
+
image: null,
|
|
12
|
+
emailVerified: true,
|
|
13
|
+
preferredLanguage: Language.en,
|
|
14
|
+
createdAt: "2026-05-02T10:00:00Z",
|
|
15
|
+
updatedAt: "2026-05-02T10:00:00Z",
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
describe("MeDtoSchema", () => {
|
|
19
|
+
it("parses a response with no pending change", () => {
|
|
20
|
+
const parsed = MeDtoSchema.parse({
|
|
21
|
+
user: {
|
|
22
|
+
id: "user-1",
|
|
23
|
+
email: "u@example.com",
|
|
24
|
+
firstName: "U",
|
|
25
|
+
lastName: "Ser",
|
|
26
|
+
name: "U Ser",
|
|
27
|
+
image: null,
|
|
28
|
+
emailVerified: true,
|
|
29
|
+
preferredLanguage: Language.en,
|
|
30
|
+
createdAt: "2026-05-02T10:00:00Z",
|
|
31
|
+
updatedAt: "2026-05-02T10:00:00Z",
|
|
32
|
+
},
|
|
33
|
+
pendingEmailChange: null,
|
|
34
|
+
});
|
|
35
|
+
expect(parsed.pendingEmailChange).toBeNull();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("parses a response with a pending change", () => {
|
|
39
|
+
const parsed = MeDtoSchema.parse({
|
|
40
|
+
user: {
|
|
41
|
+
id: "user-1",
|
|
42
|
+
email: "u@example.com",
|
|
43
|
+
firstName: "U",
|
|
44
|
+
lastName: "Ser",
|
|
45
|
+
name: "U Ser",
|
|
46
|
+
image: null,
|
|
47
|
+
emailVerified: true,
|
|
48
|
+
preferredLanguage: Language.en,
|
|
49
|
+
createdAt: "2026-05-02T10:00:00Z",
|
|
50
|
+
updatedAt: "2026-05-02T10:00:00Z",
|
|
51
|
+
},
|
|
52
|
+
pendingEmailChange: {
|
|
53
|
+
newEmail: "new@example.com",
|
|
54
|
+
requestedAt: "2026-05-02T11:00:00Z",
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
expect(parsed.pendingEmailChange?.newEmail).toBe("new@example.com");
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("rejects a response missing the user", () => {
|
|
61
|
+
expect(() => MeDtoSchema.parse({ pendingEmailChange: null })).toThrow();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("rejects a response missing the pendingEmailChange key (nullable is not optional)", () => {
|
|
65
|
+
expect(() => MeDtoSchema.parse({ user: validUser })).toThrow();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("rejects a response with an invalid nested user email", () => {
|
|
69
|
+
expect(() =>
|
|
70
|
+
MeDtoSchema.parse({
|
|
71
|
+
user: { ...validUser, email: "bad" },
|
|
72
|
+
pendingEmailChange: null,
|
|
73
|
+
}),
|
|
74
|
+
).toThrow();
|
|
75
|
+
});
|
|
76
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { PendingEmailChangeDtoSchema } from "./pending-email-change.dto";
|
|
3
|
+
import { UserDtoSchema } from "./user.dto";
|
|
4
|
+
|
|
5
|
+
export const MeDtoSchema = z.object({
|
|
6
|
+
user: UserDtoSchema,
|
|
7
|
+
pendingEmailChange: PendingEmailChangeDtoSchema.nullable(),
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
export type MeDto = z.infer<typeof MeDtoSchema>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { expect } from "@jest/globals";
|
|
2
|
+
import { PendingEmailChangeDtoSchema } from "./pending-email-change.dto";
|
|
3
|
+
|
|
4
|
+
describe("PendingEmailChangeDtoSchema", () => {
|
|
5
|
+
it("parses a valid pending change", () => {
|
|
6
|
+
const parsed = PendingEmailChangeDtoSchema.parse({
|
|
7
|
+
newEmail: "new@example.com",
|
|
8
|
+
requestedAt: "2026-05-02T10:00:00Z",
|
|
9
|
+
});
|
|
10
|
+
expect(parsed.newEmail).toBe("new@example.com");
|
|
11
|
+
expect(parsed.requestedAt).toBeInstanceOf(Date);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("rejects an invalid email", () => {
|
|
15
|
+
expect(() =>
|
|
16
|
+
PendingEmailChangeDtoSchema.parse({
|
|
17
|
+
newEmail: "not-an-email",
|
|
18
|
+
requestedAt: "2026-05-02T10:00:00Z",
|
|
19
|
+
}),
|
|
20
|
+
).toThrow();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("rejects a missing newEmail", () => {
|
|
24
|
+
expect(() =>
|
|
25
|
+
PendingEmailChangeDtoSchema.parse({
|
|
26
|
+
requestedAt: "2026-05-02T10:00:00Z",
|
|
27
|
+
}),
|
|
28
|
+
).toThrow();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("rejects a missing requestedAt", () => {
|
|
32
|
+
expect(() =>
|
|
33
|
+
PendingEmailChangeDtoSchema.parse({
|
|
34
|
+
newEmail: "new@example.com",
|
|
35
|
+
}),
|
|
36
|
+
).toThrow();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("rejects a requestedAt that is not a date", () => {
|
|
40
|
+
expect(() =>
|
|
41
|
+
PendingEmailChangeDtoSchema.parse({
|
|
42
|
+
newEmail: "new@example.com",
|
|
43
|
+
requestedAt: "not-a-date",
|
|
44
|
+
}),
|
|
45
|
+
).toThrow();
|
|
46
|
+
});
|
|
47
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { expect } from "@jest/globals";
|
|
2
|
+
import { RequestEmailChangeDtoSchema } from "./request-email-change.dto";
|
|
3
|
+
|
|
4
|
+
describe("RequestEmailChangeDtoSchema", () => {
|
|
5
|
+
it("parses a valid request", () => {
|
|
6
|
+
const parsed = RequestEmailChangeDtoSchema.parse({
|
|
7
|
+
newEmail: "new@example.com",
|
|
8
|
+
currentPassword: "hunter2",
|
|
9
|
+
});
|
|
10
|
+
expect(parsed.newEmail).toBe("new@example.com");
|
|
11
|
+
expect(parsed.currentPassword).toBe("hunter2");
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("normalizes the new email to lowercase", () => {
|
|
15
|
+
const parsed = RequestEmailChangeDtoSchema.parse({
|
|
16
|
+
newEmail: "John.Doe@Company.com",
|
|
17
|
+
currentPassword: "hunter2",
|
|
18
|
+
});
|
|
19
|
+
expect(parsed.newEmail).toBe("john.doe@company.com");
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("rejects missing currentPassword", () => {
|
|
23
|
+
expect(() => RequestEmailChangeDtoSchema.parse({ newEmail: "new@example.com" })).toThrow();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("rejects empty currentPassword", () => {
|
|
27
|
+
expect(() =>
|
|
28
|
+
RequestEmailChangeDtoSchema.parse({
|
|
29
|
+
newEmail: "new@example.com",
|
|
30
|
+
currentPassword: "",
|
|
31
|
+
}),
|
|
32
|
+
).toThrow();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("accepts a currentPassword at the maximum length", () => {
|
|
36
|
+
const parsed = RequestEmailChangeDtoSchema.parse({
|
|
37
|
+
newEmail: "new@example.com",
|
|
38
|
+
currentPassword: "a".repeat(1024),
|
|
39
|
+
});
|
|
40
|
+
expect(parsed.currentPassword).toBe("a".repeat(1024));
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("rejects a currentPassword longer than 1024 characters", () => {
|
|
44
|
+
expect(() =>
|
|
45
|
+
RequestEmailChangeDtoSchema.parse({
|
|
46
|
+
newEmail: "new@example.com",
|
|
47
|
+
currentPassword: "a".repeat(1025),
|
|
48
|
+
}),
|
|
49
|
+
).toThrow();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("rejects an invalid email", () => {
|
|
53
|
+
expect(() =>
|
|
54
|
+
RequestEmailChangeDtoSchema.parse({
|
|
55
|
+
newEmail: "not-an-email",
|
|
56
|
+
currentPassword: "hunter2",
|
|
57
|
+
}),
|
|
58
|
+
).toThrow();
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { expect } from "@jest/globals";
|
|
2
|
+
import { UpdateProfileDtoSchema } from "./update-profile.dto";
|
|
3
|
+
|
|
4
|
+
describe("updateProfileDto", () => {
|
|
5
|
+
it("accepts an empty object (all fields optional)", () => {
|
|
6
|
+
const result = UpdateProfileDtoSchema.safeParse({});
|
|
7
|
+
expect(result.success).toBe(true);
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it("accepts a valid firstName", () => {
|
|
11
|
+
const result = UpdateProfileDtoSchema.safeParse({ firstName: "Jane" });
|
|
12
|
+
expect(result.success).toBe(true);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("accepts an empty firstName (cleared name)", () => {
|
|
16
|
+
const result = UpdateProfileDtoSchema.safeParse({ firstName: "" });
|
|
17
|
+
expect(result.success).toBe(true);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("rejects a firstName longer than 100 characters", () => {
|
|
21
|
+
const result = UpdateProfileDtoSchema.safeParse({ firstName: "a".repeat(101) });
|
|
22
|
+
expect(result.success).toBe(false);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("accepts a firstName of exactly 100 characters", () => {
|
|
26
|
+
const result = UpdateProfileDtoSchema.safeParse({ firstName: "a".repeat(100) });
|
|
27
|
+
expect(result.success).toBe(true);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("accepts a valid lastName", () => {
|
|
31
|
+
const result = UpdateProfileDtoSchema.safeParse({ lastName: "Doe" });
|
|
32
|
+
expect(result.success).toBe(true);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("accepts an empty lastName (cleared name)", () => {
|
|
36
|
+
const result = UpdateProfileDtoSchema.safeParse({ lastName: "" });
|
|
37
|
+
expect(result.success).toBe(true);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("rejects a lastName longer than 100 characters", () => {
|
|
41
|
+
const result = UpdateProfileDtoSchema.safeParse({ lastName: "a".repeat(101) });
|
|
42
|
+
expect(result.success).toBe(false);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("accepts a lastName of exactly 100 characters", () => {
|
|
46
|
+
const result = UpdateProfileDtoSchema.safeParse({ lastName: "a".repeat(100) });
|
|
47
|
+
expect(result.success).toBe(true);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("accepts preferredLanguage 'en'", () => {
|
|
51
|
+
const result = UpdateProfileDtoSchema.safeParse({ preferredLanguage: "en" });
|
|
52
|
+
expect(result.success).toBe(true);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("accepts preferredLanguage 'de'", () => {
|
|
56
|
+
const result = UpdateProfileDtoSchema.safeParse({ preferredLanguage: "de" });
|
|
57
|
+
expect(result.success).toBe(true);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("rejects an unsupported preferredLanguage", () => {
|
|
61
|
+
const result = UpdateProfileDtoSchema.safeParse({ preferredLanguage: "fr" });
|
|
62
|
+
expect(result.success).toBe(false);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("accepts all fields together", () => {
|
|
66
|
+
const result = UpdateProfileDtoSchema.safeParse({
|
|
67
|
+
firstName: "Jane",
|
|
68
|
+
lastName: "Doe",
|
|
69
|
+
preferredLanguage: "de",
|
|
70
|
+
});
|
|
71
|
+
expect(result.success).toBe(true);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("collapses whitespace-only firstName to an empty (cleared) name", () => {
|
|
75
|
+
const parsed = UpdateProfileDtoSchema.parse({ firstName: " " });
|
|
76
|
+
expect(parsed.firstName).toBe("");
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("trims surrounding whitespace from firstName", () => {
|
|
80
|
+
const parsed = UpdateProfileDtoSchema.parse({ firstName: " Florian " });
|
|
81
|
+
expect(parsed.firstName).toBe("Florian");
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("collapses whitespace-only lastName to an empty (cleared) name", () => {
|
|
85
|
+
const parsed = UpdateProfileDtoSchema.parse({ lastName: " " });
|
|
86
|
+
expect(parsed.lastName).toBe("");
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("trims surrounding whitespace from lastName", () => {
|
|
90
|
+
const parsed = UpdateProfileDtoSchema.parse({ lastName: " Bieck " });
|
|
91
|
+
expect(parsed.lastName).toBe("Bieck");
|
|
92
|
+
});
|
|
93
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { LanguageEnum } from "../aas/enums/language-enum";
|
|
3
|
+
|
|
4
|
+
export const UpdateProfileDtoSchema = z.object({
|
|
5
|
+
// Empty string is a valid "cleared name" — admin-invited users have firstName: "".
|
|
6
|
+
// No .min(1): it would lock empty-name users out of saving any profile change.
|
|
7
|
+
firstName: z.string().trim().max(100).optional(),
|
|
8
|
+
lastName: z.string().trim().max(100).optional(),
|
|
9
|
+
preferredLanguage: LanguageEnum.optional(),
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
export type UpdateProfileDto = z.infer<typeof UpdateProfileDtoSchema>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { expect } from "@jest/globals";
|
|
2
|
+
import { UserDtoSchema } from "./user.dto";
|
|
3
|
+
|
|
4
|
+
const validBase = {
|
|
5
|
+
id: "user-1",
|
|
6
|
+
email: "user@example.com",
|
|
7
|
+
firstName: "Jane",
|
|
8
|
+
lastName: "Roe",
|
|
9
|
+
name: "Jane Roe",
|
|
10
|
+
image: null,
|
|
11
|
+
emailVerified: true,
|
|
12
|
+
preferredLanguage: "en",
|
|
13
|
+
createdAt: new Date("2026-01-01T00:00:00Z"),
|
|
14
|
+
updatedAt: new Date("2026-01-02T00:00:00Z"),
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
describe("userDto", () => {
|
|
18
|
+
it("accepts a fully populated user", () => {
|
|
19
|
+
const result = UserDtoSchema.safeParse(validBase);
|
|
20
|
+
expect(result.success).toBe(true);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("accepts null firstName, lastName, name, and image", () => {
|
|
24
|
+
const result = UserDtoSchema.safeParse({
|
|
25
|
+
...validBase,
|
|
26
|
+
firstName: null,
|
|
27
|
+
lastName: null,
|
|
28
|
+
name: null,
|
|
29
|
+
image: null,
|
|
30
|
+
});
|
|
31
|
+
expect(result.success).toBe(true);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("rejects undefined firstName (must always be present)", () => {
|
|
35
|
+
const { firstName, ...rest } = validBase;
|
|
36
|
+
void firstName;
|
|
37
|
+
const result = UserDtoSchema.safeParse(rest);
|
|
38
|
+
expect(result.success).toBe(false);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("rejects undefined preferredLanguage (must always be present)", () => {
|
|
42
|
+
const { preferredLanguage, ...rest } = validBase;
|
|
43
|
+
void preferredLanguage;
|
|
44
|
+
const result = UserDtoSchema.safeParse(rest);
|
|
45
|
+
expect(result.success).toBe(false);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("rejects unsupported preferredLanguage values", () => {
|
|
49
|
+
const result = UserDtoSchema.safeParse({ ...validBase, preferredLanguage: "fr" });
|
|
50
|
+
expect(result.success).toBe(false);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("rejects an invalid email", () => {
|
|
54
|
+
const result = UserDtoSchema.safeParse({ ...validBase, email: "not-an-email" });
|
|
55
|
+
expect(result.success).toBe(false);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("coerces ISO date strings to Date objects", () => {
|
|
59
|
+
const result = UserDtoSchema.safeParse({
|
|
60
|
+
...validBase,
|
|
61
|
+
createdAt: "2026-01-01T00:00:00Z",
|
|
62
|
+
updatedAt: "2026-01-02T00:00:00Z",
|
|
63
|
+
});
|
|
64
|
+
expect(result.success).toBe(true);
|
|
65
|
+
if (result.success) {
|
|
66
|
+
expect(result.data.createdAt).toBeInstanceOf(Date);
|
|
67
|
+
expect(result.data.updatedAt).toBeInstanceOf(Date);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
});
|
package/src/users/user.dto.ts
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
|
+
import { LanguageEnum } from "../aas/enums/language-enum";
|
|
1
2
|
import { z } from "zod";
|
|
2
3
|
|
|
3
|
-
export
|
|
4
|
-
id: string
|
|
5
|
-
email:
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
export const UserDtoSchema = z.object({
|
|
5
|
+
id: z.string(),
|
|
6
|
+
email: z.email(),
|
|
7
|
+
firstName: z.string().nullable(),
|
|
8
|
+
lastName: z.string().nullable(),
|
|
9
|
+
name: z.string().nullable(),
|
|
10
|
+
image: z.string().nullable(),
|
|
11
|
+
emailVerified: z.boolean(),
|
|
12
|
+
preferredLanguage: LanguageEnum,
|
|
13
|
+
createdAt: z.coerce.date(),
|
|
14
|
+
updatedAt: z.coerce.date(),
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export type UserDto = z.infer<typeof UserDtoSchema>;
|
|
12
18
|
|
|
13
19
|
export const UserRoleDto = {
|
|
14
20
|
ADMIN: "admin", // That is the super admin over all organizations
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"digital-product-document.schemas.d.ts","sourceRoot":"","sources":["../../src/shared/digital-product-document.schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,eAAO,MAAM,cAAc,oDAAwC,CAAC;AAEpE,eAAO,MAAM,+BAA+B;;;;CAIlC,CAAC;AAEX,eAAO,MAAM,mCAAmC;;;;EAA0C,CAAC;AAC3F,MAAM,MAAM,mCAAmC,GAAG,CAAC,CAAC,KAAK,CACvD,OAAO,mCAAmC,CAC3C,CAAC;AAEF,eAAO,MAAM,iDAAiD;;;;CAIpD,CAAC;AAEX,eAAO,MAAM,+CAA+C;;;;EAE3D,CAAC;AAEF,eAAO,MAAM,2CAA2C;;;;;;;;;;;iBAmBrD,CAAC;AAEJ,eAAO,MAAM,iDAAiD;;;;;;iBAE5D,CAAC;AAEH,MAAM,MAAM,2CAA2C,GAAG,CAAC,CAAC,KAAK,CAC/D,OAAO,iDAAiD,CACzD,CAAC;AAEF,eAAO,MAAM,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAO1C,CAAC;AAEH,MAAM,MAAM,yBAAyB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,+BAA+B,CAAC,CAAC"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|