diff options
author | Gil <mcg@google.com> | 2018-02-22 08:26:22 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-22 08:26:22 -0800 |
commit | 4dc63f8d7cbf60417b88c6a77839ea32656627b9 (patch) | |
tree | 9e06e7c40b71caea3a89813a506c9aebccdf1401 /Firestore/core/test/firebase/firestore/auth | |
parent | 935f3ca7d749f96c7207236a39c57f32a02c05d3 (diff) |
Fix Firestore tests for M22 (#834)
* Add FIRFirestoreTests to the Firestore Xcode project
* Avoid waitForExpectations:timeout:
This API was added in Xcode 8.3, but we still build production releases
with Xcode 8.2. waitForExpectationsWithTimeout:handler: is available
from Xcode 7.2.
* Add AppForUnitTesting
Add a utility for constructing a Firebase App for testing.
* Handle the nil UID from FIRAuth
* Avoid running CMake tests twice
* Only build app_testing on Apple platforms
* Revise test.sh messages
Diffstat (limited to 'Firestore/core/test/firebase/firestore/auth')
-rw-r--r-- | Firestore/core/test/firebase/firestore/auth/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Firestore/core/test/firebase/firestore/auth/firebase_credentials_provider_test.mm | 71 |
2 files changed, 29 insertions, 43 deletions
diff --git a/Firestore/core/test/firebase/firestore/auth/CMakeLists.txt b/Firestore/core/test/firebase/firestore/auth/CMakeLists.txt index f470bd7..a6aa2ef 100644 --- a/Firestore/core/test/firebase/firestore/auth/CMakeLists.txt +++ b/Firestore/core/test/firebase/firestore/auth/CMakeLists.txt @@ -30,5 +30,6 @@ if(APPLE) firebase_credentials_provider_test.mm DEPENDS firebase_firestore_auth_apple + firebase_firestore_testutil ) endif(APPLE) diff --git a/Firestore/core/test/firebase/firestore/auth/firebase_credentials_provider_test.mm b/Firestore/core/test/firebase/firestore/auth/firebase_credentials_provider_test.mm index e98d3d8..a6ccc4a 100644 --- a/Firestore/core/test/firebase/firestore/auth/firebase_credentials_provider_test.mm +++ b/Firestore/core/test/firebase/firestore/auth/firebase_credentials_provider_test.mm @@ -21,6 +21,7 @@ #import <FirebaseCore/FIROptionsInternal.h> #include "Firestore/core/src/firebase/firestore/util/string_apple.h" +#include "Firestore/core/test/firebase/firestore/testutil/app_testing.h" #include "gtest/gtest.h" @@ -28,67 +29,51 @@ namespace firebase { namespace firestore { namespace auth { -// TODO(zxu123): Make this an integration test and get infos from environment. -// Set a .plist file here to enable the test-case. -static NSString* const kPlist = @""; - -class FirebaseCredentialsProviderTest : public ::testing::Test { - protected: - void SetUp() override { - app_ready_ = false; - if (![kPlist hasSuffix:@".plist"]) { - return; - } - - static dispatch_once_t once_token; - dispatch_once(&once_token, ^{ - FIROptions* options = [[FIROptions alloc] initWithContentsOfFile:kPlist]; - [FIRApp configureWithOptions:options]; - }); +FIRApp* AppWithFakeUid(NSString* _Nullable uid) { + FIRApp* app = testutil::AppForUnitTesting(); + app.getUIDImplementation = ^NSString* { + return uid; + }; + return app; +} - // Set getUID implementation. - FIRApp* default_app = [FIRApp defaultApp]; - default_app.getUIDImplementation = ^NSString* { - return @"I'm a fake uid."; - }; - app_ready_ = true; - } +TEST(FirebaseCredentialsProviderTest, GetTokenUnauthenticated) { + FIRApp* app = AppWithFakeUid(nil); - bool app_ready_; -}; + FirebaseCredentialsProvider credentials_provider(app); + credentials_provider.GetToken( + /*force_refresh=*/true, [](Token token, const absl::string_view error) { + EXPECT_EQ("", token.token()); + const User& user = token.user(); + EXPECT_EQ("", user.uid()); + EXPECT_FALSE(user.is_authenticated()); + EXPECT_EQ("", error) << error; + }); +} -// Set kPlist above before enable. -TEST_F(FirebaseCredentialsProviderTest, GetToken) { - if (!app_ready_) { - return; - } +TEST(FirebaseCredentialsProviderTest, GetToken) { + FIRApp* app = AppWithFakeUid(@"fake uid"); - FirebaseCredentialsProvider credentials_provider([FIRApp defaultApp]); + FirebaseCredentialsProvider credentials_provider(app); credentials_provider.GetToken( /*force_refresh=*/true, [](Token token, const absl::string_view error) { EXPECT_EQ("", token.token()); const User& user = token.user(); - EXPECT_EQ("I'm a fake uid.", user.uid()); + EXPECT_EQ("fake uid", user.uid()); EXPECT_TRUE(user.is_authenticated()); EXPECT_EQ("", error) << error; }); } -// Set kPlist above before enable. -TEST_F(FirebaseCredentialsProviderTest, SetListener) { - if (!app_ready_) { - return; - } +TEST(FirebaseCredentialsProviderTest, SetListener) { + FIRApp* app = AppWithFakeUid(@"fake uid"); - FirebaseCredentialsProvider credentials_provider([FIRApp defaultApp]); + FirebaseCredentialsProvider credentials_provider(app); credentials_provider.SetUserChangeListener([](User user) { - EXPECT_EQ("I'm a fake uid.", user.uid()); + EXPECT_EQ("fake uid", user.uid()); EXPECT_TRUE(user.is_authenticated()); }); - // TODO(wilhuff): We should wait for the above expectations to actually happen - // before continuing. - credentials_provider.SetUserChangeListener(nullptr); } |