@@ -13,6 +13,7 @@ import com.google.common.truth.Truth.assertThat
13
13
import io.element.android.libraries.core.coroutine.CoroutineDispatchers
14
14
import io.element.android.libraries.matrix.session.SessionData
15
15
import io.element.android.libraries.sessionstorage.api.LoggedInState
16
+ import io.element.android.libraries.sessionstorage.api.LoginType
16
17
import kotlinx.coroutines.ExperimentalCoroutinesApi
17
18
import kotlinx.coroutines.test.UnconfinedTestDispatcher
18
19
import kotlinx.coroutines.test.runTest
@@ -122,7 +123,7 @@ class DatabaseSessionStoreTest {
122
123
}
123
124
124
125
@Test
125
- fun `update session update all fields except loginTimestamp ` () = runTest {
126
+ fun `update session update all fields except info used by the application ` () = runTest {
126
127
val firstSessionData = SessionData (
127
128
userId = " userId" ,
128
129
deviceId = " deviceId" ,
@@ -137,6 +138,10 @@ class DatabaseSessionStoreTest {
137
138
passphrase = " aPassphrase" ,
138
139
sessionPath = " sessionPath" ,
139
140
cachePath = " cachePath" ,
141
+ position = 0 ,
142
+ lastUsageIndex = 0 ,
143
+ userDisplayName = " userDisplayName" ,
144
+ userAvatarUrl = " userAvatarUrl" ,
140
145
)
141
146
val secondSessionData = SessionData (
142
147
userId = " userId" ,
@@ -150,8 +155,12 @@ class DatabaseSessionStoreTest {
150
155
isTokenValid = 1 ,
151
156
loginType = null ,
152
157
passphrase = " aPassphraseAltered" ,
153
- sessionPath = " sessionPath" ,
154
- cachePath = " cachePath" ,
158
+ sessionPath = " sessionPathAltered" ,
159
+ cachePath = " cachePathAltered" ,
160
+ position = 1 ,
161
+ lastUsageIndex = 1 ,
162
+ userDisplayName = " userDisplayNameAltered" ,
163
+ userAvatarUrl = " userAvatarUrlAltered" ,
155
164
)
156
165
assertThat(firstSessionData.userId).isEqualTo(secondSessionData.userId)
157
166
assertThat(firstSessionData.loginTimestamp).isNotEqualTo(secondSessionData.loginTimestamp)
@@ -172,6 +181,11 @@ class DatabaseSessionStoreTest {
172
181
assertThat(alteredSession.loginTimestamp).isEqualTo(firstSessionData.loginTimestamp)
173
182
assertThat(alteredSession.oidcData).isEqualTo(secondSessionData.oidcData)
174
183
assertThat(alteredSession.passphrase).isEqualTo(secondSessionData.passphrase)
184
+ // Check that application data have not been altered
185
+ assertThat(alteredSession.position).isEqualTo(firstSessionData.position)
186
+ assertThat(alteredSession.lastUsageIndex).isEqualTo(firstSessionData.lastUsageIndex)
187
+ assertThat(alteredSession.userDisplayName).isEqualTo(firstSessionData.userDisplayName)
188
+ assertThat(alteredSession.userAvatarUrl).isEqualTo(firstSessionData.userAvatarUrl)
175
189
}
176
190
177
191
@Test
@@ -186,10 +200,14 @@ class DatabaseSessionStoreTest {
186
200
loginTimestamp = 1 ,
187
201
oidcData = " aOidcData" ,
188
202
isTokenValid = 1 ,
189
- loginType = null ,
203
+ loginType = LoginType . PASSWORD .name ,
190
204
passphrase = " aPassphrase" ,
191
205
sessionPath = " sessionPath" ,
192
206
cachePath = " cachePath" ,
207
+ position = 0 ,
208
+ lastUsageIndex = 0 ,
209
+ userDisplayName = " userDisplayName" ,
210
+ userAvatarUrl = " userAvatarUrl" ,
193
211
)
194
212
val secondSessionData = SessionData (
195
213
userId = " userIdUnknown" ,
@@ -201,10 +219,14 @@ class DatabaseSessionStoreTest {
201
219
loginTimestamp = 2 ,
202
220
oidcData = " aOidcDataAltered" ,
203
221
isTokenValid = 1 ,
204
- loginType = null ,
222
+ loginType = LoginType . PASSWORD .name ,
205
223
passphrase = " aPassphraseAltered" ,
206
- sessionPath = " sessionPath" ,
207
- cachePath = " cachePath" ,
224
+ sessionPath = " sessionPathAltered" ,
225
+ cachePath = " cachePathAltered" ,
226
+ position = 1 ,
227
+ lastUsageIndex = 1 ,
228
+ userDisplayName = " userDisplayNameAltered" ,
229
+ userAvatarUrl = " userAvatarUrlAltered" ,
208
230
)
209
231
assertThat(firstSessionData.userId).isNotEqualTo(secondSessionData.userId)
210
232
@@ -214,14 +236,6 @@ class DatabaseSessionStoreTest {
214
236
// Get the session and check that it has not been altered
215
237
val notAlteredSession = databaseSessionStore.getSession(firstSessionData.userId)!! .toDbModel()
216
238
217
- assertThat(notAlteredSession.userId).isEqualTo(firstSessionData.userId)
218
- assertThat(notAlteredSession.deviceId).isEqualTo(firstSessionData.deviceId)
219
- assertThat(notAlteredSession.accessToken).isEqualTo(firstSessionData.accessToken)
220
- assertThat(notAlteredSession.refreshToken).isEqualTo(firstSessionData.refreshToken)
221
- assertThat(notAlteredSession.homeserverUrl).isEqualTo(firstSessionData.homeserverUrl)
222
- assertThat(notAlteredSession.slidingSyncProxy).isEqualTo(firstSessionData.slidingSyncProxy)
223
- assertThat(notAlteredSession.loginTimestamp).isEqualTo(firstSessionData.loginTimestamp)
224
- assertThat(notAlteredSession.oidcData).isEqualTo(firstSessionData.oidcData)
225
- assertThat(notAlteredSession.passphrase).isEqualTo(firstSessionData.passphrase)
239
+ assertThat(notAlteredSession).isEqualTo(firstSessionData)
226
240
}
227
241
}
0 commit comments