-
Notifications
You must be signed in to change notification settings - Fork 22
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
base: master
Are you sure you want to change the base?
Issue fix sync pr1855 #2111
Changes from all commits
7631c7a
23019f4
bdd3029
ee49309
7460b7d
f882d63
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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); | ||
|
||
// flag all contentious events as unsynced | ||
EventDao.markEventsForReUpload(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not add a test for this? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
@@ -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,57 @@ | ||
package org.smartregister.chw.sync; | ||
|
||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.MockitoAnnotations; | ||
import org.powermock.reflect.Whitebox; | ||
import org.robolectric.RuntimeEnvironment; | ||
import org.smartregister.AllConstants; | ||
import org.smartregister.Context; | ||
import org.smartregister.CoreLibrary; | ||
import org.smartregister.SyncConfiguration; | ||
import org.smartregister.chw.BaseUnitTest; | ||
|
||
|
||
public class ChwSyncIntentServiceTest extends BaseUnitTest { | ||
|
||
|
||
ChwSyncIntentService chwSyncIntentService; | ||
|
||
@Mock | ||
Context context; | ||
|
||
@Mock | ||
private SyncConfiguration syncConfiguration; | ||
|
||
|
||
@Before | ||
public void setUp() { | ||
MockitoAnnotations.initMocks(this); | ||
CoreLibrary.init(context); | ||
Whitebox.setInternalState(CoreLibrary.getInstance(), "syncConfiguration", syncConfiguration); | ||
CoreLibrary.getInstance().context().allSharedPreferences().savePreference(AllConstants.DRISHTI_BASE_URL, "https://sample-stage.smartregister.org/opensrp"); | ||
chwSyncIntentService = Mockito.spy(new ChwSyncIntentService()); | ||
Whitebox.setInternalState(chwSyncIntentService, "mBase", RuntimeEnvironment.application); | ||
|
||
} | ||
|
||
@Test | ||
public void testHandleSync() { | ||
chwSyncIntentService.handleSync(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @junaidwarsivd I am not sure if testHandleSync() method is complete |
||
} | ||
|
||
@Test | ||
public void testGetEventPullLimit() { | ||
int eventPullLimit = chwSyncIntentService.getEventPullLimit(); | ||
assert (eventPullLimit == 1000); | ||
} | ||
|
||
@Test | ||
public void testGetEventBatchSize() { | ||
Integer eventBatchSize = chwSyncIntentService.getEventBatchSize(); | ||
assert (eventBatchSize == 250); | ||
} | ||
} |
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()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
|
@@ -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';"); | ||
} | ||
|
||
|
@@ -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;"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
|
||
} | ||
|
||
|
||
} | ||
|
||
|
There was a problem hiding this comment.
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