@@ -9,6 +9,7 @@ import com.x8bit.bitwarden.data.auth.datasource.disk.model.AccountJson
9
9
import com.x8bit.bitwarden.data.auth.datasource.disk.model.AccountTokensJson
10
10
import com.x8bit.bitwarden.data.auth.datasource.disk.model.UserStateJson
11
11
import com.x8bit.bitwarden.data.auth.datasource.disk.util.FakeAuthDiskSource
12
+ import com.x8bit.bitwarden.data.platform.error.NoActiveUserException
12
13
import com.x8bit.bitwarden.data.platform.manager.ReviewPromptManager
13
14
import com.x8bit.bitwarden.data.platform.util.asFailure
14
15
import com.x8bit.bitwarden.data.platform.util.asSuccess
@@ -47,8 +48,10 @@ import io.mockk.coVerify
47
48
import io.mockk.every
48
49
import io.mockk.just
49
50
import io.mockk.mockk
51
+ import io.mockk.mockkConstructor
50
52
import io.mockk.mockkStatic
51
53
import io.mockk.runs
54
+ import io.mockk.unmockkConstructor
52
55
import io.mockk.unmockkStatic
53
56
import io.mockk.verify
54
57
import kotlinx.coroutines.test.runTest
@@ -93,12 +96,17 @@ class CipherManagerTest {
93
96
@BeforeEach
94
97
fun setup () {
95
98
mockkStatic(Uri ::class )
99
+ mockkConstructor(NoActiveUserException ::class )
100
+ every {
101
+ anyConstructed<NoActiveUserException >() == any<NoActiveUserException >()
102
+ } returns true
96
103
}
97
104
98
105
@AfterEach
99
106
fun tearDown () {
100
107
unmockkStatic(Uri ::class , Instant ::class )
101
108
unmockkStatic(Cipher ::toEncryptedNetworkCipherResponse)
109
+ unmockkConstructor(NoActiveUserException ::class )
102
110
}
103
111
104
112
@Test
@@ -607,7 +615,10 @@ class CipherManagerTest {
607
615
cipherView = mockk(),
608
616
)
609
617
610
- assertEquals(DeleteAttachmentResult .Error , result)
618
+ assertEquals(
619
+ DeleteAttachmentResult .Error (error = NoActiveUserException ()),
620
+ result,
621
+ )
611
622
}
612
623
613
624
@Suppress(" MaxLineLength" )
@@ -617,20 +628,21 @@ class CipherManagerTest {
617
628
fakeAuthDiskSource.userState = MOCK_USER_STATE
618
629
val cipherId = " mockId-1"
619
630
val attachmentId = " mockId-1"
631
+ val error = Throwable (" Fail" )
620
632
coEvery {
621
633
ciphersService.deleteCipherAttachment(
622
634
cipherId = cipherId,
623
635
attachmentId = attachmentId,
624
636
)
625
- } returns Throwable ( " Fail " ) .asFailure()
637
+ } returns error .asFailure()
626
638
627
639
val result = cipherManager.deleteCipherAttachment(
628
640
cipherId = cipherId,
629
641
attachmentId = attachmentId,
630
642
cipherView = createMockCipherView(number = 1 ),
631
643
)
632
644
633
- assertEquals(DeleteAttachmentResult .Error , result)
645
+ assertEquals(DeleteAttachmentResult .Error (error = error) , result)
634
646
}
635
647
636
648
@Suppress(" MaxLineLength" )
@@ -1138,7 +1150,7 @@ class CipherManagerTest {
1138
1150
fileUri = mockk(),
1139
1151
)
1140
1152
1141
- assertEquals(CreateAttachmentResult .Error , result)
1153
+ assertEquals(CreateAttachmentResult .Error ( NoActiveUserException ()) , result)
1142
1154
}
1143
1155
1144
1156
@Suppress(" MaxLineLength" )
@@ -1152,9 +1164,10 @@ class CipherManagerTest {
1152
1164
val mockCipherView = createMockCipherView(number = 1 )
1153
1165
val mockFileName = " mockFileName-1"
1154
1166
val mockFileSize = " 1"
1167
+ val error = Throwable (" Fail" )
1155
1168
coEvery {
1156
1169
vaultSdkSource.encryptCipher(userId = userId, cipherView = mockCipherView)
1157
- } returns Throwable ( " Fail " ) .asFailure()
1170
+ } returns error .asFailure()
1158
1171
1159
1172
val result = cipherManager.createAttachment(
1160
1173
cipherId = cipherId,
@@ -1164,7 +1177,7 @@ class CipherManagerTest {
1164
1177
fileUri = mockUri,
1165
1178
)
1166
1179
1167
- assertEquals(CreateAttachmentResult .Error , result)
1180
+ assertEquals(CreateAttachmentResult .Error (error = error) , result)
1168
1181
}
1169
1182
1170
1183
@Suppress(" MaxLineLength" )
@@ -1186,6 +1199,7 @@ class CipherManagerTest {
1186
1199
url = null ,
1187
1200
key = null ,
1188
1201
)
1202
+ val error = Throwable (" Fail" )
1189
1203
coEvery {
1190
1204
vaultSdkSource.encryptCipher(userId = userId, cipherView = mockCipherView)
1191
1205
} returns mockCipher.asSuccess()
@@ -1200,7 +1214,7 @@ class CipherManagerTest {
1200
1214
decryptedFilePath = mockFile.absolutePath,
1201
1215
encryptedFilePath = " ${mockFile.absolutePath} .enc" ,
1202
1216
)
1203
- } returns Throwable ( " Fail " ) .asFailure()
1217
+ } returns error .asFailure()
1204
1218
1205
1219
val result = cipherManager.createAttachment(
1206
1220
cipherId = cipherId,
@@ -1210,7 +1224,7 @@ class CipherManagerTest {
1210
1224
fileUri = mockUri,
1211
1225
)
1212
1226
1213
- assertEquals(CreateAttachmentResult .Error , result)
1227
+ assertEquals(CreateAttachmentResult .Error (error = error) , result)
1214
1228
}
1215
1229
1216
1230
@Suppress(" MaxLineLength" )
@@ -1225,12 +1239,13 @@ class CipherManagerTest {
1225
1239
val mockCipher = createMockSdkCipher(number = 1 , clock = clock)
1226
1240
val mockFileName = " mockFileName-1"
1227
1241
val mockFileSize = " 1"
1242
+ val error = Throwable (" Fail" )
1228
1243
coEvery {
1229
1244
vaultSdkSource.encryptCipher(userId = userId, cipherView = mockCipherView)
1230
1245
} returns mockCipher.asSuccess()
1231
1246
coEvery {
1232
1247
fileManager.writeUriToCache(fileUri = mockUri)
1233
- } returns Throwable ( " Fail " ) .asFailure()
1248
+ } returns error .asFailure()
1234
1249
1235
1250
val result = cipherManager.createAttachment(
1236
1251
cipherId = cipherId,
@@ -1240,7 +1255,7 @@ class CipherManagerTest {
1240
1255
fileUri = mockUri,
1241
1256
)
1242
1257
1243
- assertEquals(CreateAttachmentResult .Error , result)
1258
+ assertEquals(CreateAttachmentResult .Error (error = error) , result)
1244
1259
}
1245
1260
1246
1261
@Suppress(" MaxLineLength" )
@@ -1263,6 +1278,7 @@ class CipherManagerTest {
1263
1278
)
1264
1279
val mockFile = File .createTempFile(" mockFile" , " temp" )
1265
1280
val mockAttachment = createMockSdkAttachment(number = 1 )
1281
+ val error = Throwable (" Fail" )
1266
1282
coEvery {
1267
1283
vaultSdkSource.encryptCipher(userId = userId, cipherView = mockCipherView)
1268
1284
} returns mockCipher.asSuccess()
@@ -1287,7 +1303,7 @@ class CipherManagerTest {
1287
1303
fileSize = mockFileSize,
1288
1304
),
1289
1305
)
1290
- } returns Throwable ( " Fail " ) .asFailure()
1306
+ } returns error .asFailure()
1291
1307
1292
1308
val result = cipherManager.createAttachment(
1293
1309
cipherId = cipherId,
@@ -1297,7 +1313,7 @@ class CipherManagerTest {
1297
1313
fileUri = mockUri,
1298
1314
)
1299
1315
1300
- assertEquals(CreateAttachmentResult .Error , result)
1316
+ assertEquals(CreateAttachmentResult .Error (error = error) , result)
1301
1317
}
1302
1318
1303
1319
@Suppress(" MaxLineLength" )
@@ -1321,6 +1337,7 @@ class CipherManagerTest {
1321
1337
val mockFile = File .createTempFile(" mockFile" , " temp" )
1322
1338
val mockAttachment = createMockSdkAttachment(number = 1 )
1323
1339
val mockAttachmentJsonResponse = createMockAttachmentJsonResponse(number = 1 )
1340
+ val error = Throwable (" Fail" )
1324
1341
coEvery {
1325
1342
vaultSdkSource.encryptCipher(userId = userId, cipherView = mockCipherView)
1326
1343
} returns mockCipher.asSuccess()
@@ -1351,7 +1368,7 @@ class CipherManagerTest {
1351
1368
attachmentJsonResponse = mockAttachmentJsonResponse,
1352
1369
encryptedFile = File (" ${mockFile.absoluteFile} .enc" ),
1353
1370
)
1354
- } returns Throwable ( " Fail " ) .asFailure()
1371
+ } returns error .asFailure()
1355
1372
1356
1373
val result = cipherManager.createAttachment(
1357
1374
cipherId = cipherId,
@@ -1361,7 +1378,7 @@ class CipherManagerTest {
1361
1378
fileUri = mockUri,
1362
1379
)
1363
1380
1364
- assertEquals(CreateAttachmentResult .Error , result)
1381
+ assertEquals(CreateAttachmentResult .Error (error = error) , result)
1365
1382
}
1366
1383
1367
1384
@Suppress(" MaxLineLength" )
@@ -1389,6 +1406,7 @@ class CipherManagerTest {
1389
1406
val mockUpdatedCipherResponse = createMockCipher(number = 1 ).copy(
1390
1407
collectionIds = listOf (" mockId-1" ),
1391
1408
)
1409
+ val error = Throwable (" Fail" )
1392
1410
coEvery {
1393
1411
vaultSdkSource.encryptCipher(userId = userId, cipherView = mockCipherView)
1394
1412
} returns mockCipher.asSuccess()
@@ -1428,7 +1446,7 @@ class CipherManagerTest {
1428
1446
userId = userId,
1429
1447
cipher = mockUpdatedCipherResponse.toEncryptedSdkCipher(),
1430
1448
)
1431
- } returns Throwable ( " Fail " ) .asFailure()
1449
+ } returns error .asFailure()
1432
1450
1433
1451
val result = cipherManager.createAttachment(
1434
1452
cipherId = cipherId,
@@ -1438,7 +1456,7 @@ class CipherManagerTest {
1438
1456
fileUri = mockUri,
1439
1457
)
1440
1458
1441
- assertEquals(CreateAttachmentResult .Error , result)
1459
+ assertEquals(CreateAttachmentResult .Error (error = error) , result)
1442
1460
}
1443
1461
1444
1462
@Suppress(" MaxLineLength" )
0 commit comments