@stevenkellner/team-conduct-api 1.0.1 → 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
package/test/RandomData.ts
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { FineTemplateRepetition } from './../src/types/FineTemplateRepetition';
|
|
2
|
-
import { MoneyAmount } from './../src/types/MoneyAmount';
|
|
3
|
-
import { NotificationProperties } from './../src/types/NotificationProperties';
|
|
4
|
-
import { PersonSignInProperties } from './../src/types/PersonSignInProperties';
|
|
5
|
-
import { PersonPrivateProperties } from './../src/types/PersonPrivateProperties';
|
|
6
|
-
import { Dictionary, Tagged, UtcDate } from '@stevenkellner/typescript-common-functionality';
|
|
7
|
-
import { adjectives, animals, colors, names, starWars, uniqueNamesGenerator } from 'unique-names-generator';
|
|
8
|
-
import { Fine, FineAmount, FineTemplate, PayedState, Person, Team, User, UserRole } from '../src/types';
|
|
9
|
-
|
|
10
|
-
export class RandomData {
|
|
11
|
-
|
|
12
|
-
private constructor() {}
|
|
13
|
-
|
|
14
|
-
public static shared = new RandomData();
|
|
15
|
-
|
|
16
|
-
public date(): UtcDate {
|
|
17
|
-
return new UtcDate(
|
|
18
|
-
2000 + Math.round(Math.random() * 100),
|
|
19
|
-
Math.floor(Math.random() * 12),
|
|
20
|
-
Math.floor(Math.random() * 29),
|
|
21
|
-
Math.floor(Math.random() * 24),
|
|
22
|
-
Math.floor(Math.random() * 60)
|
|
23
|
-
)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
public teamId(): Team.Id {
|
|
27
|
-
return Tagged.generate('team');
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
public personId(): Person.Id {
|
|
31
|
-
return Tagged.generate('person');
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
public fineId(): Fine.Id {
|
|
35
|
-
return Tagged.generate('fine');
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
public fineTemplateId(): FineTemplate.Id {
|
|
39
|
-
return Tagged.generate('fineTemplate');
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
public teamName(): string {
|
|
43
|
-
return uniqueNamesGenerator({ dictionaries: [adjectives, starWars] });
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
public personPrivateProperties(): PersonPrivateProperties {
|
|
47
|
-
return new PersonPrivateProperties(
|
|
48
|
-
uniqueNamesGenerator({ dictionaries: [names] }),
|
|
49
|
-
uniqueNamesGenerator({ dictionaries: [names] })
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
public notificationProperties(): NotificationProperties {
|
|
54
|
-
return new NotificationProperties(
|
|
55
|
-
new Dictionary(NotificationProperties.TokenId.builder),
|
|
56
|
-
new Array(Math.floor(Math.random() * NotificationProperties.Subscription.all.length)).fill(null).map(() => NotificationProperties.Subscription.all[Math.floor(Math.random() * NotificationProperties.Subscription.all.length)])
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
public personSignInProperties(userId: User.Id | null = null): PersonSignInProperties {
|
|
61
|
-
return new PersonSignInProperties(
|
|
62
|
-
userId ?? new Tagged(uniqueNamesGenerator({ dictionaries: [adjectives, colors, animals] }), 'user'),
|
|
63
|
-
this.date(),
|
|
64
|
-
this.notificationProperties(),
|
|
65
|
-
new Array(Math.floor(Math.random() * UserRole.all.length)).fill(null).map(() => UserRole.all[Math.floor(Math.random() * UserRole.all.length)])
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
public person(id: Person.Id | null = null, fineIds: Fine.Id[] = []): Person {
|
|
70
|
-
return new Person(
|
|
71
|
-
id ?? this.personId(),
|
|
72
|
-
this.personPrivateProperties(),
|
|
73
|
-
fineIds,
|
|
74
|
-
Math.random() > 0.5 ? null : this.personSignInProperties()
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
public moneyAmount(): MoneyAmount {
|
|
79
|
-
return new MoneyAmount(
|
|
80
|
-
Math.floor(Math.random() * 100),
|
|
81
|
-
Math.floor(Math.random() * 100)
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
public fineAmount(): FineAmount {
|
|
86
|
-
if (Math.random() > 0.5) {
|
|
87
|
-
return FineAmount.item(
|
|
88
|
-
FineAmount.Item.Type.all[Math.floor(Math.random() * FineAmount.Item.Type.all.length)],
|
|
89
|
-
Math.floor(Math.random() * 100)
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
return FineAmount.money(this.moneyAmount());
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
public fine(id: Fine.Id | null = null, date: UtcDate | null = null): Fine {
|
|
96
|
-
return new Fine(
|
|
97
|
-
id ?? this.fineId(),
|
|
98
|
-
PayedState.all[Math.floor(Math.random() * PayedState.all.length)],
|
|
99
|
-
date ?? this.date(),
|
|
100
|
-
uniqueNamesGenerator({ dictionaries: [adjectives, starWars] }),
|
|
101
|
-
this.fineAmount()
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
public fineTemplateRepetition(): FineTemplateRepetition {
|
|
106
|
-
return new FineTemplateRepetition(
|
|
107
|
-
FineTemplateRepetition.Item.all[Math.floor(Math.random() * FineTemplateRepetition.Item.all.length)],
|
|
108
|
-
Math.random() > 0.5 ? null : Math.floor(Math.random() * 100)
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
public fineTemplate(id: FineTemplate.Id | null = null): FineTemplate {
|
|
113
|
-
return new FineTemplate(
|
|
114
|
-
id ?? this.fineTemplateId(),
|
|
115
|
-
uniqueNamesGenerator({ dictionaries: [adjectives, starWars] }),
|
|
116
|
-
this.fineAmount(),
|
|
117
|
-
Math.random() > 0.5 ? null : this.fineTemplateRepetition()
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
}
|
package/test/createTestTeam.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { UtcDate } from '@stevenkellner/typescript-common-functionality';
|
|
2
|
-
import { Fine, FineTemplate, Person, PersonSignInProperties, User, UserRole, Team, NotificationProperties } from '../src/types';
|
|
3
|
-
import { testTeam1 } from './testTeams/testTeam1';
|
|
4
|
-
import { FirebaseApp } from './FirebaseApp';
|
|
5
|
-
|
|
6
|
-
export type TestTeam = {
|
|
7
|
-
id: Team.Id
|
|
8
|
-
name: string,
|
|
9
|
-
persons: Person[],
|
|
10
|
-
fineTemplates: FineTemplate[]
|
|
11
|
-
fines: Fine[]
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function* internal_createTestTeam(team: TestTeam, userId: User.Id, roles: UserRole[]): Generator<Promise<unknown>> {
|
|
15
|
-
const user = new User(userId);
|
|
16
|
-
user.teams.set(team.id, new User.TeamProperties(team.name, team.persons[0].id));
|
|
17
|
-
yield FirebaseApp.shared.firestore.user(userId).set(user);
|
|
18
|
-
yield FirebaseApp.shared.firestore.team(team.id).set(new Team(team.id, team.name, null));
|
|
19
|
-
for (const [index, person] of team.persons.entries()) {
|
|
20
|
-
if (index === 0)
|
|
21
|
-
person.signInProperties = new PersonSignInProperties(userId, UtcDate.now, new NotificationProperties(), roles);
|
|
22
|
-
yield FirebaseApp.shared.firestore.person(team.id, person.id).set(person);
|
|
23
|
-
}
|
|
24
|
-
for (const fineTemplate of team.fineTemplates)
|
|
25
|
-
yield FirebaseApp.shared.firestore.fineTemplate(team.id, fineTemplate.id).set(fineTemplate);
|
|
26
|
-
for (const fine of team.fines)
|
|
27
|
-
yield FirebaseApp.shared.firestore.fine(team.id, fine.id).set(fine);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function getTestTeam(team: TestTeam | number): TestTeam {
|
|
31
|
-
if (typeof team !== 'number')
|
|
32
|
-
return team;
|
|
33
|
-
switch (team) {
|
|
34
|
-
case 1:
|
|
35
|
-
return testTeam1;
|
|
36
|
-
default:
|
|
37
|
-
throw new Error(`Unknown test team: ${team}`);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export async function createTestTeam(team: TestTeam | number, userId: User.Id, roles: UserRole[]) {
|
|
42
|
-
await Promise.all([...internal_createTestTeam(getTestTeam(team), userId, roles)]);
|
|
43
|
-
}
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { FirestoreCollection } from '@stevenkellner/firebase-function';
|
|
2
|
-
import { FirebaseApp } from './FirebaseApp';
|
|
3
|
-
import { assert, expect } from '@assertive-ts/core'
|
|
4
|
-
import { deleteDoc, doc, getDoc, getDocs, query, setDoc, updateDoc, collection, Firestore, getFirestore, connectFirestoreEmulator } from 'firebase/firestore';
|
|
5
|
-
import { Team, User } from '../src/types';
|
|
6
|
-
import { Tagged } from '@stevenkellner/typescript-common-functionality';
|
|
7
|
-
|
|
8
|
-
describe('Firebase Rules', () => {
|
|
9
|
-
|
|
10
|
-
let firestore: Firestore;
|
|
11
|
-
|
|
12
|
-
before(async () => {
|
|
13
|
-
firestore = getFirestore();
|
|
14
|
-
connectFirestoreEmulator(firestore, '127.0.0.1', 8080);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
afterEach(async () => {
|
|
18
|
-
await FirebaseApp.shared.firestore.clear();
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
22
|
-
async function expectPermissionDenied(fn: () => Promise<any>) {
|
|
23
|
-
try {
|
|
24
|
-
await fn();
|
|
25
|
-
expect(false).toBeTrue();
|
|
26
|
-
} catch (error) {
|
|
27
|
-
expect(error).toBeInstanceOf(Error);
|
|
28
|
-
assert(typeof error === 'object' && error !== null);
|
|
29
|
-
assert('code' in (error as object));
|
|
30
|
-
expect((error as { code: unknown }).code).toBeEqual('permission-denied');
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
async function createTestDocuments() {
|
|
35
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
36
|
-
const firestore = FirebaseApp.shared.firestore as { collection(key: string): FirestoreCollection<any> };
|
|
37
|
-
await firestore.collection('users').document('123').set({ data: 'test' });
|
|
38
|
-
await firestore.collection('users').document('123').collection('subCollection').document('456').set({ data: 'test' });
|
|
39
|
-
await firestore.collection('teams').document('123').set({ data: 'test' });
|
|
40
|
-
await firestore.collection('teams').document('123').collection('subCollection').document('456').set({ data: 'test' });
|
|
41
|
-
await firestore.collection('other').document('123').set({ data: 'test' });
|
|
42
|
-
await firestore.collection('other').document('123').collection('subCollection').document('456').set({ data: 'test' });
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
it('should not allow to create users, teams or anything other', async () => {
|
|
46
|
-
await expectPermissionDenied(() => setDoc(doc(firestore, 'users/123'), { data: 'test' }));
|
|
47
|
-
await expectPermissionDenied(() => setDoc(doc(firestore, 'users/123/subCollection/456'), { data: 'test' }));
|
|
48
|
-
await expectPermissionDenied(() => setDoc(doc(firestore, 'teams/123'), { data: 'test' }));
|
|
49
|
-
await expectPermissionDenied(() => setDoc(doc(firestore, 'teams/123/subCollection/456'), { data: 'test' }));
|
|
50
|
-
await expectPermissionDenied(() => setDoc(doc(firestore, 'other/123'), { data: 'test' }));
|
|
51
|
-
await expectPermissionDenied(() => setDoc(doc(firestore, 'other/123/subCollection/456'), { data: 'test' }));
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('should not allow to update users, teams or anything other', async () => {
|
|
55
|
-
await createTestDocuments();
|
|
56
|
-
await expectPermissionDenied(() => updateDoc(doc(firestore, 'users/123'), { data: 'test' }));
|
|
57
|
-
await expectPermissionDenied(() => updateDoc(doc(firestore, 'users/123/subCollection/456'), { data: 'test' }));
|
|
58
|
-
await expectPermissionDenied(() => updateDoc(doc(firestore, 'teams/123'), { data: 'test' }));
|
|
59
|
-
await expectPermissionDenied(() => updateDoc(doc(firestore, 'teams/123/subCollection/456'), { data: 'test' }));
|
|
60
|
-
await expectPermissionDenied(() => updateDoc(doc(firestore, 'other/123'), { data: 'test' }));
|
|
61
|
-
await expectPermissionDenied(() => updateDoc(doc(firestore, 'other/123/subCollection/456'), { data: 'test' }));
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('should not allow to delete users, team or anything other', async () => {
|
|
65
|
-
await createTestDocuments();
|
|
66
|
-
await expectPermissionDenied(() => deleteDoc(doc(firestore, 'users/123')));
|
|
67
|
-
await expectPermissionDenied(() => deleteDoc(doc(firestore, 'users/123/subCollection/456')));
|
|
68
|
-
await expectPermissionDenied(() => deleteDoc(doc(firestore, 'teams/123')));
|
|
69
|
-
await expectPermissionDenied(() => deleteDoc(doc(firestore, 'teams/123/subCollection/456')));
|
|
70
|
-
await expectPermissionDenied(() => deleteDoc(doc(firestore, 'other/123')));
|
|
71
|
-
await expectPermissionDenied(() => deleteDoc(doc(firestore, 'other/123/subCollection/456')));
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it('should not allow to get users or anything other then teams', async () => {
|
|
75
|
-
await createTestDocuments();
|
|
76
|
-
await expectPermissionDenied(() => getDoc(doc(firestore, 'users/123')));
|
|
77
|
-
await expectPermissionDenied(() => getDoc(doc(firestore, 'users/123/subCollection/456')));
|
|
78
|
-
await expectPermissionDenied(() => getDoc(doc(firestore, 'other/123')));
|
|
79
|
-
await expectPermissionDenied(() => getDoc(doc(firestore, 'other/123/subCollection/456')));
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it('should not allow to list users or anything other then teams', async () => {
|
|
83
|
-
await createTestDocuments();
|
|
84
|
-
await expectPermissionDenied(() => getDocs(query(collection(firestore, 'users'))));
|
|
85
|
-
await expectPermissionDenied(() => getDocs(query(collection(firestore, 'users/123/subCollection'))));
|
|
86
|
-
await expectPermissionDenied(() => getDocs(query(collection(firestore, 'other'))));
|
|
87
|
-
await expectPermissionDenied(() => getDocs(query(collection(firestore, 'other/123/subCollection'))));
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it('should not allow to get teams if not authenticated', async () => {
|
|
91
|
-
await FirebaseApp.shared.auth.signOut();
|
|
92
|
-
await createTestDocuments();
|
|
93
|
-
await expectPermissionDenied(() => getDoc(doc(firestore, 'teams/123')));
|
|
94
|
-
await expectPermissionDenied(() => getDoc(doc(firestore, 'teams/123/subCollection/456')));
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('should not allow to get teams if auth does not exists', async () => {
|
|
98
|
-
await FirebaseApp.shared.auth.signIn();
|
|
99
|
-
await createTestDocuments();
|
|
100
|
-
await expectPermissionDenied(() => getDoc(doc(firestore, 'teams/123')));
|
|
101
|
-
await expectPermissionDenied(() => getDoc(doc(firestore, 'teams/123/subCollection/456')));
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it('should allow to get teams if user is not in team', async () => {
|
|
105
|
-
const userId = await FirebaseApp.shared.auth.signIn();
|
|
106
|
-
await FirebaseApp.shared.firestore.user(userId).set(new User(userId));
|
|
107
|
-
await createTestDocuments();
|
|
108
|
-
await expectPermissionDenied(() => getDoc(doc(firestore, 'teams/123')));
|
|
109
|
-
await expectPermissionDenied(() => getDoc(doc(firestore, 'teams/123/subCollection/456')));
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it('should allow to get teams if user is in team', async () => {
|
|
113
|
-
const userId = await FirebaseApp.shared.auth.signIn();
|
|
114
|
-
const user = new User(userId);
|
|
115
|
-
user.teams.set('123' as unknown as Team.Id, new User.TeamProperties('test', Tagged.generate('person')));
|
|
116
|
-
await FirebaseApp.shared.firestore.user(userId).set(user);
|
|
117
|
-
await createTestDocuments();
|
|
118
|
-
const snapshot1 = await getDoc(doc(firestore, 'teams/123'));
|
|
119
|
-
expect(snapshot1.exists()).toBeTrue();
|
|
120
|
-
expect(snapshot1.data()).toBeEqual({ data: 'test' });
|
|
121
|
-
const snapshot2 = await getDoc(doc(firestore, 'teams/123/subCollection/456'));
|
|
122
|
-
expect(snapshot2.exists()).toBeTrue();
|
|
123
|
-
expect(snapshot2.data()).toBeEqual({ data: 'test' });
|
|
124
|
-
});
|
|
125
|
-
});
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { FirebaseApp } from '../../FirebaseApp';
|
|
2
|
-
import { expect } from '@assertive-ts/core';
|
|
3
|
-
import { Result } from '@stevenkellner/typescript-common-functionality';
|
|
4
|
-
import { FunctionsError } from '@stevenkellner/firebase-function';
|
|
5
|
-
import { RandomData } from '../../RandomData';
|
|
6
|
-
|
|
7
|
-
describe('FineAddFunction', () => {
|
|
8
|
-
|
|
9
|
-
beforeEach(async () => {
|
|
10
|
-
await FirebaseApp.shared.addTestTeam('fine-manager');
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
afterEach(async () => {
|
|
14
|
-
await FirebaseApp.shared.firestore.clear();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('person does not exist', async () => {
|
|
18
|
-
const result = await FirebaseApp.shared.functions.fine.add.executeWithResult({
|
|
19
|
-
teamId: FirebaseApp.shared.testTeam.id,
|
|
20
|
-
personId: RandomData.shared.personId(),
|
|
21
|
-
fine: RandomData.shared.fine(),
|
|
22
|
-
configuration: FirebaseApp.shared.testConfiguration
|
|
23
|
-
});
|
|
24
|
-
expect(result).toBeEqual(Result.failure(new FunctionsError('not-found', 'Person not found')));
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('fine already exists', async () => {
|
|
28
|
-
const result = await FirebaseApp.shared.functions.fine.add.executeWithResult({
|
|
29
|
-
teamId: FirebaseApp.shared.testTeam.id,
|
|
30
|
-
personId: FirebaseApp.shared.testTeam.persons[1].id,
|
|
31
|
-
fine: RandomData.shared.fine(FirebaseApp.shared.testTeam.fines[1].id),
|
|
32
|
-
configuration: FirebaseApp.shared.testConfiguration
|
|
33
|
-
});
|
|
34
|
-
expect(result).toBeEqual(Result.failure(new FunctionsError('already-exists', 'Fine already exists')));
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('should add fine', async () => {
|
|
38
|
-
const fine = RandomData.shared.fine();
|
|
39
|
-
await FirebaseApp.shared.functions.fine.add.execute({
|
|
40
|
-
teamId: FirebaseApp.shared.testTeam.id,
|
|
41
|
-
personId: FirebaseApp.shared.testTeam.persons[0].id,
|
|
42
|
-
fine: fine,
|
|
43
|
-
configuration: FirebaseApp.shared.testConfiguration
|
|
44
|
-
});
|
|
45
|
-
const fineSnapshot = await FirebaseApp.shared.firestore.fine(FirebaseApp.shared.testTeam.id, fine.id).snapshot();
|
|
46
|
-
expect(fineSnapshot.exists).toBeTrue();
|
|
47
|
-
expect(fineSnapshot.data).toBeEqual(fine.flatten);
|
|
48
|
-
const personSnapshot = await FirebaseApp.shared.firestore.person(FirebaseApp.shared.testTeam.id, FirebaseApp.shared.testTeam.persons[0].id).snapshot();
|
|
49
|
-
expect(personSnapshot.exists).toBeTrue();
|
|
50
|
-
expect(personSnapshot.data.fineIds).toContainAll(fine.id.guidString);
|
|
51
|
-
});
|
|
52
|
-
});
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { FunctionsError } from '@stevenkellner/firebase-function';
|
|
2
|
-
import { FirebaseApp } from '../../FirebaseApp';
|
|
3
|
-
import { RandomData } from '../../RandomData';
|
|
4
|
-
import { Result } from '@stevenkellner/typescript-common-functionality';
|
|
5
|
-
import { expect } from '@assertive-ts/core';
|
|
6
|
-
|
|
7
|
-
describe('FineDeleteFunction', () => {
|
|
8
|
-
|
|
9
|
-
beforeEach(async () => {
|
|
10
|
-
await FirebaseApp.shared.addTestTeam('fine-manager');
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
afterEach(async () => {
|
|
14
|
-
await FirebaseApp.shared.firestore.clear();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('person does not exist', async () => {
|
|
18
|
-
const result = await FirebaseApp.shared.functions.fine.delete.executeWithResult({
|
|
19
|
-
teamId: FirebaseApp.shared.testTeam.id,
|
|
20
|
-
personId: RandomData.shared.personId(),
|
|
21
|
-
id: FirebaseApp.shared.testTeam.fines[1].id,
|
|
22
|
-
configuration: FirebaseApp.shared.testConfiguration
|
|
23
|
-
});
|
|
24
|
-
expect(result).toBeEqual(Result.failure(new FunctionsError('not-found', 'Person not found')));
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('fine does not exist', async () => {
|
|
28
|
-
const result = await FirebaseApp.shared.functions.fine.delete.executeWithResult({
|
|
29
|
-
teamId: FirebaseApp.shared.testTeam.id,
|
|
30
|
-
personId: FirebaseApp.shared.testTeam.persons[1].id,
|
|
31
|
-
id: RandomData.shared.fineId(),
|
|
32
|
-
configuration: FirebaseApp.shared.testConfiguration
|
|
33
|
-
});
|
|
34
|
-
expect(result).toBeEqual(Result.failure(new FunctionsError('not-found', 'Fine not found')));
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('should delete fine', async () => {
|
|
38
|
-
await FirebaseApp.shared.functions.fine.delete.execute({
|
|
39
|
-
teamId: FirebaseApp.shared.testTeam.id,
|
|
40
|
-
personId: FirebaseApp.shared.testTeam.persons[0].id,
|
|
41
|
-
id: FirebaseApp.shared.testTeam.fines[1].id,
|
|
42
|
-
configuration: FirebaseApp.shared.testConfiguration
|
|
43
|
-
});
|
|
44
|
-
const fineSnapshot = await FirebaseApp.shared.firestore.fine(FirebaseApp.shared.testTeam.id, FirebaseApp.shared.testTeam.fines[1].id).snapshot();
|
|
45
|
-
expect(fineSnapshot.exists).toBeFalse();
|
|
46
|
-
const personSnapshot = await FirebaseApp.shared.firestore.person(FirebaseApp.shared.testTeam.id, FirebaseApp.shared.testTeam.persons[0].id).snapshot();
|
|
47
|
-
expect(personSnapshot.exists).toBeTrue();
|
|
48
|
-
expect(personSnapshot.data.fineIds).not.toContainAny(FirebaseApp.shared.testTeam.fines[1].id.guidString);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { expect } from '@assertive-ts/core';
|
|
2
|
-
import { FirebaseApp } from '../../FirebaseApp';
|
|
3
|
-
import { RandomData } from '../../RandomData';
|
|
4
|
-
import { Result } from '@stevenkellner/typescript-common-functionality';
|
|
5
|
-
import { FunctionsError } from '@stevenkellner/firebase-function';
|
|
6
|
-
|
|
7
|
-
describe('FineUpdateFunction', () => {
|
|
8
|
-
|
|
9
|
-
beforeEach(async () => {
|
|
10
|
-
await FirebaseApp.shared.addTestTeam('fine-manager');
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
afterEach(async () => {
|
|
14
|
-
await FirebaseApp.shared.firestore.clear();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('fine not found', async () => {
|
|
18
|
-
const result = await FirebaseApp.shared.functions.fine.update.executeWithResult({
|
|
19
|
-
teamId: FirebaseApp.shared.testTeam.id,
|
|
20
|
-
personId: RandomData.shared.personId(),
|
|
21
|
-
fine: RandomData.shared.fine(),
|
|
22
|
-
configuration: FirebaseApp.shared.testConfiguration
|
|
23
|
-
});
|
|
24
|
-
expect(result).toBeEqual(Result.failure(new FunctionsError('not-found', 'Fine not found')));
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('should update fine', async () => {
|
|
28
|
-
const fine = RandomData.shared.fine(FirebaseApp.shared.testTeam.fines[1].id);
|
|
29
|
-
await FirebaseApp.shared.functions.fine.update.execute({
|
|
30
|
-
teamId: FirebaseApp.shared.testTeam.id,
|
|
31
|
-
personId: FirebaseApp.shared.testTeam.persons[0].id,
|
|
32
|
-
fine: fine,
|
|
33
|
-
configuration: FirebaseApp.shared.testConfiguration
|
|
34
|
-
});
|
|
35
|
-
const fineSnapshot = await FirebaseApp.shared.firestore.fine(FirebaseApp.shared.testTeam.id, FirebaseApp.shared.testTeam.fines[1].id).snapshot();
|
|
36
|
-
expect(fineSnapshot.exists).toBeTrue();
|
|
37
|
-
expect(fineSnapshot.data).toBeEqual(fine.flatten);
|
|
38
|
-
});
|
|
39
|
-
});
|
|
@@ -1,35 +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('FineTemplateAddFunction', () => {
|
|
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('fineTemplate already exists', async () => {
|
|
18
|
-
const result = await FirebaseApp.shared.functions.fineTemplate.add.executeWithResult({
|
|
19
|
-
teamId: FirebaseApp.shared.testTeam.id,
|
|
20
|
-
fineTemplate: RandomData.shared.fineTemplate(FirebaseApp.shared.testTeam.fineTemplates[1].id)
|
|
21
|
-
});
|
|
22
|
-
expect(result).toBeEqual(Result.failure(new FunctionsError('already-exists', 'FineTemplate already exists')));
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('should add fineTemplate', async () => {
|
|
26
|
-
const fineTemplate = RandomData.shared.fineTemplate();
|
|
27
|
-
await FirebaseApp.shared.functions.fineTemplate.add.execute({
|
|
28
|
-
teamId: FirebaseApp.shared.testTeam.id,
|
|
29
|
-
fineTemplate: fineTemplate
|
|
30
|
-
});
|
|
31
|
-
const fineTemplateSnapshot = await FirebaseApp.shared.firestore.fineTemplate(FirebaseApp.shared.testTeam.id, fineTemplate.id).snapshot();
|
|
32
|
-
expect(fineTemplateSnapshot.exists).toBeTrue();
|
|
33
|
-
expect(fineTemplateSnapshot.data).toBeEqual(fineTemplate.flatten);
|
|
34
|
-
});
|
|
35
|
-
});
|
|
@@ -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 { RandomData } from '../../RandomData';
|
|
6
|
-
|
|
7
|
-
describe('FineTemplateDeleteFunction', () => {
|
|
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('fineTemplate not found', async () => {
|
|
18
|
-
const result = await FirebaseApp.shared.functions.fineTemplate.delete.executeWithResult({
|
|
19
|
-
teamId: FirebaseApp.shared.testTeam.id,
|
|
20
|
-
id: RandomData.shared.fineTemplateId()
|
|
21
|
-
});
|
|
22
|
-
expect(result).toBeEqual(Result.failure(new FunctionsError('not-found', 'FineTemplate not found')));
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('should delete fineTemplate', async () => {
|
|
26
|
-
await FirebaseApp.shared.functions.fineTemplate.delete.execute({
|
|
27
|
-
teamId: FirebaseApp.shared.testTeam.id,
|
|
28
|
-
id: FirebaseApp.shared.testTeam.fineTemplates[1].id
|
|
29
|
-
});
|
|
30
|
-
const fineTemplateSnapshot = await FirebaseApp.shared.firestore.fineTemplate(FirebaseApp.shared.testTeam.id, FirebaseApp.shared.testTeam.fineTemplates[1].id).snapshot();
|
|
31
|
-
expect(fineTemplateSnapshot.exists).toBeFalse();
|
|
32
|
-
});
|
|
33
|
-
});
|
|
@@ -1,35 +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('FineTemplateUpdateFunction', () => {
|
|
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('fineTemplate not found', async () => {
|
|
18
|
-
const result = await FirebaseApp.shared.functions.fineTemplate.update.executeWithResult({
|
|
19
|
-
teamId: FirebaseApp.shared.testTeam.id,
|
|
20
|
-
fineTemplate: RandomData.shared.fineTemplate()
|
|
21
|
-
});
|
|
22
|
-
expect(result).toBeEqual(Result.failure(new FunctionsError('not-found', 'FineTemplate not found')));
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('should update fineTemplate', async () => {
|
|
26
|
-
const fineTemplate = RandomData.shared.fineTemplate(FirebaseApp.shared.testTeam.fineTemplates[1].id);
|
|
27
|
-
await FirebaseApp.shared.functions.fineTemplate.update.execute({
|
|
28
|
-
teamId: FirebaseApp.shared.testTeam.id,
|
|
29
|
-
fineTemplate: fineTemplate
|
|
30
|
-
});
|
|
31
|
-
const fineTemplateSnapshot = await FirebaseApp.shared.firestore.fineTemplate(FirebaseApp.shared.testTeam.id, FirebaseApp.shared.testTeam.fineTemplates[1].id).snapshot();
|
|
32
|
-
expect(fineTemplateSnapshot.exists).toBeTrue();
|
|
33
|
-
expect(fineTemplateSnapshot.data).toBeEqual(fineTemplate.flatten);
|
|
34
|
-
});
|
|
35
|
-
});
|
|
@@ -1,48 +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 { Invitation } from '../../../src/types';
|
|
7
|
-
|
|
8
|
-
describe('InvitationInviteFunction', () => {
|
|
9
|
-
|
|
10
|
-
beforeEach(async () => {
|
|
11
|
-
await FirebaseApp.shared.addTestTeam('team-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.invitation.invite.executeWithResult(new Invitation(
|
|
20
|
-
FirebaseApp.shared.testTeam.id,
|
|
21
|
-
RandomData.shared.personId()
|
|
22
|
-
));
|
|
23
|
-
expect(result).toBeEqual(Result.failure(new FunctionsError('not-found', 'Person not found')));
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('person already has an account', async () => {
|
|
27
|
-
const result = await FirebaseApp.shared.functions.invitation.invite.executeWithResult(new Invitation(
|
|
28
|
-
FirebaseApp.shared.testTeam.id,
|
|
29
|
-
FirebaseApp.shared.testTeam.persons[0].id
|
|
30
|
-
));
|
|
31
|
-
expect(result).toBeEqual(Result.failure(new FunctionsError('already-exists', 'Person already has an account')));
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('should invite', async () => {
|
|
35
|
-
const invitation = new Invitation(
|
|
36
|
-
FirebaseApp.shared.testTeam.id,
|
|
37
|
-
FirebaseApp.shared.testTeam.persons[1].id
|
|
38
|
-
);
|
|
39
|
-
const invitationId = await FirebaseApp.shared.functions.invitation.invite.execute(invitation);
|
|
40
|
-
expect(invitationId).toBeEqual(invitation.createId());
|
|
41
|
-
const invitationSnapshot = await FirebaseApp.shared.firestore.invitation(invitationId).snapshot();
|
|
42
|
-
expect(invitationSnapshot.exists).toBeTrue();
|
|
43
|
-
expect(invitationSnapshot.data).toBeEqual({
|
|
44
|
-
teamId: FirebaseApp.shared.testTeam.id.guidString,
|
|
45
|
-
personId: FirebaseApp.shared.testTeam.persons[1].id.guidString
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
});
|