diff --git a/.github/workflows/test-changed-firestore-integration.yml b/.github/workflows/test-changed-firestore-integration.yml index 98234683477..f57d3c3ef57 100644 --- a/.github/workflows/test-changed-firestore-integration.yml +++ b/.github/workflows/test-changed-firestore-integration.yml @@ -20,13 +20,16 @@ jobs: - name: Setup Terraform uses: hashicorp/setup-terraform@v2 - name: Terraform Init - run: terraform init + run: | + cd packages/firestore + terraform init continue-on-error: true - name: Terraform Apply if: github.event_name == 'pull_request' run: | - cp config/ci.config.json config/project.json - terraform apply -var-file=config/project.json -auto-approve + cp ../../config/ci.config.json config/project.json + terraform apply -var-file=../../config/project.json -auto-approve + cd ../.. continue-on-error: true - name: Set up Node (16) uses: actions/setup-node@v3 diff --git a/firestore_index_config.tf b/packages/firestore/firestore_index_config.tf similarity index 100% rename from firestore_index_config.tf rename to packages/firestore/firestore_index_config.tf diff --git a/main.tf b/packages/firestore/main.tf similarity index 100% rename from main.tf rename to packages/firestore/main.tf diff --git a/packages/firestore/test/integration/util/composite_index_test_helper.ts b/packages/firestore/test/integration/util/composite_index_test_helper.ts index 3a0ef7ecbbe..b650578b911 100644 --- a/packages/firestore/test/integration/util/composite_index_test_helper.ts +++ b/packages/firestore/test/integration/util/composite_index_test_helper.ts @@ -17,6 +17,7 @@ import { and } from '../../../src/lite-api/query'; import { AutoId } from '../../../src/util/misc'; +import { field } from '../../util/helpers'; import { query as internalQuery, @@ -32,7 +33,13 @@ import { setDoc as setDocument, QueryCompositeFilterConstraint, QueryNonFilterConstraint, - Timestamp + Timestamp, + DocumentSnapshot, + getDoc as getDocument, + updateDoc as updateDocument, + UpdateData, + getDocs as getDocuments, + QuerySnapshot } from './firebase_export'; import { batchCommitDocsToCollection, @@ -55,6 +62,7 @@ import { COMPOSITE_INDEX_TEST_COLLECTION, DEFAULT_SETTINGS } from './settings'; export class CompositeIndexTestHelper { private readonly testId: string; private readonly TEST_ID_FIELD: string = 'testId'; + private readonly TTL_FIELD: string = 'expireAt'; // Creates a new instance of the CompositeIndexTestHelper class, with a unique test // identifier for data isolation. @@ -91,13 +99,20 @@ export class CompositeIndexTestHelper { return { ...doc, [this.TEST_ID_FIELD]: this.testId, - expireAt: new Timestamp( // Expire test data after 24 hours + [this.TTL_FIELD]: new Timestamp( // Expire test data after 24 hours Timestamp.now().seconds + 24 * 60 * 60, Timestamp.now().nanoseconds ) }; } + // Remove test-specific fields from a document, including the testId and expiration date. + removeTestSpecificFieldsFromDoc(doc: DocumentData): DocumentData { + doc._document?.data?.delete(field(this.TTL_FIELD)); + doc._document?.data?.delete(field(this.TEST_ID_FIELD)); + return doc; + } + // Helper method to hash document keys and add test-specific fields for the provided documents. private prepareTestDocuments(docs: { [key: string]: DocumentData }): { [key: string]: DocumentData; @@ -172,4 +187,34 @@ export class CompositeIndexTestHelper { ) as WithFieldValue; return setDocument(reference, processedData); } + + // This is is the same as making the update on the doc directly with merge=true. + updateDoc( + reference: DocumentReference, + data: UpdateData + ): Promise { + const processedData = this.addTestSpecificFieldsToDoc( + data + ) as UpdateData; + return updateDocument(reference, processedData); + } + + + async getDoc( + reference: DocumentReference + ): Promise> { + const docSnapshot = await getDocument(reference); + this.removeTestSpecificFieldsFromDoc(docSnapshot); + return docSnapshot; + } + + async getDocs( + query_: Query + ): Promise> { + const querySnapshot = await getDocuments(this.query(query_)); + querySnapshot.forEach(doc => { + this.removeTestSpecificFieldsFromDoc(doc); + }); + return querySnapshot; + } }