| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- /*
- * Copyright 2023 Google LLC
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- import FirebaseFirestore
- import FirebaseFirestoreSwift
- import Foundation
- class IndexingTests: FSTIntegrationTestCase {
- func testAutoIndexCreationSetSuccessfully() throws {
- // Use persistent disk cache (explict)
- let settings = db.settings
- settings.cacheSettings = PersistentCacheSettings()
- db.settings = settings
- let coll = collectionRef()
- let testDocs = [
- "a": ["match": true],
- "b": ["match": false],
- "c": ["match": false],
- ]
- writeAllDocuments(testDocs, toCollection: coll)
- coll.whereField("match", isEqualTo: true)
- .getDocuments(source: .cache) { querySnapshot, err in
- XCTAssertNil(err)
- XCTAssertEqual(querySnapshot!.count, 1)
- }
- let enableIndexAutoCreation = {
- try FSTExceptionCatcher.catchException {
- self.db.persistentCacheIndexManager!.enableIndexAutoCreation()
- }
- }
- XCTAssertNoThrow(try enableIndexAutoCreation())
- coll.whereField("match", isEqualTo: true)
- .getDocuments(source: .cache) { querySnapshot, err in
- XCTAssertNil(err)
- XCTAssertEqual(querySnapshot!.count, 1)
- }
- let disableIndexAutoCreation = {
- try FSTExceptionCatcher.catchException {
- self.db.persistentCacheIndexManager!.disableIndexAutoCreation()
- }
- }
- XCTAssertNoThrow(try disableIndexAutoCreation())
- coll.whereField("match", isEqualTo: true)
- .getDocuments(source: .cache) { querySnapshot, err in
- XCTAssertNil(err)
- XCTAssertEqual(querySnapshot!.count, 1)
- }
- let deleteAllIndexes = {
- try FSTExceptionCatcher.catchException {
- self.db.persistentCacheIndexManager!.deleteAllIndexes()
- }
- }
- XCTAssertNoThrow(try deleteAllIndexes())
- coll.whereField("match", isEqualTo: true)
- .getDocuments(source: .cache) { querySnapshot, err in
- XCTAssertNil(err)
- XCTAssertEqual(querySnapshot!.count, 1)
- }
- }
- func testAutoIndexCreationSetSuccessfullyUsingDefault() throws {
- // Use persistent disk cache (default)
- let coll = collectionRef()
- let testDocs = [
- "a": ["match": true],
- "b": ["match": false],
- "c": ["match": false],
- ]
- writeAllDocuments(testDocs, toCollection: coll)
- coll.whereField("match", isEqualTo: true)
- .getDocuments(source: .cache) { querySnapshot, err in
- XCTAssertNil(err)
- XCTAssertEqual(querySnapshot!.count, 1)
- }
- let enableIndexAutoCreation = {
- try FSTExceptionCatcher.catchException {
- self.db.persistentCacheIndexManager!.enableIndexAutoCreation()
- }
- }
- XCTAssertNoThrow(try enableIndexAutoCreation())
- coll.whereField("match", isEqualTo: true)
- .getDocuments(source: .cache) { querySnapshot, err in
- XCTAssertNil(err)
- XCTAssertEqual(querySnapshot!.count, 1)
- }
- let disableIndexAutoCreation = {
- try FSTExceptionCatcher.catchException {
- self.db.persistentCacheIndexManager!.disableIndexAutoCreation()
- }
- }
- XCTAssertNoThrow(try disableIndexAutoCreation())
- coll.whereField("match", isEqualTo: true)
- .getDocuments(source: .cache) { querySnapshot, err in
- XCTAssertNil(err)
- XCTAssertEqual(querySnapshot!.count, 1)
- }
- let deleteAllIndexes = {
- try FSTExceptionCatcher.catchException {
- self.db.persistentCacheIndexManager!.deleteAllIndexes()
- }
- }
- XCTAssertNoThrow(try deleteAllIndexes())
- coll.whereField("match", isEqualTo: true)
- .getDocuments(source: .cache) { querySnapshot, err in
- XCTAssertNil(err)
- XCTAssertEqual(querySnapshot!.count, 1)
- }
- }
- }
|