diff --git a/opensrp-chw/src/main/java/org/smartregister/chw/dao/EventDao.java b/opensrp-chw/src/main/java/org/smartregister/chw/dao/EventDao.java index 343cc12fe1..b1db063555 100644 --- a/opensrp-chw/src/main/java/org/smartregister/chw/dao/EventDao.java +++ b/opensrp-chw/src/main/java/org/smartregister/chw/dao/EventDao.java @@ -32,7 +32,7 @@ public static void markEventsForReUpload() { * @return */ public static Long getMinimumVerifiedServerVersion() { - String sql = "select max(serverVersion) serverVersion from event where dateCreated <= (select min(dateCreated) minDate from event where ifnull(eventId,'') = '' and syncStatus = 'Synced') "; + String sql = "select max(serverVersion) serverVersion from event where dateCreated <= (select min(dateCreated) minDate from event where ifnull(eventId,'') = '' and syncStatus = 'Synced') "; DataMap dataMap = c -> { return getCursorLongValue(c, "serverVersion"); }; diff --git a/opensrp-chw/src/test/java/org/smartregister/chw/dao/EventDaoTest.java b/opensrp-chw/src/test/java/org/smartregister/chw/dao/EventDaoTest.java index 94afbbe300..45e3d6bf18 100644 --- a/opensrp-chw/src/test/java/org/smartregister/chw/dao/EventDaoTest.java +++ b/opensrp-chw/src/test/java/org/smartregister/chw/dao/EventDaoTest.java @@ -13,6 +13,7 @@ import org.robolectric.RobolectricTestRunner; import org.smartregister.clientandeventmodel.Event; import org.smartregister.dao.AbstractDao; +import org.smartregister.repository.BaseRepository; import org.smartregister.repository.Repository; import java.util.Arrays; @@ -37,7 +38,7 @@ public void setUp() { } @Test - public void getEvents() { + public void getEventsReturnsCorrectEvents() { MatrixCursor matrixCursor = new MatrixCursor(new String[]{"json"}); matrixCursor.addRow(new Object[]{eventJson}); Mockito.doReturn(matrixCursor).when(database).rawQuery(Mockito.any(), Mockito.any()); @@ -48,7 +49,7 @@ public void getEvents() { } @Test - public void getLatestEvent() { + public void getLatestEventReturnsCorrectEvent() { MatrixCursor matrixCursor = new MatrixCursor(new String[]{"json"}); matrixCursor.addRow(new Object[]{eventJson}); Mockito.doReturn(matrixCursor).when(database).rawQuery(Mockito.any(), Mockito.any()); @@ -56,5 +57,23 @@ public void getLatestEvent() { Assert.assertNotNull(event); } + @Test + public void markEventsForReUploadExecutesCorrectUpdateQueries() { + Mockito.doReturn(database).when(repository).getWritableDatabase(); + EventDao.markEventsForReUpload(); + Mockito.verify(database).rawExecSQL("update client set syncStatus = '" + BaseRepository.TYPE_Unsynced + "' where baseEntityId in (select baseEntityId from event where ifnull(eventId,'') = '') "); + Mockito.verify(database).rawExecSQL("update ImageList set syncStatus = '" + BaseRepository.TYPE_Unsynced + "' where entityId in (select baseEntityId from event where ifnull(eventId,'') = '') "); + Mockito.verify(database).rawExecSQL("update event set syncStatus = '" + BaseRepository.TYPE_Unsynced + "' where ifnull(eventId,'') = '' "); + } + + @Test + public void getMinimumVerifiedServerVersionReturnsCorrectVersion() { + MatrixCursor matrixCursor = new MatrixCursor(new String[]{"serverVersion"}); + matrixCursor.addRow(new Object[]{12324567L}); + Mockito.doReturn(matrixCursor).when(database).rawQuery(Mockito.any(), Mockito.any()); + Long serverVersion = EventDao.getMinimumVerifiedServerVersion(); + Assert.assertNotNull(serverVersion); + Assert.assertTrue(serverVersion.equals(12324567L)); + } } \ No newline at end of file