File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { DocumentData , getDoc } from 'firebase/firestore'
2
+ import { beforeEach , describe , expect , it } from 'vitest'
3
+ import { extractRefs } from '../../src/firestore/utils'
4
+ import { setupFirestoreRefs } from '../utils'
5
+
6
+ describe ( 'Firestore utils' , ( ) => {
7
+ const { collection, doc, setDoc, updateDoc } = setupFirestoreRefs ( )
8
+
9
+ const docRef = doc ( )
10
+ const collectionRef = collection ( )
11
+
12
+ const docData = {
13
+ n : 42 ,
14
+ is : true ,
15
+ items : [ { text : 'foo' } ] ,
16
+ ref : docRef ,
17
+ }
18
+
19
+ beforeEach ( async ( ) => {
20
+ await setDoc ( docRef , {
21
+ // collection,
22
+ data : { } ,
23
+ index : 0 ,
24
+ } )
25
+ } )
26
+
27
+ it . skip ( 'extracts refs from documents' , async ( ) => {
28
+ const docRef = doc < DocumentData > ( )
29
+ const [ noRefsDoc , refs ] = extractRefs ( docData , undefined , { } )
30
+ expect ( noRefsDoc . ref ) . toBe ( docRef . path )
31
+ expect ( refs ) . toEqual ( {
32
+ ref : docRef ,
33
+ } )
34
+ } )
35
+
36
+ it ( 'leave Date objects alone when extracting refs' , ( ) => {
37
+ const d = new Date ( )
38
+ const [ doc , refs ] = extractRefs (
39
+ {
40
+ foo : 1 ,
41
+ bar : d ,
42
+ } ,
43
+ undefined ,
44
+ { }
45
+ )
46
+ expect ( doc . foo ) . toBe ( 1 )
47
+ expect ( doc . bar ) . toBe ( d )
48
+ expect ( refs ) . toEqual ( { } )
49
+ } )
50
+ } )
You can’t perform that action at this time.
0 commit comments