SessionStartEventTests.swift 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. //
  2. // Copyright 2022 Google LLC
  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. import XCTest
  16. @testable import FirebaseSessions
  17. class SessionStartEventTests: XCTestCase {
  18. var identifiers: MockIdentifierProvider!
  19. var time: MockTimeProvider!
  20. override func setUp() {
  21. super.setUp()
  22. identifiers = MockIdentifierProvider()
  23. time = MockTimeProvider()
  24. }
  25. func test_init_setsSessionIDs() {
  26. identifiers.mockAllValidIDs()
  27. let event = SessionStartEvent(identifiers: identifiers, time: time)
  28. assertEqualProtoString(
  29. event.proto.session_data.session_id,
  30. expected: MockIdentifierProvider.testSessionID,
  31. fieldName: "session_id"
  32. )
  33. assertEqualProtoString(
  34. event.proto.session_data.previous_session_id,
  35. expected: MockIdentifierProvider.testPreviousSessionID,
  36. fieldName: "previous_session_id"
  37. )
  38. XCTAssertEqual(event.proto.session_data.event_timestamp_us, 123)
  39. }
  40. func test_setInstallationID_setsInstallationID() {
  41. identifiers.mockAllValidIDs()
  42. let event = SessionStartEvent(identifiers: identifiers, time: time)
  43. event.setInstallationID(identifiers: identifiers)
  44. assertEqualProtoString(
  45. event.proto.session_data.firebase_installation_id,
  46. expected: MockIdentifierProvider.testInstallationID,
  47. fieldName: "firebase_installation_id"
  48. )
  49. }
  50. }