FIRMessagingInstanceTest.swift 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. FirebaseApp.configure(options: options)
  25. let original = Messaging.messaging()
  26. // Get and delete the default app.
  27. guard let defaultApp = FirebaseApp.app() else {
  28. XCTFail("Default app was not configured properly.")
  29. return
  30. }
  31. // The delete API is synchronous, so the default app will be deleted afterwards.
  32. defaultApp.delete { (success) in
  33. XCTAssertTrue(success, "FirebaseApp deletion should be successful")
  34. }
  35. XCTAssertNil(FirebaseApp.app(), "The default app should be `nil` at this point.")
  36. // Re-configure the app to trigger Messaging to re-instantiate.
  37. FirebaseApp.configure(options: options)
  38. // Get another instance of Messaging, make sure it's not the same instance.
  39. let postDelete = Messaging.messaging()
  40. XCTAssertNotEqual(original, postDelete)
  41. }
  42. }