Skip to content

Commit 63b060f

Browse files
committed
test: add utils
1 parent ce06c34 commit 63b060f

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

tests/firestore/utils.spec.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
})

0 commit comments

Comments
 (0)