-
Notifications
You must be signed in to change notification settings - Fork 930
Expose array transforms and array contains queries. #1004
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 1 commit
Commits
Show all changes
4 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,20 +21,16 @@ import firebase from '../util/firebase_export'; | |
import { apiDescribe, withTestDoc, withTestDb } from '../util/helpers'; | ||
import { EventsAccumulator } from '../util/events_accumulator'; | ||
|
||
// TODO(array-features): Remove "as any" | ||
// tslint:disable-next-line:no-any variable-name Type alias can be capitalized. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can remove "no-any" from here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oops, thanks! |
||
const FieldValue = firebase.firestore.FieldValue as any; | ||
const FieldValue = firebase.firestore.FieldValue; | ||
|
||
/** | ||
* Note: Transforms are tested pretty thoroughly in server_timestamp.test.ts | ||
* (via set, update, transactions, nested in documents, multiple transforms | ||
* together, etc.) and so these tests mostly focus on the array transform | ||
* semantics. | ||
*/ | ||
// TODO(array-features): Enable these tests once the feature is available in | ||
// prod. For now you can run these tests using: | ||
// yarn test:browser --integration --local | ||
apiDescribe.skip('Array Transforms:', persistence => { | ||
apiDescribe('Array Transforms:', persistence => { | ||
// A document reference to read and write to. | ||
let docRef: firestore.DocumentReference; | ||
|
||
|
@@ -87,15 +83,15 @@ apiDescribe.skip('Array Transforms:', persistence => { | |
|
||
it('create document with arrayUnion()', async () => { | ||
await withTestSetup(async () => { | ||
await docRef.set({ array: FieldValue._arrayUnion(1, 2) }); | ||
await docRef.set({ array: FieldValue.arrayUnion(1, 2) }); | ||
expectLocalAndRemoteEvent({ array: [1, 2] }); | ||
}); | ||
}); | ||
|
||
it('append to array via update()', async () => { | ||
await withTestSetup(async () => { | ||
await writeInitialData({ array: [1, 3] }); | ||
await docRef.update({ array: FieldValue._arrayUnion(2, 1, 4) }); | ||
await docRef.update({ array: FieldValue.arrayUnion(2, 1, 4) }); | ||
await expectLocalAndRemoteEvent({ array: [1, 3, 2, 4] }); | ||
}); | ||
}); | ||
|
@@ -104,7 +100,7 @@ apiDescribe.skip('Array Transforms:', persistence => { | |
await withTestSetup(async () => { | ||
await writeInitialData({ array: [1, 3] }); | ||
await docRef.set( | ||
{ array: FieldValue._arrayUnion(2, 1, 4) }, | ||
{ array: FieldValue.arrayUnion(2, 1, 4) }, | ||
{ merge: true } | ||
); | ||
await expectLocalAndRemoteEvent({ array: [1, 3, 2, 4] }); | ||
|
@@ -115,7 +111,7 @@ apiDescribe.skip('Array Transforms:', persistence => { | |
await withTestSetup(async () => { | ||
await writeInitialData({ array: [{ a: 'hi' }] }); | ||
await docRef.update({ | ||
array: FieldValue._arrayUnion({ a: 'hi' }, { a: 'bye' }) | ||
array: FieldValue.arrayUnion({ a: 'hi' }, { a: 'bye' }) | ||
}); | ||
await expectLocalAndRemoteEvent({ array: [{ a: 'hi' }, { a: 'bye' }] }); | ||
}); | ||
|
@@ -124,7 +120,7 @@ apiDescribe.skip('Array Transforms:', persistence => { | |
it('remove from array via update()', async () => { | ||
await withTestSetup(async () => { | ||
await writeInitialData({ array: [1, 3, 1, 3] }); | ||
await docRef.update({ array: FieldValue._arrayRemove(1, 4) }); | ||
await docRef.update({ array: FieldValue.arrayRemove(1, 4) }); | ||
await expectLocalAndRemoteEvent({ array: [3, 3] }); | ||
}); | ||
}); | ||
|
@@ -133,7 +129,7 @@ apiDescribe.skip('Array Transforms:', persistence => { | |
await withTestSetup(async () => { | ||
await writeInitialData({ array: [1, 3, 1, 3] }); | ||
await docRef.set( | ||
{ array: FieldValue._arrayRemove(1, 4) }, | ||
{ array: FieldValue.arrayRemove(1, 4) }, | ||
{ merge: true } | ||
); | ||
await expectLocalAndRemoteEvent({ array: [3, 3] }); | ||
|
@@ -143,7 +139,7 @@ apiDescribe.skip('Array Transforms:', persistence => { | |
it('remove object from array via update()', async () => { | ||
await withTestSetup(async () => { | ||
await writeInitialData({ array: [{ a: 'hi' }, { a: 'bye' }] }); | ||
await docRef.update({ array: FieldValue._arrayRemove({ a: 'hi' }) }); | ||
await docRef.update({ array: FieldValue.arrayRemove({ a: 'hi' }) }); | ||
await expectLocalAndRemoteEvent({ array: [{ a: 'bye' }] }); | ||
}); | ||
}); | ||
|
@@ -158,7 +154,7 @@ apiDescribe.skip('Array Transforms:', persistence => { | |
(persistence ? describe : describe.skip)('Server Application: ', () => { | ||
it('set() with no cached base doc', async () => { | ||
await withTestDoc(persistence, async docRef => { | ||
await docRef.set({ array: FieldValue._arrayUnion(1, 2) }); | ||
await docRef.set({ array: FieldValue.arrayUnion(1, 2) }); | ||
const snapshot = await docRef.get({ source: 'cache' }); | ||
expect(snapshot.data()).to.deep.equal({ array: [1, 2] }); | ||
}); | ||
|
@@ -175,7 +171,7 @@ apiDescribe.skip('Array Transforms:', persistence => { | |
|
||
await withTestDb(persistence, async db => { | ||
const docRef = db.doc(path); | ||
await docRef.update({ array: FieldValue._arrayUnion(1, 2) }); | ||
await docRef.update({ array: FieldValue.arrayUnion(1, 2) }); | ||
|
||
// Nothing should be cached since it was an update and we had no base | ||
// doc. | ||
|
@@ -202,7 +198,7 @@ apiDescribe.skip('Array Transforms:', persistence => { | |
await withTestDb(persistence, async db => { | ||
const docRef = db.doc(path); | ||
await docRef.set( | ||
{ array: FieldValue._arrayUnion(1, 2) }, | ||
{ array: FieldValue.arrayUnion(1, 2) }, | ||
{ merge: true } | ||
); | ||
|
||
|
@@ -215,7 +211,7 @@ apiDescribe.skip('Array Transforms:', persistence => { | |
it('update() with cached base doc using arrayUnion()', async () => { | ||
await withTestDoc(persistence, async docRef => { | ||
await docRef.set({ array: [42] }); | ||
await docRef.update({ array: FieldValue._arrayUnion(1, 2) }); | ||
await docRef.update({ array: FieldValue.arrayUnion(1, 2) }); | ||
const snapshot = await docRef.get({ source: 'cache' }); | ||
expect(snapshot.data()).to.deep.equal({ array: [42, 1, 2] }); | ||
}); | ||
|
@@ -224,7 +220,7 @@ apiDescribe.skip('Array Transforms:', persistence => { | |
it('update() with cached base doc using arrayRemove()', async () => { | ||
await withTestDoc(persistence, async docRef => { | ||
await docRef.set({ array: [42, 1, 2] }); | ||
await docRef.update({ array: FieldValue._arrayRemove(1, 2) }); | ||
await docRef.update({ array: FieldValue.arrayRemove(1, 2) }); | ||
const snapshot = await docRef.get({ source: 'cache' }); | ||
expect(snapshot.data()).to.deep.equal({ array: [42] }); | ||
}); | ||
|
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
Oops, something went wrong.
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.
Is the double-quoting intentional for better formatting?
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.
yep