Skip to content

Commit 84c6103

Browse files
committed
test(firestore): more document tests
1 parent 2df2f78 commit 84c6103

File tree

4 files changed

+129
-203
lines changed

4 files changed

+129
-203
lines changed

old_tests/core/firestore/document.spec.ts

Lines changed: 0 additions & 187 deletions
This file was deleted.

src/firestore/index.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ import {
2424
_RefWithState,
2525
} from '../shared'
2626
import { firestoreUnbinds } from './optionsApi'
27-
import { bindCollection, bindDocument, FirestoreOptions } from './subscribe'
27+
import {
28+
bindCollection,
29+
bindDocument,
30+
firestoreOptions,
31+
FirestoreOptions,
32+
} from './subscribe'
2833

2934
export const ops: OperationsType = {
3035
set: (target, key, value) => walkSet(target, key, value),
@@ -47,9 +52,10 @@ export function _useFirestoreRef(
4752
docOrCollectionRef: _MaybeRef<
4853
DocumentReference<unknown> | Query<unknown> | CollectionReference<unknown>
4954
>,
50-
options: _UseFirestoreRefOptions = {}
55+
localOptions?: _UseFirestoreRefOptions
5156
) {
5257
let _unbind!: UnbindType
58+
const options = Object.assign({}, firestoreOptions, localOptions)
5359

5460
// TODO: allow passing pending and error refs as option for when this is called using the options api
5561
const data = options.target || ref<unknown | null>(options.initialValue)
@@ -62,7 +68,14 @@ export function _useFirestoreRef(
6268

6369
function bindFirestoreRef() {
6470
const p = new Promise<unknown | null>((resolve, reject) => {
65-
const docRefValue = unref(docOrCollectionRef)
71+
let docRefValue = unref(docOrCollectionRef)
72+
if (!docRefValue.converter) {
73+
docRefValue = docRefValue.withConverter(
74+
// @ts-expect-error: seems like a ts error
75+
options.converter as FirestoreDataConverter<T>
76+
)
77+
}
78+
6679
_unbind = (isDocumentRef(docRefValue) ? bindDocument : bindCollection)(
6780
data,
6881
// @ts-expect-error: the type is good because of the ternary

src/firestore/subscribe.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -223,20 +223,13 @@ export function bindCollection<T = unknown>(
223223
ops: CommonBindOptionsParameter['ops'],
224224
resolve: CommonBindOptionsParameter['resolve'],
225225
reject: CommonBindOptionsParameter['reject'],
226-
extraOptions: FirestoreOptions = DEFAULT_OPTIONS
226+
extraOptions?: FirestoreOptions
227227
) {
228+
// FIXME: can be removed now
228229
const options = Object.assign({}, DEFAULT_OPTIONS, extraOptions) // fill default values
229230

230231
const { snapshotListenOptions, snapshotOptions, wait } = options
231232

232-
if (!collection.converter) {
233-
// @ts-expect-error: seems like a ts error
234-
collection = collection.withConverter(
235-
// @ts-expect-error: seems like a ts error
236-
options.converter as FirestoreDataConverter<T>
237-
)
238-
}
239-
240233
const key = 'value'
241234
if (!wait) ops.set(target, key, [])
242235
let arrayRef = ref(wait ? [] : target[key])
@@ -379,7 +372,7 @@ export function bindDocument<T>(
379372
ops: BindDocumentParameter['ops'],
380373
resolve: BindDocumentParameter['resolve'],
381374
reject: BindDocumentParameter['reject'],
382-
extraOptions: FirestoreOptions = DEFAULT_OPTIONS
375+
extraOptions?: FirestoreOptions
383376
) {
384377
const options = Object.assign({}, DEFAULT_OPTIONS, extraOptions) // fill default values
385378
const key = 'value'

0 commit comments

Comments
 (0)