FIRMessagingInstanceTest.swift 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright 2019 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import FirebaseCore
  17. import FirebaseMessaging
  18. import XCTest
  19. class FIRMessagingInstanceTest: XCTestCase {
  20. func testSingleton_worksAfterDelete() {
  21. // This is an example of a functional test case.
  22. // Use XCTAssert and related functions to verify your tests produce the correct results.
  23. let options = FirebaseOptions(googleAppID: "1:123:ios:123abc", gcmSenderID: "valid-sender-id")
  24. options.apiKey = "AIzaSy-ApiKeyWithValidFormat_0123456789"
  25. options.projectID = "project-id"
  26. FirebaseApp.configure(options: options)
  27. let original = Messaging.messaging()
  28. // Get and delete the default app.
  29. guard let defaultApp = FirebaseApp.app() else {
  30. XCTFail("Default app was not configured properly.")
  31. return
  32. }
  33. // The delete API is synchronous, so the default app will be deleted afterwards.
  34. defaultApp.delete { success in
  35. XCTAssertTrue(success, "FirebaseApp deletion should be successful")
  36. }
  37. XCTAssertNil(FirebaseApp.app(), "The default app should be `nil` at this point.")
  38. // Re-configure the app to trigger Messaging to re-instantiate.
  39. FirebaseApp.configure(options: options)
  40. // Get another instance of Messaging, make sure it's not the same instance.
  41. let postDelete = Messaging.messaging()
  42. XCTAssertNotEqual(original, postDelete)
  43. }
  44. }