@sneat/space-services 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,308 @@
1
+ import { Injector, runInInjectionContext } from '@angular/core';
2
+ import {
3
+ Firestore as AngularFirestore,
4
+ doc,
5
+ collection,
6
+ CollectionReference,
7
+ } from '@angular/fire/firestore';
8
+ import { QuerySnapshot } from '@firebase/firestore-types';
9
+ import { IQueryArgs, SneatApiService, SneatFirestoreService } from '@sneat/api';
10
+ import {
11
+ IIdAndBriefAndDbo,
12
+ IIdAndOptionalBriefAndOptionalDbo,
13
+ ISpaceItemWithBriefAndDbo,
14
+ ISpaceRef,
15
+ } from '@sneat/core';
16
+ import { ISpaceDbo } from '@sneat/dto';
17
+ import { ISpaceItemNavContext, ISpaceRequest } from '@sneat/space-models';
18
+ import { Observable } from 'rxjs';
19
+ import { map } from 'rxjs/operators';
20
+
21
+ type ICreateSpaceItemResponse<
22
+ Brief,
23
+ Dbo extends Brief,
24
+ > = ISpaceItemWithBriefAndDbo<Brief, Dbo>;
25
+
26
+ abstract class SpaceItemBaseService<Brief, Dbo extends Brief> {
27
+ protected readonly sfs: SneatFirestoreService<Brief, Dbo>;
28
+
29
+ protected constructor(
30
+ protected readonly injector: Injector,
31
+ public readonly collectionName: string,
32
+ public readonly afs: AngularFirestore,
33
+ public readonly sneatApiService: SneatApiService,
34
+ ) {
35
+ if (!this.collectionName) {
36
+ throw new Error('collectionName is required');
37
+ }
38
+ this.sfs = new SneatFirestoreService<Brief, Dbo>(this.injector);
39
+ }
40
+
41
+ private _collectionRef?: CollectionReference<Dbo>;
42
+
43
+ protected abstract collectionRef<Dbo2 extends Dbo>(
44
+ spaceID: string,
45
+ ): CollectionReference<Dbo2>;
46
+
47
+ public watchSpaceItemByIdWithSpaceRef<Dbo2 extends Dbo>(
48
+ space: ISpaceRef,
49
+ itemID: string,
50
+ ): Observable<ISpaceItemNavContext<Brief, Dbo2>> {
51
+
52
+ if (!space.id) {
53
+ throw new Error('spaceID is required');
54
+ }
55
+ let collectionRef: CollectionReference<Dbo2>;
56
+ if (this._collectionRef?.id == space.id) {
57
+ collectionRef = this._collectionRef as CollectionReference<Dbo2>;
58
+ } else {
59
+ collectionRef = this.collectionRef<Dbo2>(space.id);
60
+ this._collectionRef = collectionRef;
61
+ }
62
+ return runInInjectionContext(this.injector, () =>
63
+ this.sfs
64
+ .watchByID(collectionRef, itemID)
65
+ .pipe(map((o) => ({ space, ...o }))),
66
+ );
67
+ }
68
+
69
+ protected queryItems<Dbo2 extends Dbo>(
70
+ collectionRef: CollectionReference<Dbo2>,
71
+ queryArgs?: IQueryArgs,
72
+ ): Observable<IIdAndBriefAndDbo<Brief, Dbo2>[]> {
73
+ const $querySnapshot = this.sfs.watchSnapshotsByFilter<Dbo2>(
74
+ collectionRef,
75
+ queryArgs,
76
+ );
77
+ return $querySnapshot.pipe(
78
+ map((querySnapshot) => {
79
+ return this.mapQueryItem<Dbo2>(
80
+ querySnapshot as unknown as QuerySnapshot<Dbo2>,
81
+ );
82
+ }),
83
+ );
84
+ }
85
+
86
+ protected mapQueryItem<Dbo2 extends Dbo>(
87
+ querySnapshot: QuerySnapshot<Dbo2>,
88
+ ): IIdAndBriefAndDbo<Brief, Dbo2>[] {
89
+ return querySnapshot.docs.map((docSnapshot) => {
90
+ const dto = docSnapshot.data();
91
+ const { id } = docSnapshot;
92
+ const brief: Brief = dto;
93
+ return { id, brief, dbo: dto };
94
+ });
95
+ }
96
+
97
+ public deleteSpaceItem<Response>(
98
+ endpoint: string,
99
+ request: ISpaceRequest,
100
+ ): Observable<Response> {
101
+ return this.sneatApiService.delete<Response>(endpoint, undefined, request);
102
+ }
103
+
104
+ public createSpaceItem<Brief, Dbo extends Brief>(
105
+ endpoint: string,
106
+ spaceRef: ISpaceRef,
107
+ request: ISpaceRequest,
108
+ ): Observable<ISpaceItemWithBriefAndDbo<Brief, Dbo>> {
109
+ return this.sneatApiService
110
+ .post<ICreateSpaceItemResponse<Brief, Dbo>>(endpoint, request)
111
+ .pipe(
112
+ map((response) => {
113
+ if (!response) {
114
+ throw new Error('create team item response is empty');
115
+ }
116
+ if (!response.id) {
117
+ throw new Error('create team item response have no ID');
118
+ }
119
+ const item: ISpaceItemWithBriefAndDbo<Brief, Dbo> = {
120
+ space: spaceRef,
121
+ id: response.id,
122
+ dbo: response.dbo,
123
+ brief: { id: response.id, ...response.dbo } as unknown as Brief,
124
+ };
125
+ return item;
126
+ }),
127
+ );
128
+ }
129
+ }
130
+
131
+ // At the moment reserved to `happenings` only
132
+ export class GlobalSpaceItemService<
133
+ Brief,
134
+ Dbo extends Brief,
135
+ > extends SpaceItemBaseService<Brief, Dbo> {
136
+ protected override collectionRef<
137
+ Dbo2 extends Dbo,
138
+ >(): CollectionReference<Dbo2> {
139
+ return runInInjectionContext(
140
+ this.injector,
141
+ () =>
142
+ collection(this.afs, this.collectionName) as CollectionReference<Dbo2>,
143
+ );
144
+ }
145
+
146
+ public watchGlobalItems<Dbo2 extends Dbo>(
147
+ queryArgs: IQueryArgs,
148
+ ): Observable<IIdAndBriefAndDbo<Brief, Dbo2>[]> {
149
+ const collectionRef = this.collectionRef<Dbo2>();
150
+ return this.queryItems<Dbo2>(collectionRef, queryArgs);
151
+ }
152
+
153
+ public watchGlobalSpaceItemsWithSpaceRef<Dbo2 extends Dbo>(
154
+ space: ISpaceRef,
155
+ queryArgs: IQueryArgs,
156
+ ): Observable<ISpaceItemWithBriefAndDbo<Brief, Dbo2>[]> {
157
+ return this.watchGlobalSpaceItems<Dbo2>(space.id, queryArgs).pipe(
158
+ map((items) => items.map((item) => ({ ...item, space }))),
159
+ );
160
+ }
161
+
162
+ public watchGlobalSpaceItems<Dbo2 extends Dbo>(
163
+ spaceID: string,
164
+ queryArgs: IQueryArgs,
165
+ ): Observable<IIdAndBriefAndDbo<Brief, Dbo2>[]> {
166
+ queryArgs = {
167
+ ...queryArgs,
168
+ filter: [
169
+ ...(queryArgs?.filter || []),
170
+ { field: 'spaceIDs', operator: '==', value: spaceID },
171
+ ],
172
+ };
173
+ const collectionRef = this.collectionRef<Dbo2>();
174
+ return this.queryItems<Dbo2>(collectionRef, queryArgs);
175
+ }
176
+ }
177
+
178
+ // intentionally not abstract
179
+ export class ModuleSpaceItemService<
180
+ Brief,
181
+ Dbo extends Brief,
182
+ > extends SpaceItemBaseService<Brief, Dbo> {
183
+ protected readonly spacesCollection: CollectionReference<ISpaceDbo>;
184
+
185
+ constructor(
186
+ injector: Injector,
187
+ public readonly moduleID: string,
188
+ collectionName: string,
189
+ afs: AngularFirestore,
190
+ sneatApiService: SneatApiService,
191
+ ) {
192
+ super(injector, collectionName, afs, sneatApiService);
193
+ if (!moduleID) {
194
+ throw new Error('moduleID is required');
195
+ }
196
+ this.spacesCollection = collection(
197
+ this.afs,
198
+ 'spaces',
199
+ ) as CollectionReference<ISpaceDbo>;
200
+ }
201
+
202
+ protected readonly dto2brief = (id: string, dto: Dbo) => ({ id, ...dto });
203
+
204
+ // protected teamCollection(spaceID: string): AngularFirestoreCollection<ITeamDto> {
205
+ // return this.afs.collection('spaces');
206
+ // }
207
+
208
+ protected override collectionRef<Dbo2 extends Dbo>(
209
+ spaceID: string,
210
+ ): CollectionReference<Dbo2> {
211
+ if (!spaceID) {
212
+ throw new Error('spaceID is required');
213
+ }
214
+ return runInInjectionContext(
215
+ this.injector,
216
+ () =>
217
+ collection(
218
+ this.spacesCollection,
219
+ spaceID,
220
+ 'ext',
221
+ this.moduleID,
222
+ this.collectionName,
223
+ ) as CollectionReference<Dbo2>,
224
+ );
225
+ }
226
+
227
+ private readonly spaceRef = (id: string) => doc(this.spacesCollection, id);
228
+
229
+ public watchModuleSpaceItem<Dbo2 extends Dbo>(
230
+ space: ISpaceRef,
231
+ itemID: string,
232
+ ): Observable<IIdAndOptionalBriefAndOptionalDbo<Brief, Dbo2>> {
233
+ const collection = this.collectionRef<Dbo2>(space.id);
234
+ return this.sfs.watchByID<Dbo2>(collection, itemID);
235
+ }
236
+
237
+ public watchModuleSpaceItemsWithSpaceRef<Dbo2 extends Dbo>(
238
+ space: ISpaceRef,
239
+ queryArgs?: IQueryArgs,
240
+ ): Observable<ISpaceItemWithBriefAndDbo<Brief, Dbo2>[]> {
241
+ return this.watchModuleSpaceItems<Dbo2>(space.id, queryArgs).pipe(
242
+ map((items) => items.map((item) => ({ ...item, space }))),
243
+ );
244
+ }
245
+
246
+ public watchModuleSpaceItems<Dbo2 extends Dbo>(
247
+ spaceID: string,
248
+ queryArgs?: IQueryArgs,
249
+ ): Observable<IIdAndBriefAndDbo<Brief, Dbo2>[]> {
250
+ // filter = [
251
+ // ...(filter || []),
252
+ // // { field: 'spaceIDs', operator: '==', value: spaceID },
253
+ // ];
254
+ return runInInjectionContext(this.injector, () => {
255
+ const collectionRef = this.collectionRef<Dbo2>(spaceID);
256
+ return this.queryItems<Dbo2>(collectionRef, queryArgs);
257
+ });
258
+ }
259
+
260
+ // private readonly mapItemTeamItemContext = <
261
+ // Brief2 extends Brief,
262
+ // Dbo2 extends Dto,
263
+ // >(
264
+ // space: ISpaceContext,
265
+ // item: IIdAndBrief<Brief2, Dbo2>,
266
+ // ) => {
267
+ // return querySnapshot.docs.map((docSnapshot) => {
268
+ // const dto = docSnapshot.data();
269
+ // const { id } = docSnapshot;
270
+ // const brief: Brief2 = { id, ...dto } as unknown as Brief2;
271
+ // const c: ISpaceItemContext<Brief2, Dbo2> = { id, team, dto, brief };
272
+ // return c;
273
+ // });
274
+ // };
275
+
276
+ // public watchSpaceItems<Brief2 extends Brief, Dbo2 extends Dto>(
277
+ // spaceID: string,
278
+ // filter?: readonly IFilter[],
279
+ // ): Observable<IIdAndBriefAndDto<Brief2, Dbo2>[]> {
280
+ // console.log('watchSpaceItems()', spaceID, this.collectionName);
281
+ // const collectionRef = collection(
282
+ // this.teamRef(spaceID),
283
+ // this.collectionName,
284
+ // );
285
+ // const querySnapshots = this.sfs.watchSnapshotsByFilter<Dbo2>(
286
+ // collectionRef as CollectionReference<Dbo2>,
287
+ // filter || [],
288
+ // );
289
+ // return querySnapshots.pipe(
290
+ // map(a => this.mapQueryItem(a)),
291
+ // );
292
+ // }
293
+
294
+ // public watchTeamItemsWithSpaceContext<Brief2 extends Brief, Dbo2 extends Dto>(
295
+ // space: ISpaceRef,
296
+ // filter?: readonly IFilter[],
297
+ // ): Observable<ISpaceItemContext<Brief2, Dbo2>[]> {
298
+ // const querySnapshots = this.watchTeamItems(space.id, filter);
299
+ // return querySnapshots.pipe(
300
+ // map((querySnapshot) =>
301
+ // this.mapItemSpaceItemContext(
302
+ // team,
303
+ // querySnapshot as unknown as QuerySnapshot<Dbo2>,
304
+ // ),
305
+ // ),
306
+ // );
307
+ // }
308
+ }
@@ -0,0 +1,48 @@
1
+ import { TestBed } from '@angular/core/testing';
2
+ import { Injector } from '@angular/core';
3
+ import { Firestore, collection } from '@angular/fire/firestore';
4
+ import { SpaceModuleService } from './space-module.service';
5
+
6
+ // Mock collection function
7
+ vi.mock('@angular/fire/firestore', async () => {
8
+ const actual = await vi.importActual('@angular/fire/firestore');
9
+ return {
10
+ ...actual,
11
+ collection: vi.fn(() => ({ id: 'mock-collection' })),
12
+ };
13
+ });
14
+
15
+ class TestSpaceModuleService extends SpaceModuleService<{ title: string }> {
16
+ constructor(injector: Injector, afs: Firestore) {
17
+ super(injector, 'test-module', afs);
18
+ }
19
+ }
20
+
21
+ describe('SpaceModuleService', () => {
22
+ let service: TestSpaceModuleService;
23
+ let mockFirestore: Firestore;
24
+
25
+ beforeEach(() => {
26
+ mockFirestore = {
27
+ type: 'Firestore',
28
+ toJSON: () => ({}),
29
+ } as unknown as Firestore;
30
+
31
+ vi.mocked(collection).mockReturnValue({ id: 'spaces' } as unknown);
32
+
33
+ const injector = TestBed.inject(Injector);
34
+ service = new TestSpaceModuleService(injector, mockFirestore);
35
+ });
36
+
37
+ it('should be created', () => {
38
+ expect(service).toBeTruthy();
39
+ });
40
+
41
+ it('should have correct moduleID', () => {
42
+ expect(service.moduleID).toBe('test-module');
43
+ });
44
+
45
+ it('should have correct collectionName', () => {
46
+ expect(service.collectionName).toBe('ext');
47
+ });
48
+ });
@@ -0,0 +1,69 @@
1
+ import { Injector, runInInjectionContext } from '@angular/core';
2
+ import {
3
+ collection,
4
+ CollectionReference,
5
+ Firestore as AngularFirestore,
6
+ } from '@angular/fire/firestore';
7
+ import { SneatApiService } from '@sneat/api';
8
+ import { IIdAndBrief, IIdAndOptionalDbo } from '@sneat/core';
9
+ import { Observable } from 'rxjs';
10
+ import { map } from 'rxjs/operators';
11
+ import { ModuleSpaceItemService } from './space-item.service';
12
+
13
+ // import firebase from "firebase/compat";
14
+ // import Item = firebase.analytics.Item;
15
+
16
+ export abstract class SpaceModuleService<Dbo> extends ModuleSpaceItemService<
17
+ Dbo,
18
+ Dbo
19
+ > {
20
+ // protected readonly sfs: SneatFirestoreService<Brief, Dto>;
21
+ protected constructor(
22
+ injector: Injector,
23
+ moduleID: string,
24
+ afs: AngularFirestore,
25
+ ) {
26
+ // this.sfs = new SneatFirestoreService<Brief, Dto>(collectionName, afs);
27
+ super(
28
+ injector,
29
+ moduleID,
30
+ 'ext',
31
+ afs,
32
+ undefined as unknown as SneatApiService,
33
+ );
34
+ }
35
+
36
+ watchSpaceModuleRecord(spaceID: string): Observable<IIdAndOptionalDbo<Dbo>> {
37
+ return runInInjectionContext(this.injector, () => {
38
+ const collectionRef = collection(
39
+ this.spacesCollection,
40
+ spaceID,
41
+ 'ext',
42
+ ) as CollectionReference<Dbo>;
43
+ // if (this.moduleID === 'trackus') {
44
+ // return throwError(() => new Error('test error'));
45
+ // }
46
+ return this.sfs
47
+ .watchByID<Dbo>(collectionRef, this.moduleID)
48
+ .pipe
49
+ // tap((o) => console.log(`${logPrefix} =>`, o)),
50
+ ();
51
+ });
52
+ }
53
+
54
+ watchBriefs<ItemBrief>(
55
+ spaceID: string,
56
+ getBriefs: (dto?: Dbo) => Readonly<Record<string, ItemBrief>>,
57
+ ): Observable<IIdAndBrief<ItemBrief>[]> {
58
+ const o = this.watchSpaceModuleRecord(spaceID);
59
+ return o.pipe(
60
+ map((teamModule) => {
61
+ const briefs = getBriefs(teamModule?.dbo || undefined);
62
+ const items: IIdAndBrief<ItemBrief>[] = briefs
63
+ ? Object.keys(briefs).map((id) => ({ id, brief: briefs[id] }))
64
+ : [];
65
+ return items;
66
+ }),
67
+ );
68
+ }
69
+ }
@@ -0,0 +1,32 @@
1
+ import { TestBed } from '@angular/core/testing';
2
+ import { provideRouter } from '@angular/router';
3
+ import { SpaceNavService } from './space-nav.service';
4
+ import { ErrorLogger } from '@sneat/core';
5
+ import { AnalyticsService } from '@sneat/core';
6
+ import { NavController } from '@ionic/angular';
7
+
8
+ describe('SpaceNavService', () => {
9
+ beforeEach(() =>
10
+ TestBed.configureTestingModule({
11
+ providers: [
12
+ SpaceNavService,
13
+ provideRouter([]),
14
+ { provide: ErrorLogger, useValue: { logError: vi.fn() } },
15
+ { provide: AnalyticsService, useValue: { logEvent: vi.fn() } },
16
+ {
17
+ provide: NavController,
18
+ useValue: {
19
+ navigateRoot: vi.fn().mockResolvedValue(true),
20
+ navigateForward: vi.fn().mockResolvedValue(true),
21
+ navigateBack: vi.fn().mockResolvedValue(true),
22
+ },
23
+ },
24
+ ],
25
+ }),
26
+ );
27
+
28
+ it('should be created', () => {
29
+ const service: SpaceNavService = TestBed.inject(SpaceNavService);
30
+ expect(service).toBeTruthy();
31
+ });
32
+ });
@@ -0,0 +1,175 @@
1
+ import { Injectable, inject } from '@angular/core';
2
+ import { Params } from '@angular/router';
3
+ import { NavController } from '@ionic/angular';
4
+ import { AnalyticsService, IAnalyticsService, IIdAndBrief, ISpaceRef } from '@sneat/core';
5
+ import { IMemberBrief } from '@sneat/contactus-core';
6
+
7
+ type NavigationOptions = NonNullable<
8
+ Parameters<NavController['navigateRoot']>[1]
9
+ >;
10
+ import { IRecord } from '@sneat/data';
11
+ import { ISpaceDbo } from '@sneat/dto';
12
+ import { ErrorLogger, IErrorLogger } from '@sneat/core';
13
+ import { ISpaceContext } from '@sneat/space-models';
14
+
15
+ export type ScrumPageTab = 'team' | 'my' | 'risks' | 'qna';
16
+
17
+ @Injectable({
18
+ providedIn: 'root',
19
+ })
20
+ export class SpaceNavService {
21
+ private readonly errorLogger = inject<IErrorLogger>(ErrorLogger);
22
+ private readonly navController = inject(NavController);
23
+ private readonly analyticsService =
24
+ inject<IAnalyticsService>(AnalyticsService);
25
+
26
+ public navigateToSpaces(animationDirection?: 'forward' | 'back'): void {
27
+ this.analyticsService.logEvent('navigateToTeams');
28
+ this.navController
29
+ .navigateRoot('spaces', { animationDirection })
30
+ .catch((err) =>
31
+ this.errorLogger.logError(err, 'Failed to navigate to teams page'),
32
+ );
33
+ }
34
+
35
+ public navigateToLogin(options?: {
36
+ returnTo?: string;
37
+ queryParams?: Params;
38
+ // fragment?: string;
39
+ }): void {
40
+
41
+ // Do not log `returnTo` as it might holds sensitive info
42
+ this.analyticsService.logEvent('navigateToLogin');
43
+
44
+ const navOptions: NavigationOptions = {
45
+ queryParams: options?.queryParams,
46
+ animationDirection: 'back',
47
+ };
48
+ if (options?.returnTo) {
49
+ navOptions.fragment = options.returnTo;
50
+ }
51
+ this.navController
52
+ .navigateRoot('login', navOptions)
53
+ .catch((err) =>
54
+ this.errorLogger.logError(err, 'Failed to navigate to login page'),
55
+ );
56
+ }
57
+
58
+ public navigateToUserProfile(): void {
59
+ this.analyticsService.logEvent('navigateToUserProfile');
60
+ this.navController
61
+ .navigateRoot('user-profile')
62
+ .catch((err) =>
63
+ this.errorLogger.logError(err, 'Failed to naviage to user profile'),
64
+ );
65
+ }
66
+
67
+ public navigateToSpace(
68
+ space: ISpaceContext,
69
+ animationDirection?: 'forward' | 'back',
70
+ ): Promise<boolean> {
71
+ this.analyticsService.logEvent('navigateToSpace', { spaceID: space.id });
72
+ const url = `space/${space.type || space.brief?.type}/${space.id}`;
73
+ return new Promise<boolean>((resolve, reject) => {
74
+ this.navController
75
+ .navigateRoot(url, {
76
+ state: { space },
77
+ animationDirection,
78
+ })
79
+ .then(resolve)
80
+ .catch((err) => {
81
+ this.errorLogger.logError(
82
+ err,
83
+ 'Failed to navigate to team overview page with URL: ' + url,
84
+ );
85
+ reject(err);
86
+ });
87
+ });
88
+ }
89
+
90
+ public navigateToMember(
91
+ space: ISpaceContext,
92
+ memberInfo: IIdAndBrief<IMemberBrief>,
93
+ ): void {
94
+ const id = `${space.id}:${memberInfo.id}`;
95
+ this.navForward(
96
+ this.navController,
97
+ 'member',
98
+ {
99
+ queryParams: { id },
100
+ state: { space, memberInfo },
101
+ },
102
+ );
103
+ }
104
+
105
+ public navigateToAddMetric = (
106
+ navController: NavController,
107
+ team: IRecord<ISpaceDbo>,
108
+ ): void =>
109
+ this.navToSpacePage(
110
+ navController,
111
+ team,
112
+ 'add-metric',
113
+ 'navigateToAddMetric',
114
+ );
115
+
116
+ public navigateBackToSpacePage(
117
+ space: ISpaceContext,
118
+ page: string,
119
+ navOptions: NavigationOptions = {},
120
+ ): Promise<boolean> {
121
+ navOptions.animationDirection = 'back';
122
+ return this.navigateToSpacePage(space, page, navOptions);
123
+ }
124
+
125
+ public navigateForwardToSpacePage(
126
+ space: ISpaceContext,
127
+ page: string,
128
+ navOptions: NavigationOptions = {},
129
+ ): Promise<boolean> {
130
+ navOptions.animationDirection = 'forward';
131
+ return this.navigateToSpacePage(space, page, navOptions);
132
+ }
133
+
134
+ private navigateToSpacePage(
135
+ space: ISpaceContext,
136
+ page: string,
137
+ navOptions: NavigationOptions,
138
+ ): Promise<boolean> {
139
+ const url = `space/${space?.type}/${space?.id}/${page}`;
140
+ const state = navOptions.state || {};
141
+ navOptions = { ...navOptions, state: { space, ...state } };
142
+ return this.navController.navigateForward(url, navOptions);
143
+ }
144
+
145
+ private navForward(
146
+ navController: NavController,
147
+ url: string,
148
+ navOptions: NavigationOptions,
149
+ // _analyticsEvent: { name: string; params?: Record<string, unknown> },
150
+ ): void {
151
+ navController = navController || this.navController;
152
+ // this.analyticsService.logEvent(analyticsEvent.name, analyticsEvent.params);
153
+ navController
154
+ .navigateForward(url, navOptions)
155
+ .catch((err) =>
156
+ this.errorLogger.logError(err, 'Failed to navigate to: ' + url),
157
+ );
158
+ }
159
+
160
+ private navToSpacePage = (
161
+ navController: NavController,
162
+ space: ISpaceRef,
163
+ url: string,
164
+ eventName: string,
165
+ params?: Record<string, unknown>,
166
+ ): void => {
167
+ params = { ...params, space: space.id };
168
+ this.analyticsService.logEvent(eventName, params);
169
+ this.navForward(
170
+ navController,
171
+ url,
172
+ { queryParams: params, state: { space } },
173
+ );
174
+ };
175
+ }
@@ -0,0 +1,46 @@
1
+ import { TestBed } from '@angular/core/testing';
2
+ import { Firestore } from '@angular/fire/firestore';
3
+ import { SneatApiService } from '@sneat/api';
4
+ import { SneatAuthStateService, SneatUserService } from '@sneat/auth-core';
5
+ import { ErrorLogger } from '@sneat/core';
6
+ import { of } from 'rxjs';
7
+ import { SpaceServiceModule } from './space-service.module';
8
+ import { SpaceService } from './space.service';
9
+
10
+ describe('SpaceServiceModule', () => {
11
+ beforeEach(() => {
12
+ TestBed.configureTestingModule({
13
+ imports: [SpaceServiceModule],
14
+ providers: [
15
+ {
16
+ provide: ErrorLogger,
17
+ useValue: { logError: vi.fn(), logErrorHandler: () => vi.fn() },
18
+ },
19
+ {
20
+ provide: Firestore,
21
+ useValue: { type: 'Firestore', toJSON: () => ({}) },
22
+ },
23
+ {
24
+ provide: SneatUserService,
25
+ useValue: { userState: of({ record: undefined }) },
26
+ },
27
+ {
28
+ provide: SneatApiService,
29
+ useValue: { post: vi.fn(), get: vi.fn() },
30
+ },
31
+ {
32
+ provide: SneatAuthStateService,
33
+ useValue: {
34
+ authStatus: of('notAuthenticated'),
35
+ authState: of({ status: 'notAuthenticated' }),
36
+ },
37
+ },
38
+ ],
39
+ });
40
+ });
41
+
42
+ it('should provide SpaceService', () => {
43
+ const service = TestBed.inject(SpaceService);
44
+ expect(service).toBeTruthy();
45
+ });
46
+ });
@@ -0,0 +1,7 @@
1
+ import { NgModule } from '@angular/core';
2
+ import { SpaceService } from './space.service';
3
+
4
+ @NgModule({
5
+ providers: [SpaceService],
6
+ })
7
+ export class SpaceServiceModule {}