-
Notifications
You must be signed in to change notification settings - Fork 945
Avoid using hardcoded document paths which could cause conflicts when tests are running concurrently (e.g. on Travis). #250
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,14 +20,19 @@ import * as firestore from 'firestore'; | |
import { Deferred } from '../../../src/util/promise'; | ||
import { asyncIt } from '../../util/helpers'; | ||
import firebase from '../util/firebase_export'; | ||
import { apiDescribe, withTestCollection, withTestDb } from '../util/helpers'; | ||
import { | ||
apiDescribe, | ||
withTestCollection, | ||
withTestDb, | ||
withTestDoc | ||
} from '../util/helpers'; | ||
import { Firestore } from '../../../src/api/database'; | ||
|
||
apiDescribe('Database', persistence => { | ||
asyncIt('can set a document', () => { | ||
return withTestDb(persistence, db => { | ||
return db.doc('rooms/Eros').set({ | ||
desc: 'Stuff related to Eros project...', | ||
return withTestDoc(persistence, docRef => { | ||
return docRef.set({ | ||
desc: 'Stuff related to Firestore project...', | ||
owner: { | ||
name: 'Jonny', | ||
title: 'scallywag' | ||
|
@@ -46,8 +51,7 @@ apiDescribe('Database', persistence => { | |
}); | ||
|
||
asyncIt('can delete a document', () => { | ||
return withTestDb(persistence, db => { | ||
const docRef = db.doc('rooms/Eros'); | ||
return withTestDoc(persistence, docRef => { | ||
return docRef | ||
.set({ foo: 'bar' }) | ||
.then(() => { | ||
|
@@ -67,8 +71,7 @@ apiDescribe('Database', persistence => { | |
}); | ||
|
||
asyncIt('can update existing document', () => { | ||
return withTestDb(persistence, db => { | ||
const doc = db.doc('rooms/Eros'); | ||
return withTestDoc(persistence, doc => { | ||
const initialData = { | ||
desc: 'Description', | ||
owner: { name: 'Jonny', email: '[email protected]' } | ||
|
@@ -93,8 +96,7 @@ apiDescribe('Database', persistence => { | |
}); | ||
|
||
asyncIt('can merge data with an existing document using set', () => { | ||
return withTestDb(persistence, db => { | ||
const doc = db.doc('rooms/Eros'); | ||
return withTestDoc(persistence, doc => { | ||
const initialData = { | ||
desc: 'description', | ||
'owner.data': { name: 'Jonny', email: '[email protected]' } | ||
|
@@ -120,8 +122,7 @@ apiDescribe('Database', persistence => { | |
}); | ||
|
||
asyncIt('can merge server timestamps', () => { | ||
return withTestDb(persistence, db => { | ||
const doc = db.doc('rooms/Eros'); | ||
return withTestDoc(persistence, doc => { | ||
const initialData = { | ||
updated: false | ||
}; | ||
|
@@ -141,8 +142,7 @@ apiDescribe('Database', persistence => { | |
}); | ||
|
||
asyncIt('can replace an array by merging using set', () => { | ||
return withTestDb(persistence, db => { | ||
const doc = db.doc('rooms/Eros'); | ||
return withTestDoc(persistence, doc => { | ||
const initialData = { | ||
untouched: true, | ||
data: 'old', | ||
|
@@ -172,8 +172,7 @@ apiDescribe('Database', persistence => { | |
}); | ||
|
||
asyncIt('cannot update nonexistent document', () => { | ||
return withTestDb(persistence, db => { | ||
const doc = db.collection('rooms').doc(); | ||
return withTestDoc(persistence, doc => { | ||
return doc | ||
.update({ owner: 'abc' }) | ||
.then( | ||
|
@@ -192,8 +191,7 @@ apiDescribe('Database', persistence => { | |
}); | ||
|
||
asyncIt('can delete a field with an update', () => { | ||
return withTestDb(persistence, db => { | ||
const doc = db.doc('rooms/Eros'); | ||
return withTestDoc(persistence, doc => { | ||
const initialData = { | ||
desc: 'Description', | ||
owner: { name: 'Jonny', email: '[email protected]' } | ||
|
@@ -219,8 +217,7 @@ apiDescribe('Database', persistence => { | |
asyncIt('can update nested fields', () => { | ||
const FieldPath = firebase.firestore.FieldPath; | ||
|
||
return withTestDb(persistence, db => { | ||
const doc = db.doc('rooms/Eros'); | ||
return withTestDoc(persistence, doc => { | ||
const initialData = { | ||
desc: 'Description', | ||
owner: { name: 'Jonny' }, | ||
|
@@ -248,8 +245,7 @@ apiDescribe('Database', persistence => { | |
const invalidDocValues = [undefined, null, 0, 'foo', ['a'], new Date()]; | ||
for (const val of invalidDocValues) { | ||
asyncIt('set/update should reject: ' + val, () => { | ||
return withTestDb(persistence, db => { | ||
const doc = db.collection('rooms').doc(); | ||
return withTestDoc(persistence, doc => { | ||
// tslint:disable-next-line:no-any Intentionally passing bad types. | ||
expect(() => doc.set(val as any)).to.throw(); | ||
// tslint:disable-next-line:no-any Intentionally passing bad types. | ||
|
@@ -337,10 +333,9 @@ apiDescribe('Database', persistence => { | |
}); | ||
|
||
asyncIt('Local document events are fired with hasLocalChanges=true.', () => { | ||
return withTestDb(persistence, db => { | ||
return withTestDoc(persistence, docRef => { | ||
let gotLocalDocEvent = false; | ||
const remoteDocEventDeferred = new Deferred(); | ||
const docRef = db.collection('rooms').doc(); | ||
const unlisten = docRef.onSnapshot( | ||
{ includeMetadataChanges: true }, | ||
doc => { | ||
|
@@ -366,10 +361,9 @@ apiDescribe('Database', persistence => { | |
asyncIt( | ||
'Metadata only changes are not fired when no options provided', | ||
() => { | ||
return withTestDb(persistence, db => { | ||
return withTestDoc(persistence, docRef => { | ||
const secondUpdateFound = new Deferred(); | ||
let count = 0; | ||
const docRef = db.collection('rooms').doc(); | ||
const unlisten = docRef.onSnapshot(doc => { | ||
if (doc) { | ||
count++; | ||
|
@@ -563,8 +557,7 @@ apiDescribe('Database', persistence => { | |
}); | ||
|
||
asyncIt('can queue writes while offline', () => { | ||
return withTestDb(persistence, db => { | ||
const docRef = db.collection('rooms').doc(); | ||
return withTestDoc(persistence, docRef => { | ||
// TODO(mikelehen): Find better way to expose this to tests. | ||
// tslint:disable-next-line:no-any enableNetwork isn't exposed via d.ts | ||
const firestoreInternal = docRef.firestore.INTERNAL as any; | ||
|
@@ -585,8 +578,7 @@ apiDescribe('Database', persistence => { | |
}); | ||
|
||
asyncIt('can get documents while offline', () => { | ||
return withTestDb(persistence, db => { | ||
const docRef = db.collection('rooms').doc(); | ||
return withTestDoc(persistence, docRef => { | ||
// TODO(mikelehen): Find better way to expose this to tests. | ||
// tslint:disable-next-line:no-any enableNetwork isn't exposed via d.ts | ||
const firestoreInternal = docRef.firestore.INTERNAL as any; | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably not worth the effort, but it would be niceish if we picked either docRef or doc and not both :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. If we did that I'd say we should do it in a separate PR... but I don't think it's worth the effort. :-)