@stevenkellner/team-conduct-api 2.0.3 → 2.0.5
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/lib/src/firebase/FirestoreScheme.d.ts +3 -0
- package/lib/src/functions/invitation/getInvitation.d.ts +5 -5
- package/lib/src/functions/invitation/getInvitation.js +1 -1
- package/lib/src/functions/person/add.d.ts +2 -2
- package/lib/src/functions/person/add.js +1 -1
- package/lib/src/functions/person/update.d.ts +2 -2
- package/lib/src/functions/person/update.js +1 -1
- package/lib/src/functions/team/new.d.ts +2 -2
- package/lib/src/functions/team/new.js +1 -1
- package/lib/src/types/PayedState.d.ts +7 -0
- package/lib/src/types/PayedState.js +15 -0
- package/lib/src/types/Person.d.ts +4 -4
- package/lib/src/types/Person.js +2 -2
- package/lib/src/types/{PersonPrivateProperties.d.ts → PersonProperties.d.ts} +9 -9
- package/lib/src/types/{PersonPrivateProperties.js → PersonProperties.js} +12 -12
- package/lib/src/types/PersonSignInProperties.d.ts +4 -4
- package/lib/src/types/PersonSignInProperties.js +6 -6
- package/lib/src/types/User.d.ts +118 -2
- package/lib/src/types/User.js +125 -2
- package/lib/src/types/index.d.ts +1 -1
- package/lib/src/types/index.js +1 -1
- package/lib/test/firebase/firebase-utils.js +7 -5
- package/lib/test/types/PayedState.test.js +31 -0
- package/lib/test/types/Person.test.js +20 -20
- package/lib/test/types/{PersonPrivateProperties.test.js → PersonProperties.test.js} +31 -31
- package/lib/test/types/PersonSignInProperties.test.js +38 -38
- package/lib/test/types/User.test.js +227 -9
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/firebase/FirestoreScheme.ts +3 -0
- package/src/functions/invitation/getInvitation.ts +7 -7
- package/src/functions/person/add.ts +3 -3
- package/src/functions/person/update.ts +3 -3
- package/src/functions/team/new.ts +3 -3
- package/src/types/PayedState.ts +15 -0
- package/src/types/Person.ts +4 -4
- package/src/types/{PersonPrivateProperties.ts → PersonProperties.ts} +10 -10
- package/src/types/PersonSignInProperties.ts +6 -6
- package/src/types/User.ts +162 -2
- package/src/types/index.ts +1 -1
- /package/lib/test/types/{PersonPrivateProperties.test.d.ts → PersonProperties.test.d.ts} +0 -0
package/lib/src/types/User.js
CHANGED
|
@@ -12,14 +12,18 @@ const Person_1 = require("./Person");
|
|
|
12
12
|
*/
|
|
13
13
|
class User {
|
|
14
14
|
id;
|
|
15
|
+
signInDate;
|
|
16
|
+
signInType;
|
|
15
17
|
teams;
|
|
16
18
|
/**
|
|
17
19
|
* Creates a new User instance.
|
|
18
20
|
* @param id - The unique identifier for this user
|
|
19
21
|
* @param teams - Dictionary mapping team IDs to team-specific user properties
|
|
20
22
|
*/
|
|
21
|
-
constructor(id, teams = new typescript_common_functionality_1.Dictionary(Team_1.Team.Id.builder)) {
|
|
23
|
+
constructor(id, signInDate, signInType, teams = new typescript_common_functionality_1.Dictionary(Team_1.Team.Id.builder)) {
|
|
22
24
|
this.id = id;
|
|
25
|
+
this.signInDate = signInDate;
|
|
26
|
+
this.signInType = signInType;
|
|
23
27
|
this.teams = teams;
|
|
24
28
|
}
|
|
25
29
|
/**
|
|
@@ -28,6 +32,8 @@ class User {
|
|
|
28
32
|
get flatten() {
|
|
29
33
|
return {
|
|
30
34
|
id: this.id.flatten,
|
|
35
|
+
signInDate: this.signInDate.flatten,
|
|
36
|
+
signInType: this.signInType.flatten,
|
|
31
37
|
teams: this.teams.flatten
|
|
32
38
|
};
|
|
33
39
|
}
|
|
@@ -41,6 +47,123 @@ exports.User = User;
|
|
|
41
47
|
*/
|
|
42
48
|
Id.builder = typescript_common_functionality_1.Tagged.builder('user', new typescript_common_functionality_1.ValueTypeBuilder());
|
|
43
49
|
})(Id = User.Id || (User.Id = {}));
|
|
50
|
+
/**
|
|
51
|
+
* Represents email-based authentication sign-in type.
|
|
52
|
+
*
|
|
53
|
+
* Used when a user signs in using their email address.
|
|
54
|
+
*/
|
|
55
|
+
class SignInTypeEmail {
|
|
56
|
+
email;
|
|
57
|
+
/**
|
|
58
|
+
* Creates a new email sign-in type.
|
|
59
|
+
* @param email - The email address used for authentication
|
|
60
|
+
*/
|
|
61
|
+
constructor(email) {
|
|
62
|
+
this.email = email;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Gets the flattened representation for serialization.
|
|
66
|
+
*/
|
|
67
|
+
get flatten() {
|
|
68
|
+
return {
|
|
69
|
+
type: 'email',
|
|
70
|
+
email: this.email
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
User.SignInTypeEmail = SignInTypeEmail;
|
|
75
|
+
(function (SignInTypeEmail) {
|
|
76
|
+
/**
|
|
77
|
+
* Builder for constructing SignInTypeEmail instances from flattened data.
|
|
78
|
+
*/
|
|
79
|
+
class TypeBuilder {
|
|
80
|
+
/**
|
|
81
|
+
* Builds a SignInTypeEmail instance from flattened data.
|
|
82
|
+
* @param value - The flattened email sign-in type data
|
|
83
|
+
* @returns A new SignInTypeEmail instance
|
|
84
|
+
*/
|
|
85
|
+
build(value) {
|
|
86
|
+
return new SignInTypeEmail(value.email);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
SignInTypeEmail.TypeBuilder = TypeBuilder;
|
|
90
|
+
/**
|
|
91
|
+
* Singleton builder instance for SignInTypeEmail.
|
|
92
|
+
*/
|
|
93
|
+
SignInTypeEmail.builder = new TypeBuilder();
|
|
94
|
+
})(SignInTypeEmail = User.SignInTypeEmail || (User.SignInTypeEmail = {}));
|
|
95
|
+
/**
|
|
96
|
+
* Represents OAuth-based authentication sign-in type.
|
|
97
|
+
*
|
|
98
|
+
* Used when a user signs in using an OAuth provider (Google or Apple).
|
|
99
|
+
*/
|
|
100
|
+
class SignInTypeOAuth {
|
|
101
|
+
provider;
|
|
102
|
+
/**
|
|
103
|
+
* Creates a new OAuth sign-in type.
|
|
104
|
+
* @param provider - The OAuth provider used for authentication ('google' or 'apple')
|
|
105
|
+
*/
|
|
106
|
+
constructor(provider) {
|
|
107
|
+
this.provider = provider;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Gets the flattened representation for serialization.
|
|
111
|
+
*/
|
|
112
|
+
get flatten() {
|
|
113
|
+
return {
|
|
114
|
+
type: this.provider
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
User.SignInTypeOAuth = SignInTypeOAuth;
|
|
119
|
+
(function (SignInTypeOAuth) {
|
|
120
|
+
/**
|
|
121
|
+
* Builder for constructing SignInTypeOAuth instances from flattened data.
|
|
122
|
+
*/
|
|
123
|
+
class TypeBuilder {
|
|
124
|
+
/**
|
|
125
|
+
* Builds a SignInTypeOAuth instance from flattened data.
|
|
126
|
+
* @param value - The flattened OAuth sign-in type data
|
|
127
|
+
* @returns A new SignInTypeOAuth instance
|
|
128
|
+
*/
|
|
129
|
+
build(value) {
|
|
130
|
+
return new SignInTypeOAuth(value.type);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
SignInTypeOAuth.TypeBuilder = TypeBuilder;
|
|
134
|
+
/**
|
|
135
|
+
* Singleton builder instance for SignInTypeOAuth.
|
|
136
|
+
*/
|
|
137
|
+
SignInTypeOAuth.builder = new TypeBuilder();
|
|
138
|
+
})(SignInTypeOAuth = User.SignInTypeOAuth || (User.SignInTypeOAuth = {}));
|
|
139
|
+
let SignInType;
|
|
140
|
+
(function (SignInType) {
|
|
141
|
+
/**
|
|
142
|
+
* Builder for constructing SignInType instances from flattened data.
|
|
143
|
+
*
|
|
144
|
+
* Automatically determines the correct type based on the 'type' field.
|
|
145
|
+
*/
|
|
146
|
+
class TypeBuilder {
|
|
147
|
+
/**
|
|
148
|
+
* Builds a SignInType instance from flattened data.
|
|
149
|
+
*
|
|
150
|
+
* Routes to the appropriate builder based on the type field.
|
|
151
|
+
* @param value - The flattened sign-in type data
|
|
152
|
+
* @returns Either a SignInTypeEmail or SignInTypeOAuth instance
|
|
153
|
+
*/
|
|
154
|
+
build(value) {
|
|
155
|
+
if (value.type === 'email')
|
|
156
|
+
return SignInTypeEmail.builder.build(value);
|
|
157
|
+
else
|
|
158
|
+
return SignInTypeOAuth.builder.build(value);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
SignInType.TypeBuilder = TypeBuilder;
|
|
162
|
+
/**
|
|
163
|
+
* Singleton builder instance for SignInType.
|
|
164
|
+
*/
|
|
165
|
+
SignInType.builder = new TypeBuilder();
|
|
166
|
+
})(SignInType = User.SignInType || (User.SignInType = {}));
|
|
44
167
|
/**
|
|
45
168
|
* Properties that are specific to a user's membership in a particular team.
|
|
46
169
|
*/
|
|
@@ -101,7 +224,7 @@ exports.User = User;
|
|
|
101
224
|
* @returns A new User instance with all teams reconstructed
|
|
102
225
|
*/
|
|
103
226
|
build(value) {
|
|
104
|
-
return new User(Id.builder.build(value.id), typescript_common_functionality_1.Dictionary.builder(Team_1.Team.Id.builder, User.TeamProperties.builder).build(value.teams));
|
|
227
|
+
return new User(Id.builder.build(value.id), typescript_common_functionality_1.UtcDate.builder.build(value.signInDate), SignInType.builder.build(value.signInType), typescript_common_functionality_1.Dictionary.builder(Team_1.Team.Id.builder, User.TeamProperties.builder).build(value.teams));
|
|
105
228
|
}
|
|
106
229
|
}
|
|
107
230
|
User.TypeBuilder = TypeBuilder;
|
package/lib/src/types/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export * from './MoneyAmount';
|
|
|
9
9
|
export * from './NotificationProperties';
|
|
10
10
|
export * from './PayedState';
|
|
11
11
|
export * from './Person';
|
|
12
|
-
export * from './
|
|
12
|
+
export * from './PersonProperties';
|
|
13
13
|
export * from './PersonSignInProperties';
|
|
14
14
|
export * from './Pluralization';
|
|
15
15
|
export * from './Team';
|
package/lib/src/types/index.js
CHANGED
|
@@ -25,7 +25,7 @@ __exportStar(require("./MoneyAmount"), exports);
|
|
|
25
25
|
__exportStar(require("./NotificationProperties"), exports);
|
|
26
26
|
__exportStar(require("./PayedState"), exports);
|
|
27
27
|
__exportStar(require("./Person"), exports);
|
|
28
|
-
__exportStar(require("./
|
|
28
|
+
__exportStar(require("./PersonProperties"), exports);
|
|
29
29
|
__exportStar(require("./PersonSignInProperties"), exports);
|
|
30
30
|
__exportStar(require("./Pluralization"), exports);
|
|
31
31
|
__exportStar(require("./Team"), exports);
|
|
@@ -62,13 +62,15 @@ class Document {
|
|
|
62
62
|
static user(id, teams) {
|
|
63
63
|
return Document.data(index_1.User.builder.build({
|
|
64
64
|
id: id.value,
|
|
65
|
+
signInDate: typescript_common_functionality_1.UtcDate.now.flatten,
|
|
66
|
+
signInType: { type: 'google' },
|
|
65
67
|
teams: teams.flatten
|
|
66
68
|
}).flatten);
|
|
67
69
|
}
|
|
68
70
|
static personNotSignedIn(id) {
|
|
69
71
|
return Document.data(index_1.Person.builder.build({
|
|
70
72
|
id: id.guidString,
|
|
71
|
-
properties: index_1.
|
|
73
|
+
properties: index_1.PersonProperties.builder.build({
|
|
72
74
|
firstName: 'Test',
|
|
73
75
|
lastName: 'User'
|
|
74
76
|
}).flatten,
|
|
@@ -79,13 +81,13 @@ class Document {
|
|
|
79
81
|
static person(id, userId, roles) {
|
|
80
82
|
return Document.data(index_1.Person.builder.build({
|
|
81
83
|
id: id.guidString,
|
|
82
|
-
properties: index_1.
|
|
84
|
+
properties: index_1.PersonProperties.builder.build({
|
|
83
85
|
firstName: 'Test',
|
|
84
86
|
lastName: 'User'
|
|
85
87
|
}).flatten,
|
|
86
88
|
fineIds: [],
|
|
87
89
|
signInProperties: index_1.PersonSignInProperties.builder.build({
|
|
88
|
-
|
|
90
|
+
joinDate: typescript_common_functionality_1.UtcDate.now.flatten,
|
|
89
91
|
userId: userId.value,
|
|
90
92
|
notificationProperties: new index_1.NotificationProperties().flatten,
|
|
91
93
|
roles: roles
|
|
@@ -95,13 +97,13 @@ class Document {
|
|
|
95
97
|
static personWithSubscriptions(id, subscriptions, tokens) {
|
|
96
98
|
return Document.data(index_1.Person.builder.build({
|
|
97
99
|
id: id.guidString,
|
|
98
|
-
properties: index_1.
|
|
100
|
+
properties: index_1.PersonProperties.builder.build({
|
|
99
101
|
firstName: 'Test',
|
|
100
102
|
lastName: 'User'
|
|
101
103
|
}).flatten,
|
|
102
104
|
fineIds: [],
|
|
103
105
|
signInProperties: index_1.PersonSignInProperties.builder.build({
|
|
104
|
-
|
|
106
|
+
joinDate: typescript_common_functionality_1.UtcDate.now.flatten,
|
|
105
107
|
userId: 'user-123',
|
|
106
108
|
notificationProperties: new index_1.NotificationProperties(tokens, subscriptions).flatten,
|
|
107
109
|
roles: []
|
|
@@ -86,6 +86,37 @@ describe('PayedState', () => {
|
|
|
86
86
|
});
|
|
87
87
|
});
|
|
88
88
|
});
|
|
89
|
+
describe('PayedState.toggled', () => {
|
|
90
|
+
it('should toggle payed to notPayed', () => {
|
|
91
|
+
const result = PayedState_1.PayedState.toggled('payed');
|
|
92
|
+
(0, core_1.expect)(result).toBeEqual('notPayed');
|
|
93
|
+
});
|
|
94
|
+
it('should toggle notPayed to payed', () => {
|
|
95
|
+
const result = PayedState_1.PayedState.toggled('notPayed');
|
|
96
|
+
(0, core_1.expect)(result).toBeEqual('payed');
|
|
97
|
+
});
|
|
98
|
+
it('should toggle back and forth', () => {
|
|
99
|
+
const state1 = 'payed';
|
|
100
|
+
const state2 = PayedState_1.PayedState.toggled(state1);
|
|
101
|
+
const state3 = PayedState_1.PayedState.toggled(state2);
|
|
102
|
+
(0, core_1.expect)(state2).toBeEqual('notPayed');
|
|
103
|
+
(0, core_1.expect)(state3).toBeEqual('payed');
|
|
104
|
+
});
|
|
105
|
+
it('should toggle all payment states', () => {
|
|
106
|
+
PayedState_1.PayedState.all.forEach(state => {
|
|
107
|
+
const toggled = PayedState_1.PayedState.toggled(state);
|
|
108
|
+
(0, core_1.expect)(toggled).not.toBeEqual(state);
|
|
109
|
+
(0, core_1.expect)(PayedState_1.PayedState.all.includes(toggled)).toBeTrue();
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
it('should be reversible', () => {
|
|
113
|
+
PayedState_1.PayedState.all.forEach(state => {
|
|
114
|
+
const toggledOnce = PayedState_1.PayedState.toggled(state);
|
|
115
|
+
const toggledTwice = PayedState_1.PayedState.toggled(toggledOnce);
|
|
116
|
+
(0, core_1.expect)(toggledTwice).toBeEqual(state);
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
});
|
|
89
120
|
describe('PayedState.builder', () => {
|
|
90
121
|
it('should build valid payment state from string', () => {
|
|
91
122
|
const state = PayedState_1.PayedState.builder.build('payed');
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const core_1 = require("@assertive-ts/core");
|
|
4
4
|
const Person_1 = require("../../src/types/Person");
|
|
5
|
-
const
|
|
5
|
+
const PersonProperties_1 = require("../../src/types/PersonProperties");
|
|
6
6
|
const PersonSignInProperties_1 = require("../../src/types/PersonSignInProperties");
|
|
7
7
|
const NotificationProperties_1 = require("../../src/types/NotificationProperties");
|
|
8
8
|
const Fine_1 = require("../../src/types/Fine");
|
|
@@ -35,7 +35,7 @@ describe('Person', () => {
|
|
|
35
35
|
it('should create a person with all properties', () => {
|
|
36
36
|
const userId = User_1.User.Id.builder.build('u1234567-89ab-4def-0123-456789abcdef');
|
|
37
37
|
const personId = Person_1.Person.Id.builder.build('a1111111-1111-4111-1111-111111111111');
|
|
38
|
-
const properties = new
|
|
38
|
+
const properties = new PersonProperties_1.PersonProperties('John', 'Doe');
|
|
39
39
|
const fineIds = [Fine_1.Fine.Id.builder.build('b2222222-2222-4222-2222-222222222222')];
|
|
40
40
|
const signInProperties = new PersonSignInProperties_1.PersonSignInProperties(userId, typescript_common_functionality_1.UtcDate.now, new NotificationProperties_1.NotificationProperties(), []);
|
|
41
41
|
const person = new Person_1.Person(personId, properties, fineIds, signInProperties);
|
|
@@ -46,21 +46,21 @@ describe('Person', () => {
|
|
|
46
46
|
});
|
|
47
47
|
it('should create a person with default empty fineIds', () => {
|
|
48
48
|
const personId = Person_1.Person.Id.builder.build('a1111111-1111-4111-1111-111111111111');
|
|
49
|
-
const properties = new
|
|
49
|
+
const properties = new PersonProperties_1.PersonProperties('Jane', null);
|
|
50
50
|
const person = new Person_1.Person(personId, properties);
|
|
51
51
|
(0, core_1.expect)(person.fineIds.length).toBeEqual(0);
|
|
52
52
|
(0, core_1.expect)(person.signInProperties).toBeEqual(null);
|
|
53
53
|
});
|
|
54
54
|
it('should create a person without sign-in properties', () => {
|
|
55
55
|
const personId = Person_1.Person.Id.builder.build('a1111111-1111-4111-1111-111111111111');
|
|
56
|
-
const properties = new
|
|
56
|
+
const properties = new PersonProperties_1.PersonProperties('Alice', 'Smith');
|
|
57
57
|
const fineIds = [];
|
|
58
58
|
const person = new Person_1.Person(personId, properties, fineIds, null);
|
|
59
59
|
(0, core_1.expect)(person.signInProperties).toBeEqual(null);
|
|
60
60
|
});
|
|
61
61
|
it('should create a person with multiple fines', () => {
|
|
62
62
|
const personId = Person_1.Person.Id.builder.build('a1111111-1111-4111-1111-111111111111');
|
|
63
|
-
const properties = new
|
|
63
|
+
const properties = new PersonProperties_1.PersonProperties('Bob', null);
|
|
64
64
|
const fineIds = [
|
|
65
65
|
Fine_1.Fine.Id.builder.build('b2222222-2222-4222-2222-222222222222'),
|
|
66
66
|
Fine_1.Fine.Id.builder.build('c3333333-3333-4333-3333-333333333333'),
|
|
@@ -71,7 +71,7 @@ describe('Person', () => {
|
|
|
71
71
|
});
|
|
72
72
|
it('should handle person with only first name', () => {
|
|
73
73
|
const personId = Person_1.Person.Id.builder.build('a1111111-1111-4111-1111-111111111111');
|
|
74
|
-
const properties = new
|
|
74
|
+
const properties = new PersonProperties_1.PersonProperties('Charlie', null);
|
|
75
75
|
const person = new Person_1.Person(personId, properties);
|
|
76
76
|
(0, core_1.expect)(person.properties.lastName).toBeEqual(null);
|
|
77
77
|
});
|
|
@@ -79,25 +79,25 @@ describe('Person', () => {
|
|
|
79
79
|
describe('Person.name', () => {
|
|
80
80
|
it('should return full name when last name is present', () => {
|
|
81
81
|
const personId = Person_1.Person.Id.builder.build('a1111111-1111-4111-1111-111111111111');
|
|
82
|
-
const properties = new
|
|
82
|
+
const properties = new PersonProperties_1.PersonProperties('John', 'Doe');
|
|
83
83
|
const person = new Person_1.Person(personId, properties);
|
|
84
84
|
(0, core_1.expect)(person.name).toBeEqual('John Doe');
|
|
85
85
|
});
|
|
86
86
|
it('should return only first name when last name is null', () => {
|
|
87
87
|
const personId = Person_1.Person.Id.builder.build('a1111111-1111-4111-1111-111111111111');
|
|
88
|
-
const properties = new
|
|
88
|
+
const properties = new PersonProperties_1.PersonProperties('Jane', null);
|
|
89
89
|
const person = new Person_1.Person(personId, properties);
|
|
90
90
|
(0, core_1.expect)(person.name).toBeEqual('Jane');
|
|
91
91
|
});
|
|
92
92
|
it('should handle names with special characters', () => {
|
|
93
93
|
const personId = Person_1.Person.Id.builder.build('a1111111-1111-4111-1111-111111111111');
|
|
94
|
-
const properties = new
|
|
94
|
+
const properties = new PersonProperties_1.PersonProperties('José', 'García');
|
|
95
95
|
const person = new Person_1.Person(personId, properties);
|
|
96
96
|
(0, core_1.expect)(person.name).toBeEqual('José García');
|
|
97
97
|
});
|
|
98
98
|
it('should format name correctly with spaces', () => {
|
|
99
99
|
const personId = Person_1.Person.Id.builder.build('a1111111-1111-4111-1111-111111111111');
|
|
100
|
-
const properties = new
|
|
100
|
+
const properties = new PersonProperties_1.PersonProperties('Alice', 'Smith');
|
|
101
101
|
const person = new Person_1.Person(personId, properties);
|
|
102
102
|
const nameParts = person.name.split(' ');
|
|
103
103
|
(0, core_1.expect)(nameParts.length).toBeEqual(2);
|
|
@@ -109,7 +109,7 @@ describe('Person', () => {
|
|
|
109
109
|
it('should return flattened representation with all properties', () => {
|
|
110
110
|
const userId = User_1.User.Id.builder.build('u1234567-89ab-4def-0123-456789abcdef');
|
|
111
111
|
const personId = Person_1.Person.Id.builder.build('a1111111-1111-4111-1111-111111111111');
|
|
112
|
-
const properties = new
|
|
112
|
+
const properties = new PersonProperties_1.PersonProperties('John', 'Doe');
|
|
113
113
|
const fineIds = [Fine_1.Fine.Id.builder.build('b2222222-2222-4222-2222-222222222222')];
|
|
114
114
|
const signInProperties = new PersonSignInProperties_1.PersonSignInProperties(userId, typescript_common_functionality_1.UtcDate.now, new NotificationProperties_1.NotificationProperties(), []);
|
|
115
115
|
const person = new Person_1.Person(personId, properties, fineIds, signInProperties);
|
|
@@ -122,14 +122,14 @@ describe('Person', () => {
|
|
|
122
122
|
});
|
|
123
123
|
it('should return flattened representation with null sign-in properties', () => {
|
|
124
124
|
const personId = Person_1.Person.Id.builder.build('a1111111-1111-4111-1111-111111111111');
|
|
125
|
-
const properties = new
|
|
125
|
+
const properties = new PersonProperties_1.PersonProperties('Jane', null);
|
|
126
126
|
const person = new Person_1.Person(personId, properties);
|
|
127
127
|
const flattened = person.flatten;
|
|
128
128
|
(0, core_1.expect)(flattened.signInProperties).toBeEqual(null);
|
|
129
129
|
});
|
|
130
130
|
it('should flatten empty fineIds array', () => {
|
|
131
131
|
const personId = Person_1.Person.Id.builder.build('a1111111-1111-4111-1111-111111111111');
|
|
132
|
-
const properties = new
|
|
132
|
+
const properties = new PersonProperties_1.PersonProperties('Alice', 'Smith');
|
|
133
133
|
const person = new Person_1.Person(personId, properties, []);
|
|
134
134
|
const flattened = person.flatten;
|
|
135
135
|
(0, core_1.expect)(flattened.fineIds.length).toBeEqual(0);
|
|
@@ -137,7 +137,7 @@ describe('Person', () => {
|
|
|
137
137
|
});
|
|
138
138
|
it('should flatten multiple fineIds', () => {
|
|
139
139
|
const personId = Person_1.Person.Id.builder.build('a1111111-1111-4111-1111-111111111111');
|
|
140
|
-
const properties = new
|
|
140
|
+
const properties = new PersonProperties_1.PersonProperties('Bob', null);
|
|
141
141
|
const fineIds = [
|
|
142
142
|
Fine_1.Fine.Id.builder.build('b2222222-2222-4222-2222-222222222222'),
|
|
143
143
|
Fine_1.Fine.Id.builder.build('c3333333-3333-4333-3333-333333333333')
|
|
@@ -150,7 +150,7 @@ describe('Person', () => {
|
|
|
150
150
|
});
|
|
151
151
|
it('should have correct structure', () => {
|
|
152
152
|
const personId = Person_1.Person.Id.builder.build('a1111111-1111-4111-1111-111111111111');
|
|
153
|
-
const properties = new
|
|
153
|
+
const properties = new PersonProperties_1.PersonProperties('Charlie', 'Brown');
|
|
154
154
|
const person = new Person_1.Person(personId, properties);
|
|
155
155
|
const flattened = person.flatten;
|
|
156
156
|
(0, core_1.expect)(typeof flattened.id).toBeEqual('string');
|
|
@@ -169,7 +169,7 @@ describe('Person', () => {
|
|
|
169
169
|
fineIds: ['b2222222-2222-4222-2222-222222222222'],
|
|
170
170
|
signInProperties: {
|
|
171
171
|
userId: 'user-123',
|
|
172
|
-
|
|
172
|
+
joinDate: typescript_common_functionality_1.UtcDate.now.flatten,
|
|
173
173
|
notificationProperties: {
|
|
174
174
|
tokens: {},
|
|
175
175
|
subscriptions: []
|
|
@@ -229,7 +229,7 @@ describe('Person', () => {
|
|
|
229
229
|
it('should round-trip through flatten and build with all properties', () => {
|
|
230
230
|
const userId = User_1.User.Id.builder.build('u1234567-89ab-4def-0123-456789abcdef');
|
|
231
231
|
const personId = Person_1.Person.Id.builder.build('a1111111-1111-4111-1111-111111111111');
|
|
232
|
-
const properties = new
|
|
232
|
+
const properties = new PersonProperties_1.PersonProperties('John', 'Doe');
|
|
233
233
|
const fineIds = [Fine_1.Fine.Id.builder.build('b2222222-2222-4222-2222-222222222222')];
|
|
234
234
|
const signInProperties = new PersonSignInProperties_1.PersonSignInProperties(userId, typescript_common_functionality_1.UtcDate.now, new NotificationProperties_1.NotificationProperties(), []);
|
|
235
235
|
const original = new Person_1.Person(personId, properties, fineIds, signInProperties);
|
|
@@ -242,21 +242,21 @@ describe('Person', () => {
|
|
|
242
242
|
});
|
|
243
243
|
it('should round-trip through flatten and build with null sign-in properties', () => {
|
|
244
244
|
const personId = Person_1.Person.Id.builder.build('a1111111-1111-4111-1111-111111111111');
|
|
245
|
-
const properties = new
|
|
245
|
+
const properties = new PersonProperties_1.PersonProperties('Jane', null);
|
|
246
246
|
const original = new Person_1.Person(personId, properties);
|
|
247
247
|
const rebuilt = Person_1.Person.builder.build(original.flatten);
|
|
248
248
|
(0, core_1.expect)(rebuilt.signInProperties).toBeEqual(null);
|
|
249
249
|
});
|
|
250
250
|
it('should round-trip through flatten and build with empty fineIds', () => {
|
|
251
251
|
const personId = Person_1.Person.Id.builder.build('a1111111-1111-4111-1111-111111111111');
|
|
252
|
-
const properties = new
|
|
252
|
+
const properties = new PersonProperties_1.PersonProperties('Alice', 'Smith');
|
|
253
253
|
const original = new Person_1.Person(personId, properties, []);
|
|
254
254
|
const rebuilt = Person_1.Person.builder.build(original.flatten);
|
|
255
255
|
(0, core_1.expect)(rebuilt.fineIds.length).toBeEqual(0);
|
|
256
256
|
});
|
|
257
257
|
it('should preserve name property through round-trip', () => {
|
|
258
258
|
const personId = Person_1.Person.Id.builder.build('a1111111-1111-4111-1111-111111111111');
|
|
259
|
-
const properties = new
|
|
259
|
+
const properties = new PersonProperties_1.PersonProperties('Charlie', 'Brown');
|
|
260
260
|
const original = new Person_1.Person(personId, properties);
|
|
261
261
|
const rebuilt = Person_1.Person.builder.build(original.flatten);
|
|
262
262
|
(0, core_1.expect)(rebuilt.name).toBeEqual(original.name);
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const core_1 = require("@assertive-ts/core");
|
|
4
|
-
const
|
|
5
|
-
describe('
|
|
6
|
-
describe('
|
|
4
|
+
const PersonProperties_1 = require("../../src/types/PersonProperties");
|
|
5
|
+
describe('PersonProperties', () => {
|
|
6
|
+
describe('PersonProperties constructor', () => {
|
|
7
7
|
it('should create properties with first name and last name', () => {
|
|
8
|
-
const props = new
|
|
8
|
+
const props = new PersonProperties_1.PersonProperties('John', 'Doe');
|
|
9
9
|
(0, core_1.expect)(props.firstName).toBeEqual('John');
|
|
10
10
|
(0, core_1.expect)(props.lastName).toBeEqual('Doe');
|
|
11
11
|
});
|
|
12
12
|
it('should create properties with first name only', () => {
|
|
13
|
-
const props = new
|
|
13
|
+
const props = new PersonProperties_1.PersonProperties('Jane', null);
|
|
14
14
|
(0, core_1.expect)(props.firstName).toBeEqual('Jane');
|
|
15
15
|
(0, core_1.expect)(props.lastName).toBeNull();
|
|
16
16
|
});
|
|
@@ -22,38 +22,38 @@ describe('PersonPrivateProperties', () => {
|
|
|
22
22
|
{ firstName: 'Diana', lastName: 'Williams' }
|
|
23
23
|
];
|
|
24
24
|
testCases.forEach(testCase => {
|
|
25
|
-
const props = new
|
|
25
|
+
const props = new PersonProperties_1.PersonProperties(testCase.firstName, testCase.lastName);
|
|
26
26
|
(0, core_1.expect)(props.firstName).toBeEqual(testCase.firstName);
|
|
27
27
|
(0, core_1.expect)(props.lastName).toBeEqual(testCase.lastName);
|
|
28
28
|
});
|
|
29
29
|
});
|
|
30
30
|
it('should handle names with special characters', () => {
|
|
31
|
-
const props = new
|
|
31
|
+
const props = new PersonProperties_1.PersonProperties('François', 'O\'Brien');
|
|
32
32
|
(0, core_1.expect)(props.firstName).toBeEqual('François');
|
|
33
33
|
(0, core_1.expect)(props.lastName).toBeEqual('O\'Brien');
|
|
34
34
|
});
|
|
35
35
|
it('should handle long names', () => {
|
|
36
36
|
const longFirstName = 'Alexander-Christopher-Maximilian';
|
|
37
37
|
const longLastName = 'Van Der Woodsen-Humphrey-Bass';
|
|
38
|
-
const props = new
|
|
38
|
+
const props = new PersonProperties_1.PersonProperties(longFirstName, longLastName);
|
|
39
39
|
(0, core_1.expect)(props.firstName).toBeEqual(longFirstName);
|
|
40
40
|
(0, core_1.expect)(props.lastName).toBeEqual(longLastName);
|
|
41
41
|
});
|
|
42
42
|
it('should handle empty string as first name', () => {
|
|
43
|
-
const props = new
|
|
43
|
+
const props = new PersonProperties_1.PersonProperties('', 'Doe');
|
|
44
44
|
(0, core_1.expect)(props.firstName).toBeEqual('');
|
|
45
45
|
(0, core_1.expect)(props.lastName).toBeEqual('Doe');
|
|
46
46
|
});
|
|
47
47
|
});
|
|
48
|
-
describe('
|
|
48
|
+
describe('PersonProperties.flatten', () => {
|
|
49
49
|
it('should return flattened representation with both names', () => {
|
|
50
|
-
const props = new
|
|
50
|
+
const props = new PersonProperties_1.PersonProperties('John', 'Smith');
|
|
51
51
|
const flattened = props.flatten;
|
|
52
52
|
(0, core_1.expect)(flattened.firstName).toBeEqual('John');
|
|
53
53
|
(0, core_1.expect)(flattened.lastName).toBeEqual('Smith');
|
|
54
54
|
});
|
|
55
55
|
it('should return flattened representation with first name only', () => {
|
|
56
|
-
const props = new
|
|
56
|
+
const props = new PersonProperties_1.PersonProperties('Jane', null);
|
|
57
57
|
const flattened = props.flatten;
|
|
58
58
|
(0, core_1.expect)(flattened.firstName).toBeEqual('Jane');
|
|
59
59
|
(0, core_1.expect)(flattened.lastName).toBeNull();
|
|
@@ -61,36 +61,36 @@ describe('PersonPrivateProperties', () => {
|
|
|
61
61
|
it('should match the original values', () => {
|
|
62
62
|
const firstName = 'Michael';
|
|
63
63
|
const lastName = 'Brown';
|
|
64
|
-
const props = new
|
|
64
|
+
const props = new PersonProperties_1.PersonProperties(firstName, lastName);
|
|
65
65
|
const flattened = props.flatten;
|
|
66
66
|
(0, core_1.expect)(flattened.firstName).toBeEqual(firstName);
|
|
67
67
|
(0, core_1.expect)(flattened.lastName).toBeEqual(lastName);
|
|
68
68
|
});
|
|
69
69
|
it('should have correct structure', () => {
|
|
70
|
-
const props = new
|
|
70
|
+
const props = new PersonProperties_1.PersonProperties('Test', 'User');
|
|
71
71
|
const flattened = props.flatten;
|
|
72
72
|
(0, core_1.expect)(typeof flattened.firstName).toBeEqual('string');
|
|
73
73
|
(0, core_1.expect)(typeof flattened.lastName).toBeEqual('string');
|
|
74
74
|
});
|
|
75
75
|
it('should handle null lastName correctly in flattened form', () => {
|
|
76
|
-
const props = new
|
|
76
|
+
const props = new PersonProperties_1.PersonProperties('Single', null);
|
|
77
77
|
const flattened = props.flatten;
|
|
78
78
|
(0, core_1.expect)(flattened.lastName).toBeNull();
|
|
79
79
|
});
|
|
80
80
|
it('should preserve special characters in flattened form', () => {
|
|
81
|
-
const props = new
|
|
81
|
+
const props = new PersonProperties_1.PersonProperties('José', 'García');
|
|
82
82
|
const flattened = props.flatten;
|
|
83
83
|
(0, core_1.expect)(flattened.firstName).toBeEqual('José');
|
|
84
84
|
(0, core_1.expect)(flattened.lastName).toBeEqual('García');
|
|
85
85
|
});
|
|
86
86
|
});
|
|
87
|
-
describe('
|
|
87
|
+
describe('PersonProperties.TypeBuilder', () => {
|
|
88
88
|
it('should build properties from flattened data with both names', () => {
|
|
89
89
|
const flattened = {
|
|
90
90
|
firstName: 'Emily',
|
|
91
91
|
lastName: 'Davis'
|
|
92
92
|
};
|
|
93
|
-
const props =
|
|
93
|
+
const props = PersonProperties_1.PersonProperties.builder.build(flattened);
|
|
94
94
|
(0, core_1.expect)(props.firstName).toBeEqual('Emily');
|
|
95
95
|
(0, core_1.expect)(props.lastName).toBeEqual('Davis');
|
|
96
96
|
});
|
|
@@ -99,19 +99,19 @@ describe('PersonPrivateProperties', () => {
|
|
|
99
99
|
firstName: 'Oliver',
|
|
100
100
|
lastName: null
|
|
101
101
|
};
|
|
102
|
-
const props =
|
|
102
|
+
const props = PersonProperties_1.PersonProperties.builder.build(flattened);
|
|
103
103
|
(0, core_1.expect)(props.firstName).toBeEqual('Oliver');
|
|
104
104
|
(0, core_1.expect)(props.lastName).toBeNull();
|
|
105
105
|
});
|
|
106
106
|
it('should round-trip through flatten and build with both names', () => {
|
|
107
|
-
const original = new
|
|
108
|
-
const rebuilt =
|
|
107
|
+
const original = new PersonProperties_1.PersonProperties('Sophia', 'Wilson');
|
|
108
|
+
const rebuilt = PersonProperties_1.PersonProperties.builder.build(original.flatten);
|
|
109
109
|
(0, core_1.expect)(rebuilt.firstName).toBeEqual(original.firstName);
|
|
110
110
|
(0, core_1.expect)(rebuilt.lastName).toBeEqual(original.lastName);
|
|
111
111
|
});
|
|
112
112
|
it('should round-trip through flatten and build with null lastName', () => {
|
|
113
|
-
const original = new
|
|
114
|
-
const rebuilt =
|
|
113
|
+
const original = new PersonProperties_1.PersonProperties('Liam', null);
|
|
114
|
+
const rebuilt = PersonProperties_1.PersonProperties.builder.build(original.flatten);
|
|
115
115
|
(0, core_1.expect)(rebuilt.firstName).toBeEqual(original.firstName);
|
|
116
116
|
(0, core_1.expect)(rebuilt.lastName).toBeNull();
|
|
117
117
|
});
|
|
@@ -123,14 +123,14 @@ describe('PersonPrivateProperties', () => {
|
|
|
123
123
|
{ firstName: 'William', lastName: 'Thomas' }
|
|
124
124
|
];
|
|
125
125
|
testCases.forEach(testCase => {
|
|
126
|
-
const props =
|
|
126
|
+
const props = PersonProperties_1.PersonProperties.builder.build(testCase);
|
|
127
127
|
(0, core_1.expect)(props.firstName).toBeEqual(testCase.firstName);
|
|
128
128
|
(0, core_1.expect)(props.lastName).toBeEqual(testCase.lastName);
|
|
129
129
|
});
|
|
130
130
|
});
|
|
131
131
|
it('should handle special characters through round-trip', () => {
|
|
132
|
-
const original = new
|
|
133
|
-
const rebuilt =
|
|
132
|
+
const original = new PersonProperties_1.PersonProperties('Müller', 'O\'Reilly');
|
|
133
|
+
const rebuilt = PersonProperties_1.PersonProperties.builder.build(original.flatten);
|
|
134
134
|
(0, core_1.expect)(rebuilt.firstName).toBeEqual('Müller');
|
|
135
135
|
(0, core_1.expect)(rebuilt.lastName).toBeEqual('O\'Reilly');
|
|
136
136
|
});
|
|
@@ -139,15 +139,15 @@ describe('PersonPrivateProperties', () => {
|
|
|
139
139
|
firstName: '',
|
|
140
140
|
lastName: 'Empty'
|
|
141
141
|
};
|
|
142
|
-
const props =
|
|
142
|
+
const props = PersonProperties_1.PersonProperties.builder.build(flattened);
|
|
143
143
|
(0, core_1.expect)(props.firstName).toBeEqual('');
|
|
144
144
|
(0, core_1.expect)(props.lastName).toBeEqual('Empty');
|
|
145
145
|
});
|
|
146
146
|
it('should preserve exact values through multiple round-trips', () => {
|
|
147
|
-
const original = new
|
|
148
|
-
const rebuilt1 =
|
|
149
|
-
const rebuilt2 =
|
|
150
|
-
const rebuilt3 =
|
|
147
|
+
const original = new PersonProperties_1.PersonProperties('Isabella', 'Martinez');
|
|
148
|
+
const rebuilt1 = PersonProperties_1.PersonProperties.builder.build(original.flatten);
|
|
149
|
+
const rebuilt2 = PersonProperties_1.PersonProperties.builder.build(rebuilt1.flatten);
|
|
150
|
+
const rebuilt3 = PersonProperties_1.PersonProperties.builder.build(rebuilt2.flatten);
|
|
151
151
|
(0, core_1.expect)(rebuilt3.firstName).toBeEqual(original.firstName);
|
|
152
152
|
(0, core_1.expect)(rebuilt3.lastName).toBeEqual(original.lastName);
|
|
153
153
|
});
|