Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Index sync status column #201

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())));

Expand Down