@stevenkellner/team-conduct-api 1.0.2 → 1.0.3
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/index.ts +1 -0
- package/lib/index.js +1 -1
- package/package.json +6 -33
- package/src/Firestore.ts +2 -2
- package/src/firebase/FirebaseConfiguration.ts +39 -0
- package/src/firebase/Messaging.ts +29 -0
- package/src/firebase/index.ts +2 -0
- package/src/functions/fine/update.ts +1 -1
- package/src/functions/notification/register.ts +1 -1
- package/src/pushNotification.ts +3 -4
- package/src/types/MoneyAmount.ts +4 -0
- package/tsconfig.json +110 -14
- package/.mocharc.js +0 -22
- package/.vscode/launch.json +0 -14
- package/LICENSE +0 -21
- package/src/index.ts +0 -24
- package/test/FirebaseApp.ts +0 -64
- package/test/FirebaseAuth.ts +0 -26
- package/test/FirebaseFirestore.ts +0 -20
- package/test/FirebaseFunctions.ts +0 -17
- package/test/RandomData.ts +0 -120
- package/test/createTestTeam.ts +0 -43
- package/test/firebase-rules.test.ts +0 -125
- package/test/functions/fine/add.test.ts +0 -52
- package/test/functions/fine/delete.test.ts +0 -50
- package/test/functions/fine/update.test.ts +0 -39
- package/test/functions/fineTemplate/add.test.ts +0 -35
- package/test/functions/fineTemplate/delete.test.ts +0 -33
- package/test/functions/fineTemplate/update.test.ts +0 -35
- package/test/functions/invitation/invite.test.ts +0 -48
- package/test/functions/invitation/register.test.ts +0 -137
- package/test/functions/invitation/withdraw.test.ts +0 -33
- package/test/functions/notifcation/register.test.ts +0 -47
- package/test/functions/notifcation/subscribe.test.ts +0 -46
- package/test/functions/paypalMe/edit.test.ts +0 -42
- package/test/functions/person/add.test.ts +0 -39
- package/test/functions/person/delete.test.ts +0 -41
- package/test/functions/person/update.test.ts +0 -39
- package/test/functions/team/new.test.ts +0 -139
- package/test/functions/user/login.test.ts +0 -37
- package/test/functions/user/roleEdit.test.ts +0 -47
- package/test/testTeams/testTeam1.ts +0 -63
- package/test/waitForEmulator.ts +0 -11
- package/tsconfig.dev.json +0 -5
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import { expect } from '@assertive-ts/core';
|
|
2
|
-
import { FirebaseApp } from '../../FirebaseApp';
|
|
3
|
-
import { Dictionary, Result, Tagged } from '@stevenkellner/typescript-common-functionality';
|
|
4
|
-
import { FunctionsError } from '@stevenkellner/firebase-function';
|
|
5
|
-
import { RandomData } from '../../RandomData';
|
|
6
|
-
import { Invitation, Team, User } from '../../../src/types';
|
|
7
|
-
|
|
8
|
-
describe('InvitationRegisterFunction', () => {
|
|
9
|
-
|
|
10
|
-
let userId: User.Id;
|
|
11
|
-
|
|
12
|
-
beforeEach(async () => {
|
|
13
|
-
userId = await FirebaseApp.shared.addTestTeam('team-manager');
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
afterEach(async () => {
|
|
17
|
-
await FirebaseApp.shared.firestore.clear();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('not signed in', async () => {
|
|
21
|
-
const invitationId = await FirebaseApp.shared.functions.invitation.invite.execute(new Invitation(
|
|
22
|
-
FirebaseApp.shared.testTeam.id,
|
|
23
|
-
FirebaseApp.shared.testTeam.persons[1].id
|
|
24
|
-
));
|
|
25
|
-
await FirebaseApp.shared.auth.signOut();
|
|
26
|
-
const result = await FirebaseApp.shared.functions.invitation.register.executeWithResult(invitationId);
|
|
27
|
-
expect(result).toBeEqual(Result.failure(new FunctionsError('unauthenticated', 'User not authenticated')));
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('invitation not found', async () => {
|
|
31
|
-
const result = await FirebaseApp.shared.functions.invitation.register.executeWithResult(new Tagged('no-invitation', 'invitation'));
|
|
32
|
-
expect(result).toBeEqual(Result.failure(new FunctionsError('not-found', 'Invitation not found')));
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('user already in team', async () => {
|
|
36
|
-
const invitationId = await FirebaseApp.shared.functions.invitation.invite.execute(new Invitation(
|
|
37
|
-
FirebaseApp.shared.testTeam.id,
|
|
38
|
-
FirebaseApp.shared.testTeam.persons[1].id
|
|
39
|
-
));
|
|
40
|
-
const result = await FirebaseApp.shared.functions.invitation.register.executeWithResult(invitationId);
|
|
41
|
-
expect(result).toBeEqual(Result.failure(new FunctionsError('already-exists', 'User already in team')));
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('person not found', async () => {
|
|
45
|
-
const invitationId = await FirebaseApp.shared.functions.invitation.invite.execute(new Invitation(
|
|
46
|
-
FirebaseApp.shared.testTeam.id,
|
|
47
|
-
FirebaseApp.shared.testTeam.persons[1].id
|
|
48
|
-
));
|
|
49
|
-
await FirebaseApp.shared.firestore.user(userId).remove();
|
|
50
|
-
await FirebaseApp.shared.firestore.person(FirebaseApp.shared.testTeam.id, FirebaseApp.shared.testTeam.persons[1].id).remove();
|
|
51
|
-
const result = await FirebaseApp.shared.functions.invitation.register.executeWithResult(invitationId);
|
|
52
|
-
expect(result).toBeEqual(Result.failure(new FunctionsError('not-found', 'Person not found')));
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('register not existing user', async () => {
|
|
56
|
-
const invitationId = await FirebaseApp.shared.functions.invitation.invite.execute(new Invitation(
|
|
57
|
-
FirebaseApp.shared.testTeam.id,
|
|
58
|
-
FirebaseApp.shared.testTeam.persons[1].id
|
|
59
|
-
));
|
|
60
|
-
await FirebaseApp.shared.firestore.user(userId).remove();
|
|
61
|
-
const user = await FirebaseApp.shared.functions.invitation.register.execute(invitationId);
|
|
62
|
-
expect(user).toBeEqual(new User(userId, new Dictionary(Team.Id.builder, {
|
|
63
|
-
[FirebaseApp.shared.testTeam.id.guidString]: new User.TeamProperties(FirebaseApp.shared.testTeam.name, FirebaseApp.shared.testTeam.persons[1].id)
|
|
64
|
-
})));
|
|
65
|
-
const invitationSnapshot = await FirebaseApp.shared.firestore.invitation(invitationId).snapshot();
|
|
66
|
-
expect(invitationSnapshot.exists).toBeFalse();
|
|
67
|
-
const userSnapshot = await FirebaseApp.shared.firestore.user(userId).snapshot();
|
|
68
|
-
expect(userSnapshot.exists).toBeTrue();
|
|
69
|
-
expect(userSnapshot.data).toBeEqual({
|
|
70
|
-
id: userId.value,
|
|
71
|
-
teams: {
|
|
72
|
-
[FirebaseApp.shared.testTeam.id.guidString]: {
|
|
73
|
-
name: FirebaseApp.shared.testTeam.name,
|
|
74
|
-
personId: FirebaseApp.shared.testTeam.persons[1].id.guidString
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
const personSnapshot = await FirebaseApp.shared.firestore.person(FirebaseApp.shared.testTeam.id, FirebaseApp.shared.testTeam.persons[1].id).snapshot();
|
|
79
|
-
expect(personSnapshot.exists).toBeTrue();
|
|
80
|
-
expect(personSnapshot.data.signInProperties !== null).toBeEqual(true);
|
|
81
|
-
expect(personSnapshot.data).toBeEqual({
|
|
82
|
-
...personSnapshot.data,
|
|
83
|
-
signInProperties: {
|
|
84
|
-
userId: userId.value,
|
|
85
|
-
signInDate: personSnapshot.data.signInProperties!.signInDate,
|
|
86
|
-
notificationProperties: {
|
|
87
|
-
tokens: {},
|
|
88
|
-
subscriptions: []
|
|
89
|
-
},
|
|
90
|
-
roles: []
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('register existing user', async () => {
|
|
96
|
-
const invitationId = await FirebaseApp.shared.functions.invitation.invite.execute(new Invitation(
|
|
97
|
-
FirebaseApp.shared.testTeam.id,
|
|
98
|
-
FirebaseApp.shared.testTeam.persons[1].id
|
|
99
|
-
));
|
|
100
|
-
const signedInUser = new User(userId);
|
|
101
|
-
signedInUser.teams.set(RandomData.shared.teamId(), new User.TeamProperties('team-1', Tagged.generate('person')));
|
|
102
|
-
await FirebaseApp.shared.firestore.user(userId).set(signedInUser);
|
|
103
|
-
const user = await FirebaseApp.shared.functions.invitation.register.execute(invitationId);
|
|
104
|
-
const userSnapshot = await FirebaseApp.shared.firestore.user(userId).snapshot();
|
|
105
|
-
expect(userSnapshot.exists).toBeTrue();
|
|
106
|
-
expect(userSnapshot.data).toBeEqual({
|
|
107
|
-
id: userId.value,
|
|
108
|
-
teams: {
|
|
109
|
-
...userSnapshot.data.teams,
|
|
110
|
-
[FirebaseApp.shared.testTeam.id.guidString]: {
|
|
111
|
-
name: FirebaseApp.shared.testTeam.name,
|
|
112
|
-
personId: FirebaseApp.shared.testTeam.persons[1].id.guidString
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
signedInUser.teams.set(FirebaseApp.shared.testTeam.id, new User.TeamProperties(FirebaseApp.shared.testTeam.name, FirebaseApp.shared.testTeam.persons[1].id));
|
|
117
|
-
expect(user).toBeEqual(new User(userId, signedInUser.teams));
|
|
118
|
-
const invitationSnapshot = await FirebaseApp.shared.firestore.invitation(invitationId).snapshot();
|
|
119
|
-
expect(invitationSnapshot.exists).toBeFalse();
|
|
120
|
-
const personSnapshot = await FirebaseApp.shared.firestore.person(FirebaseApp.shared.testTeam.id, FirebaseApp.shared.testTeam.persons[1].id).snapshot();
|
|
121
|
-
expect(personSnapshot.exists).toBeTrue();
|
|
122
|
-
expect(personSnapshot.data.signInProperties !== null).toBeEqual(true);
|
|
123
|
-
expect(personSnapshot.data).toBeEqual({
|
|
124
|
-
...personSnapshot.data,
|
|
125
|
-
signInProperties: {
|
|
126
|
-
userId: userId.value,
|
|
127
|
-
|
|
128
|
-
signInDate: personSnapshot.data.signInProperties!.signInDate,
|
|
129
|
-
notificationProperties: {
|
|
130
|
-
tokens: {},
|
|
131
|
-
subscriptions: []
|
|
132
|
-
},
|
|
133
|
-
roles: []
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
});
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { expect } from '@assertive-ts/core';
|
|
2
|
-
import { FirebaseApp } from '../../FirebaseApp';
|
|
3
|
-
import { Result } from '@stevenkellner/typescript-common-functionality';
|
|
4
|
-
import { FunctionsError } from '@stevenkellner/firebase-function';
|
|
5
|
-
import { Invitation } from '../../../src/types';
|
|
6
|
-
|
|
7
|
-
describe('InvitationWithdrawFunction', () => {
|
|
8
|
-
|
|
9
|
-
beforeEach(async () => {
|
|
10
|
-
await FirebaseApp.shared.addTestTeam('team-manager');
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
afterEach(async () => {
|
|
14
|
-
await FirebaseApp.shared.firestore.clear();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('invitation not found', async () => {
|
|
18
|
-
const result = await FirebaseApp.shared.functions.invitation.withdraw.executeWithResult(new Invitation(
|
|
19
|
-
FirebaseApp.shared.testTeam.id,
|
|
20
|
-
FirebaseApp.shared.testTeam.persons[1].id
|
|
21
|
-
));
|
|
22
|
-
expect(result).toBeEqual(Result.failure(new FunctionsError('not-found', 'Invitation not found')));
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('should withdraw', async () => {
|
|
26
|
-
const invitation = new Invitation(FirebaseApp.shared.testTeam.id, FirebaseApp.shared.testTeam.persons[1].id);
|
|
27
|
-
const invitationId = invitation.createId();
|
|
28
|
-
await FirebaseApp.shared.firestore.invitation(invitationId).set(invitation);
|
|
29
|
-
await FirebaseApp.shared.functions.invitation.withdraw.execute(invitation);
|
|
30
|
-
const invitationSnapshot = await FirebaseApp.shared.firestore.invitation(invitationId).snapshot();
|
|
31
|
-
expect(invitationSnapshot.exists).toBeFalse();
|
|
32
|
-
});
|
|
33
|
-
});
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { NotificationProperties } from './../../../src/types/NotificationProperties';
|
|
2
|
-
import { expect } from '@assertive-ts/core';
|
|
3
|
-
import { FirebaseApp } from '../../FirebaseApp';
|
|
4
|
-
import { Result } from '@stevenkellner/typescript-common-functionality';
|
|
5
|
-
import { FunctionsError } from '@stevenkellner/firebase-function';
|
|
6
|
-
import { RandomData } from '../../RandomData';
|
|
7
|
-
|
|
8
|
-
describe('NotificationRegisterFunction', () => {
|
|
9
|
-
|
|
10
|
-
beforeEach(async () => {
|
|
11
|
-
await FirebaseApp.shared.addTestTeam('fineTemplate-manager');
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
afterEach(async () => {
|
|
15
|
-
await FirebaseApp.shared.firestore.clear();
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it('person not found', async () => {
|
|
19
|
-
const result = await FirebaseApp.shared.functions.notification.register.executeWithResult({
|
|
20
|
-
teamId: FirebaseApp.shared.testTeam.id,
|
|
21
|
-
personId: RandomData.shared.personId(),
|
|
22
|
-
token: 'abc'
|
|
23
|
-
});
|
|
24
|
-
expect(result).toBeEqual(Result.failure(new FunctionsError('not-found', 'Person not found')));
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('person not signed in', async () => {
|
|
28
|
-
const result = await FirebaseApp.shared.functions.notification.register.executeWithResult({
|
|
29
|
-
teamId: FirebaseApp.shared.testTeam.id,
|
|
30
|
-
personId: FirebaseApp.shared.testTeam.persons[1].id,
|
|
31
|
-
token: 'abc'
|
|
32
|
-
});
|
|
33
|
-
expect(result).toBeEqual(Result.failure(new FunctionsError('unauthenticated', 'Person not signed in')));
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('should register notification', async () => {
|
|
37
|
-
await FirebaseApp.shared.functions.notification.register.execute({
|
|
38
|
-
teamId: FirebaseApp.shared.testTeam.id,
|
|
39
|
-
personId: FirebaseApp.shared.testTeam.persons[0].id,
|
|
40
|
-
token: 'abc'
|
|
41
|
-
});
|
|
42
|
-
const personSnapshot = await FirebaseApp.shared.firestore.person(FirebaseApp.shared.testTeam.id, FirebaseApp.shared.testTeam.persons[0].id).snapshot();
|
|
43
|
-
expect(personSnapshot.exists).toBeTrue();
|
|
44
|
-
expect(personSnapshot.data.signInProperties !== null).toBeTrue();
|
|
45
|
-
expect(personSnapshot.data.signInProperties?.notificationProperties.tokens[NotificationProperties.TokenId.create('abc').value]).toBeEqual('abc');
|
|
46
|
-
});
|
|
47
|
-
});
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { expect } from '@assertive-ts/core';
|
|
2
|
-
import { FirebaseApp } from '../../FirebaseApp';
|
|
3
|
-
import { Result } from '@stevenkellner/typescript-common-functionality';
|
|
4
|
-
import { FunctionsError } from '@stevenkellner/firebase-function';
|
|
5
|
-
import { RandomData } from '../../RandomData';
|
|
6
|
-
|
|
7
|
-
describe('NotificationSubscribeFunction', () => {
|
|
8
|
-
|
|
9
|
-
beforeEach(async () => {
|
|
10
|
-
await FirebaseApp.shared.addTestTeam('fineTemplate-manager');
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
afterEach(async () => {
|
|
14
|
-
await FirebaseApp.shared.firestore.clear();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('person not found', async () => {
|
|
18
|
-
const result = await FirebaseApp.shared.functions.notification.subscribe.executeWithResult({
|
|
19
|
-
teamId: FirebaseApp.shared.testTeam.id,
|
|
20
|
-
personId: RandomData.shared.personId(),
|
|
21
|
-
subscriptions: ['new-fine', 'fine-reminder']
|
|
22
|
-
});
|
|
23
|
-
expect(result).toBeEqual(Result.failure(new FunctionsError('not-found', 'Person not found')));
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('person not signed in', async () => {
|
|
27
|
-
const result = await FirebaseApp.shared.functions.notification.subscribe.executeWithResult({
|
|
28
|
-
teamId: FirebaseApp.shared.testTeam.id,
|
|
29
|
-
personId: FirebaseApp.shared.testTeam.persons[1].id,
|
|
30
|
-
subscriptions: ['new-fine', 'fine-reminder']
|
|
31
|
-
});
|
|
32
|
-
expect(result).toBeEqual(Result.failure(new FunctionsError('unauthenticated', 'Person not signed in')));
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('should subscribe notification', async () => {
|
|
36
|
-
await FirebaseApp.shared.functions.notification.subscribe.execute({
|
|
37
|
-
teamId: FirebaseApp.shared.testTeam.id,
|
|
38
|
-
personId: FirebaseApp.shared.testTeam.persons[0].id,
|
|
39
|
-
subscriptions: ['new-fine', 'fine-reminder']
|
|
40
|
-
});
|
|
41
|
-
const personSnapshot = await FirebaseApp.shared.firestore.person(FirebaseApp.shared.testTeam.id, FirebaseApp.shared.testTeam.persons[0].id).snapshot();
|
|
42
|
-
expect(personSnapshot.exists).toBeTrue();
|
|
43
|
-
expect(personSnapshot.data.signInProperties !== null).toBeTrue();
|
|
44
|
-
expect(personSnapshot.data.signInProperties?.notificationProperties.subscriptions).toBeEqual(['new-fine', 'fine-reminder']);
|
|
45
|
-
});
|
|
46
|
-
});
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { expect } from '@assertive-ts/core';
|
|
2
|
-
import { FirebaseApp } from '../../FirebaseApp';
|
|
3
|
-
import { Result } from '@stevenkellner/typescript-common-functionality';
|
|
4
|
-
import { FunctionsError } from '@stevenkellner/firebase-function';
|
|
5
|
-
|
|
6
|
-
describe('PaypalMeEditFunction', () => {
|
|
7
|
-
|
|
8
|
-
beforeEach(async () => {
|
|
9
|
-
await FirebaseApp.shared.addTestTeam('team-manager');
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
afterEach(async () => {
|
|
13
|
-
await FirebaseApp.shared.firestore.clear();
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('team not found', async () => {
|
|
17
|
-
await FirebaseApp.shared.firestore.team(FirebaseApp.shared.testTeam.id).remove();
|
|
18
|
-
const result = await FirebaseApp.shared.functions.paypalMe.edit.executeWithResult({
|
|
19
|
-
teamId: FirebaseApp.shared.testTeam.id,
|
|
20
|
-
paypalMeLink: 'https://paypal.me/TeamPropertiesManager'
|
|
21
|
-
});
|
|
22
|
-
expect(result).toBeEqual(Result.failure(new FunctionsError('not-found', 'Team not found')));
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('add and remove paypalMeLink', async () => {
|
|
26
|
-
await FirebaseApp.shared.functions.paypalMe.edit.execute({
|
|
27
|
-
teamId: FirebaseApp.shared.testTeam.id,
|
|
28
|
-
paypalMeLink: 'paypal.me/my-link'
|
|
29
|
-
});
|
|
30
|
-
let teamSnapshot = await FirebaseApp.shared.firestore.team(FirebaseApp.shared.testTeam.id).snapshot();
|
|
31
|
-
expect(teamSnapshot.exists).toBeTrue();
|
|
32
|
-
expect(teamSnapshot.data.paypalMeLink).toBeEqual('paypal.me/my-link');
|
|
33
|
-
|
|
34
|
-
await FirebaseApp.shared.functions.paypalMe.edit.execute({
|
|
35
|
-
teamId: FirebaseApp.shared.testTeam.id,
|
|
36
|
-
paypalMeLink: null
|
|
37
|
-
});
|
|
38
|
-
teamSnapshot = await FirebaseApp.shared.firestore.team(FirebaseApp.shared.testTeam.id).snapshot();
|
|
39
|
-
expect(teamSnapshot.exists).toBeTrue();
|
|
40
|
-
expect(teamSnapshot.data.paypalMeLink).toBeEqual(null);
|
|
41
|
-
});
|
|
42
|
-
});
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { expect } from '@assertive-ts/core';
|
|
2
|
-
import { FirebaseApp } from '../../FirebaseApp';
|
|
3
|
-
import { Result } from '@stevenkellner/typescript-common-functionality';
|
|
4
|
-
import { FunctionsError } from '@stevenkellner/firebase-function';
|
|
5
|
-
import { RandomData } from '../../RandomData';
|
|
6
|
-
import { Person } from '../../../src/types';
|
|
7
|
-
|
|
8
|
-
describe('PersonAddFunction', () => {
|
|
9
|
-
|
|
10
|
-
beforeEach(async () => {
|
|
11
|
-
await FirebaseApp.shared.addTestTeam('person-manager');
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
afterEach(async () => {
|
|
15
|
-
await FirebaseApp.shared.firestore.clear();
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it('person already exists', async () => {
|
|
19
|
-
const result = await FirebaseApp.shared.functions.person.add.executeWithResult({
|
|
20
|
-
teamId: FirebaseApp.shared.testTeam.id,
|
|
21
|
-
id: FirebaseApp.shared.testTeam.persons[1].id,
|
|
22
|
-
properties: RandomData.shared.personPrivateProperties()
|
|
23
|
-
});
|
|
24
|
-
expect(result).toBeEqual(Result.failure(new FunctionsError('already-exists', 'Person already exists')));
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('should add person', async () => {
|
|
28
|
-
const personId = RandomData.shared.personId();
|
|
29
|
-
const personPrivateProperties = RandomData.shared.personPrivateProperties();
|
|
30
|
-
await FirebaseApp.shared.functions.person.add.execute({
|
|
31
|
-
teamId: FirebaseApp.shared.testTeam.id,
|
|
32
|
-
id: personId,
|
|
33
|
-
properties: personPrivateProperties
|
|
34
|
-
});
|
|
35
|
-
const personSnapshot = await FirebaseApp.shared.firestore.person(FirebaseApp.shared.testTeam.id, personId).snapshot();
|
|
36
|
-
expect(personSnapshot.exists).toBeTrue();
|
|
37
|
-
expect(personSnapshot.data).toBeEqual(new Person(personId, personPrivateProperties).flatten);
|
|
38
|
-
});
|
|
39
|
-
});
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { expect } from '@assertive-ts/core';
|
|
2
|
-
import { FirebaseApp } from '../../FirebaseApp';
|
|
3
|
-
import { Result } from '@stevenkellner/typescript-common-functionality';
|
|
4
|
-
import { FunctionsError } from '@stevenkellner/firebase-function';
|
|
5
|
-
import { RandomData } from '../../RandomData';
|
|
6
|
-
|
|
7
|
-
describe('PersonDeleteFunction', () => {
|
|
8
|
-
|
|
9
|
-
beforeEach(async () => {
|
|
10
|
-
await FirebaseApp.shared.addTestTeam('person-manager');
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
afterEach(async () => {
|
|
14
|
-
await FirebaseApp.shared.firestore.clear();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('person not found', async () => {
|
|
18
|
-
const result = await FirebaseApp.shared.functions.person.delete.executeWithResult({
|
|
19
|
-
teamId: FirebaseApp.shared.testTeam.id,
|
|
20
|
-
id: RandomData.shared.personId()
|
|
21
|
-
});
|
|
22
|
-
expect(result).toBeEqual(Result.failure(new FunctionsError('not-found', 'Person not found')));
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('person is signed in', async () => {
|
|
26
|
-
const result = await FirebaseApp.shared.functions.person.delete.executeWithResult({
|
|
27
|
-
teamId: FirebaseApp.shared.testTeam.id,
|
|
28
|
-
id: FirebaseApp.shared.testTeam.persons[0].id
|
|
29
|
-
});
|
|
30
|
-
expect(result).toBeEqual(Result.failure(new FunctionsError('failed-precondition', 'Person is signed in')));
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('should delete person', async () => {
|
|
34
|
-
await FirebaseApp.shared.functions.person.delete.execute({
|
|
35
|
-
teamId: FirebaseApp.shared.testTeam.id,
|
|
36
|
-
id: FirebaseApp.shared.testTeam.persons[1].id
|
|
37
|
-
});
|
|
38
|
-
const personSnapshot = await FirebaseApp.shared.firestore.person(FirebaseApp.shared.testTeam.id, FirebaseApp.shared.testTeam.persons[1].id).snapshot();
|
|
39
|
-
expect(personSnapshot.exists).toBeFalse();
|
|
40
|
-
});
|
|
41
|
-
});
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { expect } from '@assertive-ts/core';
|
|
2
|
-
import { FirebaseApp } from '../../FirebaseApp';
|
|
3
|
-
import { Result } from '@stevenkellner/typescript-common-functionality';
|
|
4
|
-
import { FunctionsError } from '@stevenkellner/firebase-function';
|
|
5
|
-
import { RandomData } from '../../RandomData';
|
|
6
|
-
import { Person } from '../../../src/types';
|
|
7
|
-
|
|
8
|
-
describe('PersonUpdateFunction', () => {
|
|
9
|
-
|
|
10
|
-
beforeEach(async () => {
|
|
11
|
-
await FirebaseApp.shared.addTestTeam('person-manager');
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
afterEach(async () => {
|
|
15
|
-
await FirebaseApp.shared.firestore.clear();
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it('person not found', async () => {
|
|
19
|
-
const result = await FirebaseApp.shared.functions.person.update.executeWithResult({
|
|
20
|
-
teamId: FirebaseApp.shared.testTeam.id,
|
|
21
|
-
id: RandomData.shared.personId(),
|
|
22
|
-
properties: RandomData.shared.personPrivateProperties()
|
|
23
|
-
});
|
|
24
|
-
expect(result).toBeEqual(Result.failure(new FunctionsError('not-found', 'Person not found')));
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('should update person', async () => {
|
|
28
|
-
const personPrivateProperties = RandomData.shared.personPrivateProperties();
|
|
29
|
-
await FirebaseApp.shared.functions.person.update.execute({
|
|
30
|
-
teamId: FirebaseApp.shared.testTeam.id,
|
|
31
|
-
id: FirebaseApp.shared.testTeam.persons[1].id,
|
|
32
|
-
properties: personPrivateProperties
|
|
33
|
-
});
|
|
34
|
-
const personSnapshot = await FirebaseApp.shared.firestore.person(FirebaseApp.shared.testTeam.id, FirebaseApp.shared.testTeam.persons[1].id).snapshot();
|
|
35
|
-
expect(personSnapshot.exists).toBeTrue();
|
|
36
|
-
const snapshotPerson = Person.builder.build(personSnapshot.data);
|
|
37
|
-
expect(personSnapshot.data).toBeEqual(new Person(FirebaseApp.shared.testTeam.persons[1].id, personPrivateProperties, snapshotPerson.fineIds, snapshotPerson.signInProperties).flatten);
|
|
38
|
-
});
|
|
39
|
-
});
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import { expect } from '@assertive-ts/core';
|
|
2
|
-
import { FirebaseApp } from '../../FirebaseApp';
|
|
3
|
-
import { Result } from '@stevenkellner/typescript-common-functionality';
|
|
4
|
-
import { FunctionsError } from '@stevenkellner/firebase-function';
|
|
5
|
-
import { RandomData } from '../../RandomData';
|
|
6
|
-
import { User, UserRole } from '../../../src/types';
|
|
7
|
-
|
|
8
|
-
describe('TeamNewFunction', () => {
|
|
9
|
-
|
|
10
|
-
let userId: User.Id;
|
|
11
|
-
|
|
12
|
-
beforeEach(async () => {
|
|
13
|
-
userId = await FirebaseApp.shared.addTestTeam();
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
afterEach(async () => {
|
|
17
|
-
await FirebaseApp.shared.firestore.clear();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('should throw an error if user is not authenticated', async () => {
|
|
21
|
-
await FirebaseApp.shared.auth.signOut();
|
|
22
|
-
const result = await FirebaseApp.shared.functions.team.new.executeWithResult({
|
|
23
|
-
id: RandomData.shared.teamId(),
|
|
24
|
-
name: RandomData.shared.teamName(),
|
|
25
|
-
paypalMeLink: null,
|
|
26
|
-
personId: RandomData.shared.personId(),
|
|
27
|
-
personProperties: RandomData.shared.personPrivateProperties()
|
|
28
|
-
});
|
|
29
|
-
expect(result).toBeEqual(Result.failure(new FunctionsError('permission-denied', 'User is not authenticated')));
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('should throw an error if team already exists', async () => {
|
|
33
|
-
const result = await FirebaseApp.shared.functions.team.new.executeWithResult({
|
|
34
|
-
id: FirebaseApp.shared.testTeam.id,
|
|
35
|
-
name: RandomData.shared.teamName(),
|
|
36
|
-
paypalMeLink: null,
|
|
37
|
-
personId: RandomData.shared.personId(),
|
|
38
|
-
personProperties: RandomData.shared.personPrivateProperties()
|
|
39
|
-
});
|
|
40
|
-
expect(result).toBeEqual(Result.failure(new FunctionsError('already-exists', 'Team already exists')));
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('should create a new team existing user', async () => {
|
|
44
|
-
const teamId = RandomData.shared.teamId();
|
|
45
|
-
const teamName = RandomData.shared.teamName();
|
|
46
|
-
const personId = RandomData.shared.personId();
|
|
47
|
-
const personPrivateProperties = RandomData.shared.personPrivateProperties();
|
|
48
|
-
const user = await FirebaseApp.shared.functions.team.new.execute({
|
|
49
|
-
id: teamId,
|
|
50
|
-
name: teamName,
|
|
51
|
-
paypalMeLink: null,
|
|
52
|
-
personId: personId,
|
|
53
|
-
personProperties: personPrivateProperties
|
|
54
|
-
});
|
|
55
|
-
expect(user.teams.has(teamId)).toBeTrue();
|
|
56
|
-
expect(user.teams.get(teamId)).toBeEqual(new User.TeamProperties(teamName, personId));
|
|
57
|
-
const userSnpapshot = await FirebaseApp.shared.firestore.user(userId).snapshot();
|
|
58
|
-
expect(userSnpapshot.exists).toBeTrue();
|
|
59
|
-
expect(teamId.guidString in userSnpapshot.data.teams).toBeTrue();
|
|
60
|
-
const userTeam = userSnpapshot.data.teams[teamId.guidString];
|
|
61
|
-
expect(userTeam).toBeEqual({
|
|
62
|
-
name: teamName,
|
|
63
|
-
personId: personId.guidString
|
|
64
|
-
});
|
|
65
|
-
const teamSnapshot = await FirebaseApp.shared.firestore.team(teamId).snapshot();
|
|
66
|
-
expect(teamSnapshot.exists).toBeTrue();
|
|
67
|
-
expect(teamSnapshot.data).toBeEqual({
|
|
68
|
-
id: teamId.guidString,
|
|
69
|
-
name: teamName,
|
|
70
|
-
paypalMeLink: null
|
|
71
|
-
});
|
|
72
|
-
const personSnapshot = await FirebaseApp.shared.firestore.person(teamId, personId).snapshot();
|
|
73
|
-
expect(personSnapshot.exists).toBeTrue();
|
|
74
|
-
expect(personSnapshot.data.signInProperties !== null).toBeTrue();
|
|
75
|
-
expect(personSnapshot.data).toBeEqual({
|
|
76
|
-
id: personId.guidString,
|
|
77
|
-
properties: personPrivateProperties.flatten,
|
|
78
|
-
fineIds: [],
|
|
79
|
-
signInProperties: {
|
|
80
|
-
userId: userId.value,
|
|
81
|
-
signInDate: personSnapshot.data.signInProperties!.signInDate,
|
|
82
|
-
notificationProperties: {
|
|
83
|
-
tokens: {},
|
|
84
|
-
subscriptions: []
|
|
85
|
-
},
|
|
86
|
-
roles: UserRole.all
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('should create a new team not exiting user', async () => {
|
|
92
|
-
const teamId = RandomData.shared.teamId();
|
|
93
|
-
const teamName = RandomData.shared.teamName();
|
|
94
|
-
const personId = RandomData.shared.personId();
|
|
95
|
-
const personPrivateProperties = RandomData.shared.personPrivateProperties();
|
|
96
|
-
await FirebaseApp.shared.firestore.user(userId).remove();
|
|
97
|
-
const user = await FirebaseApp.shared.functions.team.new.execute({
|
|
98
|
-
id: teamId,
|
|
99
|
-
name: teamName,
|
|
100
|
-
paypalMeLink: null,
|
|
101
|
-
personId: personId,
|
|
102
|
-
personProperties: personPrivateProperties
|
|
103
|
-
});
|
|
104
|
-
expect(user.teams.has(teamId)).toBeTrue();
|
|
105
|
-
expect(user.teams.get(teamId)).toBeEqual(new User.TeamProperties(teamName, personId));
|
|
106
|
-
const userSnpapshot = await FirebaseApp.shared.firestore.user(userId).snapshot();
|
|
107
|
-
expect(userSnpapshot.exists).toBeTrue();
|
|
108
|
-
expect(teamId.guidString in userSnpapshot.data.teams).toBeTrue();
|
|
109
|
-
const userTeam = userSnpapshot.data.teams[teamId.guidString];
|
|
110
|
-
expect(userTeam).toBeEqual({
|
|
111
|
-
name: teamName,
|
|
112
|
-
personId: personId.guidString
|
|
113
|
-
});
|
|
114
|
-
const teamSnapshot = await FirebaseApp.shared.firestore.team(teamId).snapshot();
|
|
115
|
-
expect(teamSnapshot.exists).toBeTrue();
|
|
116
|
-
expect(teamSnapshot.data).toBeEqual({
|
|
117
|
-
id: teamId.guidString,
|
|
118
|
-
name: teamName,
|
|
119
|
-
paypalMeLink: null
|
|
120
|
-
});
|
|
121
|
-
const personSnapshot = await FirebaseApp.shared.firestore.person(teamId, personId).snapshot();
|
|
122
|
-
expect(personSnapshot.exists).toBeTrue();
|
|
123
|
-
expect(personSnapshot.data.signInProperties !== null).toBeTrue();
|
|
124
|
-
expect(personSnapshot.data).toBeEqual({
|
|
125
|
-
id: personId.guidString,
|
|
126
|
-
properties: personPrivateProperties.flatten,
|
|
127
|
-
fineIds: [],
|
|
128
|
-
signInProperties: {
|
|
129
|
-
userId: userId.value,
|
|
130
|
-
signInDate: personSnapshot.data.signInProperties!.signInDate,
|
|
131
|
-
notificationProperties: {
|
|
132
|
-
tokens: {},
|
|
133
|
-
subscriptions: []
|
|
134
|
-
},
|
|
135
|
-
roles: UserRole.all
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
});
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { expect } from '@assertive-ts/core';
|
|
2
|
-
import { FirebaseApp } from '../../FirebaseApp';
|
|
3
|
-
import { Result } from '@stevenkellner/typescript-common-functionality';
|
|
4
|
-
import { FunctionsError } from '@stevenkellner/firebase-function';
|
|
5
|
-
import { User } from '../../../src/types';
|
|
6
|
-
|
|
7
|
-
describe('UserLoginFunction', () => {
|
|
8
|
-
|
|
9
|
-
let userId: User.Id;
|
|
10
|
-
|
|
11
|
-
beforeEach(async () => {
|
|
12
|
-
userId = await FirebaseApp.shared.addTestTeam();
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
afterEach(async () => {
|
|
16
|
-
await FirebaseApp.shared.firestore.clear();
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('not signed in', async () => {
|
|
20
|
-
await FirebaseApp.shared.auth.signOut();
|
|
21
|
-
const result = await FirebaseApp.shared.functions.user.login.executeWithResult(null);
|
|
22
|
-
expect(result).toBeEqual(Result.failure(new FunctionsError('unauthenticated', 'User is not authenticated.')));
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('user not found', async () => {
|
|
26
|
-
await FirebaseApp.shared.auth.signOut();
|
|
27
|
-
await FirebaseApp.shared.auth.signIn('abc.def@ghi.jkl', 'password');
|
|
28
|
-
const result = await FirebaseApp.shared.functions.user.login.executeWithResult(null);
|
|
29
|
-
expect(result).toBeEqual(Result.failure(new FunctionsError('not-found', 'User not found.')));
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('login', async () => {
|
|
33
|
-
const user = await FirebaseApp.shared.functions.user.login.execute(null);
|
|
34
|
-
const userSnapshot = await FirebaseApp.shared.firestore.user(userId).snapshot();
|
|
35
|
-
expect(user).toBeEqual(User.builder.build(userSnapshot.data));
|
|
36
|
-
});
|
|
37
|
-
});
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { expect } from '@assertive-ts/core';
|
|
2
|
-
import { FirebaseApp } from '../../FirebaseApp';
|
|
3
|
-
import { Result } from '@stevenkellner/typescript-common-functionality';
|
|
4
|
-
import { FunctionsError } from '@stevenkellner/firebase-function';
|
|
5
|
-
import { RandomData } from '../../RandomData';
|
|
6
|
-
|
|
7
|
-
describe('UserRoleEditFunction', () => {
|
|
8
|
-
|
|
9
|
-
beforeEach(async () => {
|
|
10
|
-
await FirebaseApp.shared.addTestTeam('team-manager');
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
afterEach(async () => {
|
|
14
|
-
await FirebaseApp.shared.firestore.clear();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('remove team-manager role from user', async () => {
|
|
18
|
-
const result = await FirebaseApp.shared.functions.user.roleEdit.executeWithResult({
|
|
19
|
-
teamId: FirebaseApp.shared.testTeam.id,
|
|
20
|
-
personId: FirebaseApp.shared.testTeam.persons[0].id,
|
|
21
|
-
roles: []
|
|
22
|
-
});
|
|
23
|
-
expect(result).toBeEqual(Result.failure(new FunctionsError('unavailable', 'User cannot remove their own team-manager role')));
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('user does not exist', async () => {
|
|
27
|
-
const result = await FirebaseApp.shared.functions.user.roleEdit.executeWithResult({
|
|
28
|
-
teamId: FirebaseApp.shared.testTeam.id,
|
|
29
|
-
personId: RandomData.shared.personId(),
|
|
30
|
-
roles: ['team-manager']
|
|
31
|
-
});
|
|
32
|
-
expect(result).toBeEqual(Result.failure(new FunctionsError('not-found', 'User does not exist')));
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('edit user roles', async () => {
|
|
36
|
-
await FirebaseApp.shared.functions.user.roleEdit.execute({
|
|
37
|
-
teamId: FirebaseApp.shared.testTeam.id,
|
|
38
|
-
personId: FirebaseApp.shared.testTeam.persons[0].id,
|
|
39
|
-
roles: ['team-manager', 'fine-manager', 'person-manager']
|
|
40
|
-
});
|
|
41
|
-
const personSnapshot = await FirebaseApp.shared.firestore.person(FirebaseApp.shared.testTeam.id, FirebaseApp.shared.testTeam.persons[0].id).snapshot();
|
|
42
|
-
expect(personSnapshot.exists).toBeTrue();
|
|
43
|
-
expect(personSnapshot.data.signInProperties === null).toBeFalse();
|
|
44
|
-
expect(personSnapshot.data.signInProperties!.roles.length).toBeEqual(3);
|
|
45
|
-
expect(personSnapshot.data.signInProperties!.roles).toContainAll('team-manager', 'fine-manager', 'person-manager');
|
|
46
|
-
});
|
|
47
|
-
});
|