Skip to content

Commit aa01d4a

Browse files
committed
move terraform into firestore
1 parent 719e51a commit aa01d4a

File tree

4 files changed

+53
-5
lines changed

4 files changed

+53
-5
lines changed

.github/workflows/test-changed-firestore-integration.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,16 @@ jobs:
2020
- name: Setup Terraform
2121
uses: hashicorp/setup-terraform@v2
2222
- name: Terraform Init
23-
run: terraform init
23+
run: |
24+
cd packages/firestore
25+
terraform init
2426
continue-on-error: true
2527
- name: Terraform Apply
2628
if: github.event_name == 'pull_request'
2729
run: |
28-
cp config/ci.config.json config/project.json
29-
terraform apply -var-file=config/project.json -auto-approve
30+
cp ../../config/ci.config.json config/project.json
31+
terraform apply -var-file=../../config/project.json -auto-approve
32+
cd ../..
3033
continue-on-error: true
3134
- name: Set up Node (16)
3235
uses: actions/setup-node@v3
File renamed without changes.

packages/firestore/test/integration/util/composite_index_test_helper.ts

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import { and } from '../../../src/lite-api/query';
1919
import { AutoId } from '../../../src/util/misc';
20+
import { field } from '../../util/helpers';
2021

2122
import {
2223
query as internalQuery,
@@ -32,7 +33,13 @@ import {
3233
setDoc as setDocument,
3334
QueryCompositeFilterConstraint,
3435
QueryNonFilterConstraint,
35-
Timestamp
36+
Timestamp,
37+
DocumentSnapshot,
38+
getDoc as getDocument,
39+
updateDoc as updateDocument,
40+
UpdateData,
41+
getDocs as getDocuments,
42+
QuerySnapshot
3643
} from './firebase_export';
3744
import {
3845
batchCommitDocsToCollection,
@@ -55,6 +62,7 @@ import { COMPOSITE_INDEX_TEST_COLLECTION, DEFAULT_SETTINGS } from './settings';
5562
export class CompositeIndexTestHelper {
5663
private readonly testId: string;
5764
private readonly TEST_ID_FIELD: string = 'testId';
65+
private readonly TTL_FIELD: string = 'expireAt';
5866

5967
// Creates a new instance of the CompositeIndexTestHelper class, with a unique test
6068
// identifier for data isolation.
@@ -91,13 +99,20 @@ export class CompositeIndexTestHelper {
9199
return {
92100
...doc,
93101
[this.TEST_ID_FIELD]: this.testId,
94-
expireAt: new Timestamp( // Expire test data after 24 hours
102+
[this.TTL_FIELD]: new Timestamp( // Expire test data after 24 hours
95103
Timestamp.now().seconds + 24 * 60 * 60,
96104
Timestamp.now().nanoseconds
97105
)
98106
};
99107
}
100108

109+
// Remove test-specific fields from a document, including the testId and expiration date.
110+
removeTestSpecificFieldsFromDoc(doc: DocumentData): DocumentData {
111+
doc._document?.data?.delete(field(this.TTL_FIELD));
112+
doc._document?.data?.delete(field(this.TEST_ID_FIELD));
113+
return doc;
114+
}
115+
101116
// Helper method to hash document keys and add test-specific fields for the provided documents.
102117
private prepareTestDocuments(docs: { [key: string]: DocumentData }): {
103118
[key: string]: DocumentData;
@@ -172,4 +187,34 @@ export class CompositeIndexTestHelper {
172187
) as WithFieldValue<T>;
173188
return setDocument(reference, processedData);
174189
}
190+
191+
// This is is the same as making the update on the doc directly with merge=true.
192+
updateDoc<T, DbModelType extends DocumentData>(
193+
reference: DocumentReference<T, DbModelType>,
194+
data: UpdateData<DbModelType>
195+
): Promise<void> {
196+
const processedData = this.addTestSpecificFieldsToDoc(
197+
data
198+
) as UpdateData<DbModelType>;
199+
return updateDocument(reference, processedData);
200+
}
201+
202+
203+
async getDoc<T, DbModelType extends DocumentData>(
204+
reference: DocumentReference<T, DbModelType>
205+
): Promise<DocumentSnapshot<T, DbModelType>> {
206+
const docSnapshot = await getDocument<T, DbModelType>(reference);
207+
this.removeTestSpecificFieldsFromDoc(docSnapshot);
208+
return docSnapshot;
209+
}
210+
211+
async getDocs<T, DbModelType extends DocumentData>(
212+
query_: Query<T, DbModelType>
213+
): Promise<QuerySnapshot<T, DbModelType>> {
214+
const querySnapshot = await getDocuments(this.query(query_));
215+
querySnapshot.forEach(doc => {
216+
this.removeTestSpecificFieldsFromDoc(doc);
217+
});
218+
return querySnapshot;
219+
}
175220
}

0 commit comments

Comments
 (0)