mirror of
https://github.com/zhigang1992/react-native-firebase.git
synced 2026-04-22 11:16:18 +08:00
Tests for firestore and auth
This commit is contained in:
@@ -4,12 +4,11 @@
|
||||
*/
|
||||
import CollectionReference from './CollectionReference';
|
||||
import DocumentSnapshot from './DocumentSnapshot';
|
||||
import FieldPath from './FieldPath';
|
||||
import { mergeFieldPathData } from './utils';
|
||||
import { parseUpdateArgs } from './utils';
|
||||
import { buildNativeMap } from './utils/serialize';
|
||||
import { getAppEventName, SharedEventEmitter } from '../../utils/events';
|
||||
import { getLogger } from '../../utils/log';
|
||||
import { firestoreAutoId, isFunction, isObject, isString } from '../../utils';
|
||||
import { firestoreAutoId, isFunction, isObject } from '../../utils';
|
||||
import { getNativeModule } from '../../utils/native';
|
||||
|
||||
import type Firestore from './';
|
||||
@@ -50,9 +49,7 @@ export default class DocumentReference {
|
||||
|
||||
get parent(): CollectionReference {
|
||||
const parentPath = this._documentPath.parent();
|
||||
if (!parentPath) {
|
||||
throw new Error('Invalid document path');
|
||||
}
|
||||
// $FlowExpectedError: parentPath can never be null
|
||||
return new CollectionReference(this._firestore, parentPath);
|
||||
}
|
||||
|
||||
@@ -232,34 +229,7 @@ export default class DocumentReference {
|
||||
}
|
||||
|
||||
update(...args: any[]): Promise<void> {
|
||||
let data = {};
|
||||
if (args.length === 1) {
|
||||
if (!isObject(args[0])) {
|
||||
throw new Error(
|
||||
'DocumentReference.update failed: If using a single argument, it must be an object.'
|
||||
);
|
||||
}
|
||||
// eslint-disable-next-line prefer-destructuring
|
||||
data = args[0];
|
||||
} else if (args.length % 2 === 1) {
|
||||
throw new Error(
|
||||
'DocumentReference.update failed: Must have either a single object argument, or equal numbers of key/value pairs.'
|
||||
);
|
||||
} else {
|
||||
for (let i = 0; i < args.length; i += 2) {
|
||||
const key = args[i];
|
||||
const value = args[i + 1];
|
||||
if (isString(key)) {
|
||||
data[key] = value;
|
||||
} else if (key instanceof FieldPath) {
|
||||
data = mergeFieldPathData(data, key._segments, value);
|
||||
} else {
|
||||
throw new Error(
|
||||
`DocumentReference.update failed: Argument at index ${i} must be a string or FieldPath`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
const data = parseUpdateArgs(args, 'DocumentReference.update');
|
||||
const nativeData = buildNativeMap(data);
|
||||
return getNativeModule(this._firestore).documentUpdate(
|
||||
this.path,
|
||||
|
||||
Reference in New Issue
Block a user