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

Issue fix sync pr1855 #2111

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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 build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ allprojects {
maven { url "https://cloudant.github.io/cloudant-sync-eap/repository" }
maven { url 'https://maven.fabric.io/public' }
maven { url "https://s3.amazonaws.com/repo.commonsware.com" }
maven { url 'https://nexus.pentaho.org/content/groups/omni/' }
//maven { url 'https://nexus.pentaho.org/content/groups/omni/' }
maven {
url 'https://dl.bintray.com/ibm-watson-health/ibm-fhir-server-releases'
content {
Expand Down
2 changes: 1 addition & 1 deletion opensrp-chw/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ android {
versionName "1.0.8"
buildConfigField "int", "OPENMRS_UNIQUE_ID_INITIAL_BATCH_SIZE", '10000'
buildConfigField "int", "OPENMRS_UNIQUE_ID_BATCH_SIZE", '10000'
buildConfigField "int", "OPENMRS_UNIQUE_ID_SOURCE", '2'
buildConfigField "int", "OPENMRS_UNIQUE_ID_SOURCE", '1'
buildConfigField "String", 'opensrp_url', '"https://boresha-afya.smartregister.org/opensrp/"'
buildConfigField "String", 'guidebooks_url', '"https://opensrp.s3.amazonaws.com/media/ba/"'
buildConfigField "String", 'opensrp_url_debug', '"https://boresha-afya-stage.smartregister.org/opensrp/"'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
package org.smartregister.chw.sync;

import org.smartregister.chw.dao.EventDao;
import org.smartregister.sync.intent.SyncIntentService;

public class ChwSyncIntentService extends SyncIntentService {

@Override
protected void handleSync() {
// fetch the last downloaded serverVersion before any unsyced data
Long serverVersion = EventDao.getMinimumVerifiedServerVersion();
if (serverVersion != null)
org.smartregister.util.Utils.getAllSharedPreferences().saveLastSyncDate(serverVersion);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this try to sync already synced events and clients? I just want to understand this


// flag all contentious events as unsynced
EventDao.markEventsForReUpload();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not add a test for this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ekigamba this is the Protected method writing a unit test might not be applicable for it

super.handleSync();
}


@Override
public int getEventPullLimit() {
return 1000;
Expand All @@ -12,6 +26,6 @@ public int getEventPullLimit() {

@Override
protected Integer getEventBatchSize(){
return 50;
return 250;
} // Should this be configurable?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.smartregister.chw.util;

import android.app.Activity;
import android.os.Bundle;

import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentMatchers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.smartregister.commonregistry.CommonPersonObjectClient;

import static org.mockito.Mockito.verify;

public class AllClientsUtilsTest {


@Mock
Activity mockActivity;

@Mock
CommonPersonObjectClient mockPatient;

@Mock
Bundle mockBundle;


@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
}

@Test
public void testGoToChildProfile() {
AllClientsUtils.goToChildProfile(mockActivity, mockPatient, mockBundle);
verify(mockActivity).startActivity(ArgumentMatchers.any());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Kindly update this test to match the expected activity class here
  2. Check that the intent has the correct extras as expected

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import org.smartregister.chw.application.ChwApplication;
import org.smartregister.repository.EventClientRepository;

import static org.mockito.Mockito.verify;

@RunWith(RobolectricTestRunner.class)
@Config(application = ChwApplication.class, sdk = 22)
public class RepositoryUtilsTest {
Expand All @@ -35,7 +37,7 @@ public void updateNullEventIdsUpdatesCorrectEvents() {
ArgumentMatchers.any(String[].class), ArgumentMatchers.eq("eventId IS NULL AND validationStatus = ?"),
ArgumentMatchers.any(String[].class), ArgumentMatchers.isNull(), ArgumentMatchers.isNull(), ArgumentMatchers.isNull());
RepositoryUtils.updateNullEventIds(database);
Mockito.verify(database).execSQL("UPDATE event SET eventId = '3b598b80-13ee-4a9a-8cd1-8e66fa76bbe9', " +
verify(database).execSQL("UPDATE event SET eventId = '3b598b80-13ee-4a9a-8cd1-8e66fa76bbe9', " +
"syncStatus = 'Synced' WHERE formSubmissionId = '45a294f5-ec2f-4233-847a-6f7910a6e63f';");
}

Expand Down Expand Up @@ -131,4 +133,16 @@ private static String getSampleEventJSONString() {
"}";
}


@Test
public void testAddDetailsColumnToFamilySearchTable() throws Exception {

SQLiteDatabase database = Mockito.mock(SQLiteDatabase.class);
RepositoryUtils.addDetailsColumnToFamilySearchTable(database);

verify(database).execSQL("ALTER TABLE ec_family ADD COLUMN entity_type VARCHAR; UPDATE ec_family SET entity_type = 'ec_family' WHERE id is not null;");

verify(database).execSQL("ALTER TABLE ec_family ADD COLUMN entity_type VARCHAR; UPDATE ec_family SET entity_type = 'ec_family' WHERE id is not null;");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Kindly remove the duplicated verification here
  2. Test/assert that the fields are added to the FTS table

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,51 @@

import android.app.Activity;
import android.os.Environment;
import android.view.Menu;

import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.bottomnavigation.LabelVisibilityMode;

import org.jetbrains.annotations.NotNull;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.smartregister.chw.BaseUnitTest;
import org.smartregister.chw.BuildConfig;
import org.smartregister.chw.R;
import org.smartregister.chw.application.ChwApplication;
import org.smartregister.chw.core.utils.Utils;
import org.smartregister.chw.model.ReferralTypeModel;
import org.smartregister.helper.BottomNavigationHelper;

import java.util.Arrays;
import java.util.List;

import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.smartregister.chw.util.Utils.addHyphenBetweenNumbers;
import static org.smartregister.chw.util.Utils.formatDateForVisual;
import static org.smartregister.chw.util.Utils.getClientName;
import static org.smartregister.chw.util.Utils.getFormattedDateFromTimeStamp;

public class UtilsTest extends BaseUnitTest {

@Mock
BottomNavigationHelper mockBottomNavigationHelper;

@Mock
BottomNavigationView mockBottomNavigationView;

@Mock
BottomNavigationView.OnNavigationItemSelectedListener mockListener;

@Mock
Menu menu;

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
Expand Down Expand Up @@ -123,4 +144,22 @@ public void testAddHyphenBetweenNumbers() {
Assert.assertEquals("Ali is around 2-3 years old", addHyphenBetweenNumbers("Ali is around 2 3 years old"));
Assert.assertEquals("Ali is around 2 years old", addHyphenBetweenNumbers("Ali is around 2 years old"));
}

@Test
public void testSetupBottomNavigation() {

when(mockBottomNavigationView.getMenu()).thenReturn(menu);

org.smartregister.chw.util.Utils.setupBottomNavigation(mockBottomNavigationHelper, mockBottomNavigationView, mockListener);
verify(mockBottomNavigationView).setLabelVisibilityMode(LabelVisibilityMode.LABEL_VISIBILITY_LABELED);
verify(mockBottomNavigationView).inflateMenu(R.menu.bottom_nav_menu);
verify(mockBottomNavigationHelper).disableShiftMode(mockBottomNavigationView);
verify(mockBottomNavigationView).setOnNavigationItemSelectedListener(mockListener);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we verify if the QR, job aids and reports items are removed if the flavor does not have them



}


}