-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
thomas.nisolle-ext
committed
Feb 1, 2022
1 parent
aac103d
commit 50dd49d
Showing
35 changed files
with
208 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 25 additions & 75 deletions
100
projects/ngx-firebase-repository/src/e2e/util/firestore-mock.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,36 @@ | ||
import firebase from 'firebase'; | ||
import { from, Observable, Subject } from 'rxjs'; | ||
import { omit } from 'lodash'; | ||
import { arrayMap } from '@witty-services/rxjs-common'; | ||
import { map } from 'rxjs/operators'; | ||
import CollectionReference = firebase.firestore.CollectionReference; | ||
import DocumentData = firebase.firestore.DocumentData; | ||
import DocumentReference = firebase.firestore.DocumentReference; | ||
import createSpy = jasmine.createSpy; | ||
import { from, Observable, of } from 'rxjs'; | ||
import { CollectionReference, DocumentData, DocumentReference, Firestore } from 'firebase/firestore'; | ||
import { PartialWithFieldValue, WithFieldValue } from '@firebase/firestore'; | ||
|
||
export class FirestoreMock { | ||
|
||
public readonly collectionAdd: any = createSpy('collectionAdd'); | ||
public readonly documentDelete: any = createSpy('documentDelete'); | ||
public readonly documentUpdate: any = createSpy('documentUpdate'); | ||
private readonly data: Map<string, Observable<any>> = new Map<string, Observable<any>>(); | ||
|
||
public mock(path: string, ...values: any[]): void { | ||
this.data.set(path, from(values)); | ||
} | ||
|
||
public collection(path: string): CollectionReference<DocumentData> { | ||
const firestore: FirestoreMock = this; | ||
|
||
return { | ||
add: (data: any): Promise<DocumentReference<DocumentData>> => { | ||
firestore.collectionAdd(path, data); | ||
export function collection(firestore: Firestore, path: string): CollectionReference<DocumentData> { | ||
return {} as CollectionReference; | ||
} | ||
|
||
return this.getDocumentReference(path).toPromise(); | ||
}, | ||
onSnapshot: (subscriber: any) => { | ||
this.getData(path).pipe( | ||
arrayMap((item: any) => ({ | ||
id: item.id, | ||
data: () => omit(item, ['id']) | ||
})) | ||
).subscribe((docs: any) => { | ||
subscriber.next({docs}); | ||
}, () => void 0, () => { | ||
subscriber.complete(); | ||
}); | ||
} | ||
} as CollectionReference; | ||
} | ||
export function doc(firestore: Firestore, path: string): DocumentReference<DocumentData> { | ||
return {} as DocumentReference; | ||
} | ||
|
||
public doc(path: string): DocumentReference<DocumentData> { | ||
const firestore: FirestoreMock = this; | ||
export function addDoc<T>(reference: CollectionReference<T>, data: WithFieldValue<T>): Promise<DocumentReference<T>> { | ||
return of({}).toPromise() as Promise<DocumentReference<T>>; | ||
} | ||
|
||
return { | ||
delete(): Promise<void> { | ||
firestore.documentDelete(path); | ||
export function updateDoc(reference: DocumentReference<unknown>, value: unknown, ...moreFieldsAndValues: unknown[]): Promise<void> { | ||
return of(void 0).toPromise() as Promise<void>; | ||
} | ||
|
||
return Promise.resolve(); | ||
}, | ||
update(data: any): Promise<void> { | ||
firestore.documentUpdate(path, data); | ||
export function setDoc<T>(reference: DocumentReference<T>, data: PartialWithFieldValue<T>): Promise<void> { | ||
return of(void 0).toPromise() as Promise<void>; | ||
} | ||
|
||
return Promise.resolve(); | ||
}, | ||
onSnapshot: (subscriber: any) => { | ||
this.getDocumentReference(path).subscribe((value: any) => { | ||
subscriber.next(value); | ||
}, () => void 0, () => { | ||
subscriber.complete(); | ||
}); | ||
} | ||
} as DocumentReference; | ||
} | ||
export function deleteDoc(reference: DocumentReference<unknown>): Promise<void> { | ||
return of(void 0).toPromise() as Promise<void>; | ||
} | ||
|
||
private getData(path: string): Observable<any> { | ||
if (!this.data.has(path)) { | ||
this.data.set(path, new Subject<any>()); | ||
} | ||
export class FirestoreMock { | ||
|
||
return this.data.get(path); | ||
} | ||
private static readonly data: Map<string, Observable<any>> = new Map<string, Observable<any>>(); | ||
|
||
private getDocumentReference(path: string): Observable<any> { | ||
return this.getData(path).pipe( | ||
map((item: any) => ({ | ||
id: item.id, | ||
data: () => omit(item, ['id']) | ||
})) | ||
); | ||
public static mock(path: string, ...values: any[]): void { | ||
FirestoreMock.data.set(path, from(values)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
...ebase-repository/src/lib/configuration/context/firebase-criteria-context.configuration.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 2 additions & 4 deletions
6
...ebase-repository/src/lib/configuration/context/firebase-order-by-context.configuration.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 2 additions & 3 deletions
5
projects/ngx-firebase-repository/src/lib/converter/fb-timestamp.converter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 3 additions & 4 deletions
7
projects/ngx-firebase-repository/src/lib/decorator/firebase-created-at.decorator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 7 additions & 3 deletions
10
projects/ngx-firebase-repository/src/lib/decorator/firebase-order-by.decorator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,20 @@ | ||
/** | ||
* @ignore | ||
*/ | ||
import {FirebaseOrderByContextConfiguration} from '../configuration/context/firebase-order-by-context.configuration'; | ||
import { FirebaseOrderByContextConfiguration } from '../configuration/context/firebase-order-by-context.configuration'; | ||
|
||
export const FIREBASE_ORDER_BY_METADATA_KEY: string = 'firebaseOrderBy'; | ||
export const FIREBASE_ORDER_BY_METADATA_KEY: string = 'firebaseOrderBys'; | ||
|
||
export function FirebaseOrderBy(): any { | ||
return (target: any, propertyKey: string) => { | ||
const firebaseOrderByContextConfiguration: FirebaseOrderByContextConfiguration = { | ||
propertyKey | ||
}; | ||
|
||
Reflect.defineMetadata(FIREBASE_ORDER_BY_METADATA_KEY, firebaseOrderByContextConfiguration, target); | ||
let metas: FirebaseOrderByContextConfiguration[] = []; | ||
if (Reflect.hasMetadata(FIREBASE_ORDER_BY_METADATA_KEY, target)) { | ||
metas = Reflect.getMetadata(FIREBASE_ORDER_BY_METADATA_KEY, target); | ||
} | ||
Reflect.defineMetadata(FIREBASE_ORDER_BY_METADATA_KEY, metas.concat(firebaseOrderByContextConfiguration), target); | ||
}; | ||
} |
Oops, something went wrong.