ChildSyncService implements SyncService<Child> { public String getSyncPath(Child child, User currentUser) throws JSONException { if (currentUser.isVerified()) { return child.isNew() ? CHILDREN_API_PATH : new StringBuilder(CHILDREN_API_PATH) .append("/").append(child.get(internal_id.getColumnName())).toString(); } else { return UNVERIFIED_USER_CHILDREN_API_PATH; } } @Inject  ChildSyncService(RapidFtrApplication context, EntityHttpDao<Child> childHttpDao, ChildRepository childRepository); @Override Child sync(Child child, User currentUser); String getSyncPath(Child child, User currentUser); @Override void setMedia(Child child); @Override int getNotificationId(); @Override String getNotificationTitle(); @Override void setLastSyncedAt(Child child); @Override Child getRecord(String resourceUrl); List<String> getIdsToDownload(); static final String CHILDREN_API_PATH; static final String CHILDREN_API_PARAMETER; static final String UNVERIFIED_USER_CHILDREN_API_PATH; }
@Test public void shouldNotIncludeCouchDbIdInSyncPathIfUnavailable() throws Exception { Child child = new Child("id1", "user1", "{ 'test1' : 'value1' }"); ChildSyncService childSyncService = new ChildSyncService(mockContext(), childHttpDao, repository); assertEquals("/api/children", childSyncService.getSyncPath(child, currentUser)); }
@Test public void shouldIncludeCouchDbIdInSyncPathIfAvailable() throws Exception { Child child = new Child("id1", "user1", "{ 'test1' : 'value1' }"); child.put(Database.ChildTableColumn.internal_id.getColumnName(), "xyz"); ChildSyncService childSyncService = new ChildSyncService(mockContext(), childHttpDao, repository); assertEquals("/api/children/xyz", childSyncService.getSyncPath(child, currentUser)); }
@Test public void shouldReutrnUnverifiedPathIfUserIsNotVerified() throws JSONException { Child child = new Child("id1", "user1", "{ 'test1' : 'value1' }"); doReturn(false).when(currentUser).isVerified(); ChildSyncService childSyncService = new ChildSyncService(mockContext(), childHttpDao, repository); assertEquals("/api/children/unverified", childSyncService.getSyncPath(child, currentUser)); }