@@ -11,9 +11,7 @@ import com.couchbase.learningpath.data.stockItem.StockItemRepositoryDb
1111import com.couchbase.learningpath.data.userprofile.UserProfileRepository
1212import com.couchbase.learningpath.data.warehouse.WarehouseRepository
1313import com.couchbase.learningpath.data.warehouse.WarehouseRepositoryDb
14- import com.couchbase.learningpath.models.Project
15- import com.couchbase.learningpath.models.User
16- import com.couchbase.learningpath.models.Warehouse
14+ import com.couchbase.learningpath.models.*
1715import com.couchbase.learningpath.services.MockAuthenticationService
1816import com.couchbase.lite.CouchbaseLiteException
1917import com.couchbase.lite.Dictionary
@@ -296,7 +294,8 @@ class DatabaseIntegrationTests {
296294 }
297295 }
298296
299- @Test fun testGetWarehouse (){
297+ @Test
298+ fun testGetWarehouse () {
300299 // arrange
301300 runTest {
302301 // act
@@ -308,19 +307,21 @@ class DatabaseIntegrationTests {
308307 }
309308 }
310309
311- @Test fun testWarehouseGetByCityState (){
310+ @Test
311+ fun testWarehouseGetByCityState () {
312312 // arrange
313313 runTest {
314- // act
314+ // act
315315 val warehouses = warehouseRepository.get()
316316 val warehouse1 = warehouses[0 ]
317317 val warehouse1CitySearch = warehouse1.city.substring(0 , 3 )
318318 val warehouse2 = warehouses[1 ]
319319 val warehouse2CitySearch = warehouse2.city.substring(0 , 3 )
320- val warehouse2StateSearch = warehouse2.state.substring(0 ,1 )
320+ val warehouse2StateSearch = warehouse2.state.substring(0 , 1 )
321321
322322 val warehouseResults1 = warehouseRepository.getByCityState(warehouse1CitySearch, null )
323- val warehouseResults2 = warehouseRepository.getByCityState(warehouse2CitySearch, warehouse2StateSearch)
323+ val warehouseResults2 =
324+ warehouseRepository.getByCityState(warehouse2CitySearch, warehouse2StateSearch)
324325
325326 // assert
326327 assertNotNull(warehouseResults1)
@@ -334,6 +335,112 @@ class DatabaseIntegrationTests {
334335 }
335336 }
336337
338+ @Test
339+ fun testGetAuditsByProjectId () {
340+ // arrange
341+ runTest {
342+ val projects = projectRepository.getDocuments(user1.team).first()
343+ val project = projects.first()
344+
345+ // act
346+ val audits = auditRepository.getAuditsByProjectId(project.projectId)?.first()
347+
348+ // assert
349+ assertNotNull(audits)
350+ assertEquals(50 , audits?.count())
351+ }
352+ }
353+
354+ @Test
355+ fun testGetAudit () {
356+ // arrange
357+ runTest {
358+ val projects = projectRepository.getDocuments(user1.team).first()
359+ val project = projects.first()
360+ val audits = auditRepository.getAuditsByProjectId(project.projectId)?.first()
361+ val audit = audits?.first()
362+
363+ // arrange
364+ assertNotNull(audit)
365+ audit?.let {
366+ val testAudit =
367+ auditRepository.get(projectId = project.projectId, auditId = it.auditId)
368+
369+ // assert
370+ assertNotNull(testAudit)
371+ assertEquals(it.auditId, testAudit.auditId)
372+ assertEquals(it.stockItem, testAudit.stockItem)
373+ assertEquals(it.notes, testAudit.notes)
374+ assertEquals(it.count, testAudit.count)
375+ assertEquals(it.team, testAudit.team)
376+ }
377+ }
378+ }
379+
380+ @Test
381+ fun testUpdateAuditStockItem () {
382+ // arrange
383+ runTest {
384+ val projects = projectRepository.getDocuments(user1.team).first()
385+ val project = projects.first()
386+ val audits = auditRepository.getAuditsByProjectId(project.projectId)?.first()
387+ val audit = audits?.first()
388+
389+ // arrange
390+ assertNotNull(audit)
391+ audit?.let {
392+ val stockItems = stockItemRepository.get()
393+ val stockItem = stockItems.random()
394+ auditRepository.updateAuditStockItem(it.projectId, it.auditId, stockItem)
395+ val testAudit = auditRepository.get(it.projectId, it.auditId)
396+
397+ // assert
398+ assertNotNull(testAudit)
399+ assertEquals(stockItem, testAudit.stockItem)
400+ }
401+ }
402+ }
403+
404+ @Test
405+ fun testGetStockItems () {
406+ // arrange
407+ runTest {
408+ // act
409+ val stockItems = stockItemRepository.get()
410+
411+ // assert
412+ assertEquals(3000 , stockItems.count())
413+ }
414+ }
415+
416+ @Test
417+ fun testStockItemCount (){
418+ // arrange
419+ runTest {
420+ // act
421+ val stockItemCount = stockItemRepository.count()
422+
423+ // assert
424+ assertEquals(3000 , stockItemCount)
425+ }
426+ }
427+
428+ @Test
429+ fun testGetStockItemsByNameDescription (){
430+ // arrange
431+ runTest {
432+ val stockItems = stockItemRepository.get()
433+ val stockItem = stockItems.first()
434+ // act
435+ val testStockItemsByName = stockItemRepository.getByNameDescription(stockItem.name.substring(0 ,5 ), null )
436+ val testStockItemsByNameDescription = stockItemRepository.getByNameDescription(stockItem.name.substring(0 , 2 ), stockItem.description.substring(0 , 2 ))
437+
438+ // assert
439+ assertTrue(testStockItemsByName.contains(stockItem))
440+ assertTrue(testStockItemsByNameDescription.contains(stockItem))
441+ }
442+ }
443+
337444 private fun getDemoUser1ProfileDictionary (): MutableMap <String , String > {
338445 val dict = mutableMapOf<String , String >()
339446 dict[" givenName" ] = demoUser1GivenName
@@ -344,15 +451,4 @@ class DatabaseIntegrationTests {
344451 dict[" documentType" ] = " user"
345452 return dict
346453 }
347-
348- private fun getDemoUser2ProfileDictionary (): MutableMap <String , String > {
349- val dict = mutableMapOf<String , String >()
350- dict[" givenName" ] = demoUser2GivenName
351- dict[" surname" ] = demoUser2Surname
352- dict[" jobTitle" ] = demoUser2JobTitle
353- dict[" team" ] = user2.team
354- dict[" email" ] = user2.username
355- dict[" documentType" ] = " user"
356- return dict
357- }
358454}
0 commit comments