diff --git a/gradle.properties b/gradle.properties index 91ec69d3..b77a47fc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -VERSION_NAME=5.1.0-SNAPSHOT +VERSION_NAME=5.1.1-SNAPSHOT VERSION_CODE=3 GROUP=org.smartregister POM_SETTING_DESCRIPTION=OpenSRP Client Immunization diff --git a/opensrp-immunization/src/main/java/org/smartregister/immunization/repository/VaccineRepository.java b/opensrp-immunization/src/main/java/org/smartregister/immunization/repository/VaccineRepository.java index bb969fa8..1a670d30 100644 --- a/opensrp-immunization/src/main/java/org/smartregister/immunization/repository/VaccineRepository.java +++ b/opensrp-immunization/src/main/java/org/smartregister/immunization/repository/VaccineRepository.java @@ -66,6 +66,7 @@ public class VaccineRepository extends BaseRepository { private static final String VACCINE_SQL = "CREATE TABLE vaccines (_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,base_entity_id VARCHAR NOT NULL,program_client_id VARCHAR NULL,name VARCHAR NOT NULL,calculation INTEGER,date DATETIME NOT NULL,anmid VARCHAR NULL,location_id VARCHAR NULL,sync_status VARCHAR, updated_at INTEGER NULL, UNIQUE(base_entity_id, program_client_id, name) ON CONFLICT IGNORE)"; private static final String BASE_ENTITY_ID_INDEX = "CREATE INDEX " + VACCINE_TABLE_NAME + "_" + BASE_ENTITY_ID + "_index ON " + VACCINE_TABLE_NAME + "(" + BASE_ENTITY_ID + " COLLATE NOCASE);"; private static final String UPDATED_AT_INDEX = "CREATE INDEX " + VACCINE_TABLE_NAME + "_" + UPDATED_AT_COLUMN + "_index ON " + VACCINE_TABLE_NAME + "(" + UPDATED_AT_COLUMN + ");"; + public static final String SYNC_STATUS_INDEX = "CREATE INDEX IF NOT EXISTS " + VACCINE_TABLE_NAME + "_" + SYNC_STATUS + "_index ON " + VACCINE_TABLE_NAME + "(" + SYNC_STATUS + ");"; public static String HIA2_Within = "Within"; public static String HIA2_Overdue = "Overdue"; @@ -81,6 +82,7 @@ public static void createTable(SQLiteDatabase database) { database.execSQL(VACCINE_SQL); database.execSQL(BASE_ENTITY_ID_INDEX); database.execSQL(UPDATED_AT_INDEX); + database.execSQL(SYNC_STATUS_INDEX); } public static void migrateCreatedAt(SQLiteDatabase database) { diff --git a/opensrp-immunization/src/test/java/org/smartregister/immunization/domain/ServiceScheduleTest.java b/opensrp-immunization/src/test/java/org/smartregister/immunization/domain/ServiceScheduleTest.java index b00baf35..ceb2b072 100644 --- a/opensrp-immunization/src/test/java/org/smartregister/immunization/domain/ServiceScheduleTest.java +++ b/opensrp-immunization/src/test/java/org/smartregister/immunization/domain/ServiceScheduleTest.java @@ -11,7 +11,9 @@ import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.rule.PowerMockRule; +import org.robolectric.util.ReflectionHelpers; import org.smartregister.Context; +import org.smartregister.domain.AlertStatus; import org.smartregister.immunization.BaseUnitTest; import org.smartregister.immunization.ImmunizationLibrary; import org.smartregister.immunization.repository.RecurringServiceRecordRepository; @@ -149,4 +151,18 @@ public void isServiceIssuedShouldReturnTrueWhenServiceIsWithinServiceRecords() { Assert.assertTrue(ServiceSchedule.isServiceIssued("bcg2", serviceRecords)); } + @Test + public void testCalculateAlertStatusShouldReturnNormalForTodayDate() { + AlertStatus status = ReflectionHelpers.callStaticMethod(ServiceSchedule.class, "calculateAlertStatus", + ReflectionHelpers.ClassParameter.from(DateTime.class, new DateTime())); + Assert.assertEquals(AlertStatus.normal, status); + } + + @Test + public void testCalculateAlertStatusShouldReturnNullForUpcomingDate() { + AlertStatus status = ReflectionHelpers.callStaticMethod(ServiceSchedule.class, "calculateAlertStatus", + ReflectionHelpers.ClassParameter.from(DateTime.class, new DateTime().plusDays(10))); + Assert.assertNull(status); + } + } diff --git a/opensrp-immunization/src/test/java/org/smartregister/immunization/domain/VaccinationClientTest.java b/opensrp-immunization/src/test/java/org/smartregister/immunization/domain/VaccinationClientTest.java new file mode 100644 index 00000000..d0c7b1c9 --- /dev/null +++ b/opensrp-immunization/src/test/java/org/smartregister/immunization/domain/VaccinationClientTest.java @@ -0,0 +1,26 @@ +package org.smartregister.immunization.domain; + +import org.joda.time.DateTime; +import org.junit.Assert; +import org.junit.Test; +import org.smartregister.immunization.BaseUnitTest; + +public class VaccinationClientTest extends BaseUnitTest { + + + @Test + public void testSetBaseEntityIdSetsTheCorrectValue() { + VaccinationClient client = new VaccinationClient(); + client.setBaseEntityId("baseEntityId"); + Assert.assertEquals("baseEntityId", client.getBaseEntityId()); + } + + @Test + public void testSetBirthDateTimeSetsTheCorrectValue() { + VaccinationClient client = new VaccinationClient(); + DateTime dateTime = new DateTime(); + client.setBirthDateTime(dateTime); + Assert.assertEquals(dateTime, client.getBirthDateTime()); + } + +} diff --git a/opensrp-immunization/src/test/java/org/smartregister/immunization/repository/VaccineRepositoryTest.java b/opensrp-immunization/src/test/java/org/smartregister/immunization/repository/VaccineRepositoryTest.java index 53046cbd..4e8fa29d 100644 --- a/opensrp-immunization/src/test/java/org/smartregister/immunization/repository/VaccineRepositoryTest.java +++ b/opensrp-immunization/src/test/java/org/smartregister/immunization/repository/VaccineRepositoryTest.java @@ -122,7 +122,7 @@ public void verifyUpdateHia2StatusTest() { @Test public void verifyCreateTableTest() { VaccineRepository.createTable(sqliteDatabase); - Mockito.verify(sqliteDatabase, Mockito.times(3)).execSQL(ArgumentMatchers.anyString()); + Mockito.verify(sqliteDatabase, Mockito.times(4)).execSQL(ArgumentMatchers.anyString()); } @Test diff --git a/opensrp-immunization/src/test/java/org/smartregister/immunization/utils/VaccinateActionUtilsTest.java b/opensrp-immunization/src/test/java/org/smartregister/immunization/utils/VaccinateActionUtilsTest.java index 09867a3a..2ff3cfd9 100644 --- a/opensrp-immunization/src/test/java/org/smartregister/immunization/utils/VaccinateActionUtilsTest.java +++ b/opensrp-immunization/src/test/java/org/smartregister/immunization/utils/VaccinateActionUtilsTest.java @@ -326,7 +326,7 @@ public void assertMoreThanThreeMonthsReturnsTrueForDatesMoreThanThreeMonths() { Assert.assertFalse(VaccinateActionUtils.moreThanThreeMonths(new Date(dateTime.getMillis()))); dateTime = new DateTime(); - dateTime = dateTime.minusMonths(3).minusHours(1); + dateTime = dateTime.minusMonths(3).minusDays(1).minusHours(1); Assert.assertTrue(VaccinateActionUtils.moreThanThreeMonths(new Date(dateTime.getMillis())));