Skip to content

Commit

Permalink
Fix failing tests on EventClientRepository
Browse files Browse the repository at this point in the history
- Add more method documentation
  • Loading branch information
ekigamba committed Nov 1, 2022
1 parent 6b6f0f4 commit aea2c60
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ public static boolean shouldSchedule() {
return !allSharedPreferences.getBooleanPreference(AllConstants.PREF_KEY.DUPLICATE_IDS_FIXED);
}

/**
* Schedule this job to run periodically
*
* @param context
* @param mins - Duration after which the job repeatedly runs. This should be at least 15 mins
*/
public static void schedulePeriodically(Context context, int mins) {
PeriodicWorkRequest periodicWorkRequest = new PeriodicWorkRequest.Builder(DuplicateCleanerWorker.class, mins, TimeUnit.MINUTES)
.build();
Expand All @@ -49,7 +55,7 @@ public Result doWork() {

if (!allSharedPreferences.getBooleanPreference(AllConstants.PREF_KEY.DUPLICATE_IDS_FIXED)) {
DuplicateZeirIdStatus duplicateZeirIdStatus = AppHealthUtils.cleanUniqueZeirIds();
Timber.i("Doing some cleaning work");
Timber.i("Started doing duplicate client-identifier cleanup");
if (duplicateZeirIdStatus != null && duplicateZeirIdStatus.equals(DuplicateZeirIdStatus.CLEANED)) {
allSharedPreferences.saveBooleanPreference(AllConstants.PREF_KEY.DUPLICATE_IDS_FIXED, true);
WorkManager.getInstance(mContext).cancelWorkById(this.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ZeirIdCleanupRepository extends BaseRepository {
private static final String DUPLICATES_SQL =
"WITH duplicates AS ( " +
" WITH clients AS ( " +
" SELECT baseEntityId, COALESCE(json_extract(json, '$.identifiers.ZEIR_ID'), json_extract(json, '$.identifiers.M_ZEIR_ID'), json_extract(json, '$.identifiers.zeir_id'), json_extract(json, '$.identifiers.ANC_ID')) zeir_id" +
" SELECT baseEntityId, COALESCE(json_extract(json, '$.identifiers.ZEIR_ID'), json_extract(json, '$.identifiers.M_ZEIR_ID'), json_extract(json, '$.identifiers.zeir_id'), json_extract(json, '$.identifiers.ANC_ID')) zeir_id " +
" FROM client " +
" ) " +
" SELECT b.* FROM (SELECT baseEntityId, zeir_id FROM clients GROUP BY zeir_id HAVING count(zeir_id) > 1) a " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ public MatrixCursor getCursorMaxRowId() {
public void testCleanDuplicateMotherIdsShouldFixAndMarkDuplicateClientsUnSynced() throws Exception {
String DUPLICATES_SQL = "WITH duplicates AS ( " +
" WITH clients AS ( " +
" SELECT baseEntityId, COALESCE(json_extract(json, '$.identifiers.ZEIR_ID'), json_extract(json, '$.identifiers.M_ZEIR_ID')) zeir_id " +
" SELECT baseEntityId, COALESCE(json_extract(json, '$.identifiers.ZEIR_ID'), json_extract(json, '$.identifiers.M_ZEIR_ID'), json_extract(json, '$.identifiers.zeir_id'), json_extract(json, '$.identifiers.ANC_ID')) zeir_id " +
" FROM client " +
" ) " +
" SELECT b.* FROM (SELECT baseEntityId, zeir_id FROM clients GROUP BY zeir_id HAVING count(zeir_id) > 1) a " +
Expand All @@ -766,6 +766,7 @@ public void testCleanDuplicateMotherIdsShouldFixAndMarkDuplicateClientsUnSynced(
DuplicateZeirIdStatus duplicateZeirIdStatus = eventClientRepository.cleanDuplicateMotherIds();
Assert.assertEquals(DuplicateZeirIdStatus.CLEANED, duplicateZeirIdStatus);
verify(sqliteDatabase, times(1)).rawQuery(eq(DUPLICATES_SQL), any());
verify(sqliteDatabase, times(2)).rawQuery(eq("SELECT COUNT (*) FROM unique_ids WHERE status=?"), any());
verify(sqliteDatabase, times(1)).insert(eq("client"), eq(null), any());
}

Expand Down
5 changes: 5 additions & 0 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ repositories {
apply plugin: 'com.android.application'
apply plugin: 'org.smartregister.gradle.jarjar'


configurations.all {
all*.exclude group: 'com.google.guava', module: 'listenablefuture'
}

android {

compileSdkVersion androidCompileSdkVersion
Expand Down

0 comments on commit aea2c60

Please sign in to comment.