Skip to content

Firestore: in tests, silence the verbose warning about old timestamp behavior #1058

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/firestore/test/integration/api/fields.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import {
withTestCollectionSettings,
withTestDoc
} from '../util/helpers';
import * as log from '../../../src/util/log';
import { LogLevel } from '../../../src/util/log';

const FieldPath = firebase.firestore.FieldPath;
const Timestamp = firebase.firestore.Timestamp;
Expand Down Expand Up @@ -349,12 +351,18 @@ apiDescribe('Timestamp Fields in snapshots', persistence => {
};

it('are returned as native dates if timestampsInSnapshots is not set', () => {
// Avoid the verbose log message triggered by timestampsInSnapshots ==
// false.
const logLevel = log.getLogLevel();
log.setLogLevel(LogLevel.SILENT);

const settings = { ...DEFAULT_SETTINGS };
settings['timestampsInSnapshots'] = false;

const timestamp = new Timestamp(100, 123456789);
const testDocs = { a: testDataWithTimestamps(timestamp) };
return withTestCollectionSettings(persistence, settings, testDocs, coll => {
log.setLogLevel(logLevel);
return coll
.doc('a')
.get()
Expand Down Expand Up @@ -411,13 +419,17 @@ apiDescribe('Timestamp Fields in snapshots', persistence => {
});

it('timestampsInSnapshots affects server timestamps', () => {
const logLevel = log.getLogLevel();
log.setLogLevel(LogLevel.SILENT);

const settings = { ...DEFAULT_SETTINGS };
settings['timestampsInSnapshots'] = false;
const testDocs = {
a: { timestamp: firebase.firestore.FieldValue.serverTimestamp() }
};

return withTestCollectionSettings(persistence, settings, testDocs, coll => {
log.setLogLevel(logLevel);
return coll
.doc('a')
.get()
Expand Down
13 changes: 7 additions & 6 deletions packages/firestore/test/util/api_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,16 @@ export const FIRESTORE = new Firestore({
});

export function firestore(): Firestore {
FIRESTORE.settings({ timestampsInSnapshots: true });
return FIRESTORE;
}

export function collectionReference(path: string): CollectionReference {
return new CollectionReference(pathFrom(path), FIRESTORE);
return new CollectionReference(pathFrom(path), firestore());
}

export function documentReference(path: string): DocumentReference {
return new DocumentReference(key(path), FIRESTORE);
return new DocumentReference(key(path), firestore());
}

export function documentSnapshot(
Expand All @@ -64,18 +65,18 @@ export function documentSnapshot(
): DocumentSnapshot {
if (data) {
return new DocumentSnapshot(
FIRESTORE,
firestore(),
key(path),
doc(path, 1, data),
fromCache
);
} else {
return new DocumentSnapshot(FIRESTORE, key(path), null, fromCache);
return new DocumentSnapshot(firestore(), key(path), null, fromCache);
}
}

export function query(path: string): Query {
return new Query(InternalQuery.atPath(pathFrom(path)), FIRESTORE);
return new Query(InternalQuery.atPath(pathFrom(path)), firestore());
}

/**
Expand Down Expand Up @@ -121,5 +122,5 @@ export function querySnapshot(
syncStateChanged,
/* excludesMetadataChanges= */ false
);
return new QuerySnapshot(FIRESTORE, query, viewSnapshot);
return new QuerySnapshot(firestore(), query, viewSnapshot);
}