|
| 1 | +/* |
| 2 | + * Copyright (c) 2014-2026 Stream.io Inc. All rights reserved. |
| 3 | + * |
| 4 | + * Licensed under the Stream 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 | + * https://github.com/GetStream/stream-video-android/blob/main/LICENSE |
| 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 | + |
| 17 | +package io.getstream.video.android.core |
| 18 | + |
| 19 | +import com.google.common.truth.Truth.assertThat |
| 20 | +import io.getstream.video.android.core.sorting.participant |
| 21 | +import io.getstream.video.android.core.sorting.stubCallActions |
| 22 | +import kotlinx.coroutines.CoroutineScope |
| 23 | +import kotlinx.coroutines.test.StandardTestDispatcher |
| 24 | +import kotlinx.coroutines.test.TestCoroutineScheduler |
| 25 | +import org.junit.Test |
| 26 | +import org.threeten.bp.OffsetDateTime |
| 27 | +import org.threeten.bp.ZoneOffset |
| 28 | +import stream.video.sfu.models.Participant |
| 29 | + |
| 30 | +class ParticipantStateJoinedAtTest { |
| 31 | + |
| 32 | + private val scope = CoroutineScope(StandardTestDispatcher(TestCoroutineScheduler())) |
| 33 | + |
| 34 | + @Test |
| 35 | + fun `joinedAt keeps the instant the SFU sent`() { |
| 36 | + val state = participant("session", scope, stubCallActions()) |
| 37 | + |
| 38 | + state.updateFromParticipantInfo( |
| 39 | + Participant( |
| 40 | + session_id = "session", |
| 41 | + joined_at = java.time.Instant.parse("2026-10-22T08:15:30.123456789Z"), |
| 42 | + ), |
| 43 | + ) |
| 44 | + |
| 45 | + assertThat(state.joinedAt.value) |
| 46 | + .isEqualTo(OffsetDateTime.of(2026, 10, 22, 8, 15, 30, 123_456_789, ZoneOffset.UTC)) |
| 47 | + } |
| 48 | + |
| 49 | + @Test |
| 50 | + fun `joinedAt falls back to now when the SFU sends none`() { |
| 51 | + val state = participant("session", scope, stubCallActions()) |
| 52 | + val before = OffsetDateTime.now(ZoneOffset.UTC) |
| 53 | + |
| 54 | + state.updateFromParticipantInfo(Participant(session_id = "session")) |
| 55 | + |
| 56 | + val joinedAt = state.joinedAt.value!! |
| 57 | + assertThat(joinedAt).isAtLeast(before) |
| 58 | + assertThat(joinedAt).isAtMost(OffsetDateTime.now(ZoneOffset.UTC)) |
| 59 | + } |
| 60 | +} |
0 commit comments