diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ServerToClientMessage.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ServerToClientMessage.java index b2133df86..b28e92288 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ServerToClientMessage.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ServerToClientMessage.java @@ -11,10 +11,10 @@ public abstract class ServerToClientMessage { public abstract void processMessage(); - private static final String TYPE_MAKE_CHANGES = "MakeChanges"; - private static final String TYPE_ACKNOWLEDGE_CHANGE = "AcknowledgeChange"; - private static final String TYPE_DOUBLE_CHECK = "DoubleCheck"; - private static final String TYPE_DEBUG = "Debug"; + public static final String TYPE_MAKE_CHANGES = "MakeChanges"; + public static final String TYPE_ACKNOWLEDGE_CHANGE = "AcknowledgeChange"; + public static final String TYPE_DOUBLE_CHECK = "DoubleCheck"; + public static final String TYPE_DEBUG = "Debug"; protected final JSONObject json; diff --git a/tests-sync/src/com/todoroo/astrid/sync/AstridNewSyncMigrationTest.java b/tests-sync/src/com/todoroo/astrid/sync/AstridNewSyncMigrationTest.java index 734238261..edc878a99 100644 --- a/tests-sync/src/com/todoroo/astrid/sync/AstridNewSyncMigrationTest.java +++ b/tests-sync/src/com/todoroo/astrid/sync/AstridNewSyncMigrationTest.java @@ -35,11 +35,11 @@ public class AstridNewSyncMigrationTest extends NewSyncTestCase { private void setupOldDatabase() { // Init 5 unsynced tasks and tags for (int i = 1; i <= 5; i++) { - Task task = createTask("Task " + i); + Task task = createTask("Task " + i, true); task.setValue(Task.REMOTE_ID, null); taskDao.save(task); - TagData tag = createTagData("Tag " + i); + TagData tag = createTagData("Tag " + i, true); tag.setValue(TagData.REMOTE_ID, null); tagDataDao.saveExisting(tag); } diff --git a/tests-sync/src/com/todoroo/astrid/sync/NewSyncTestCase.java b/tests-sync/src/com/todoroo/astrid/sync/NewSyncTestCase.java index 540462db9..f394aee69 100644 --- a/tests-sync/src/com/todoroo/astrid/sync/NewSyncTestCase.java +++ b/tests-sync/src/com/todoroo/astrid/sync/NewSyncTestCase.java @@ -5,6 +5,7 @@ import com.todoroo.astrid.dao.TagDataDao; import com.todoroo.astrid.dao.TagOutstandingDao; import com.todoroo.astrid.dao.TaskDao; import com.todoroo.astrid.dao.TaskOutstandingDao; +import com.todoroo.astrid.data.SyncFlags; import com.todoroo.astrid.data.TagData; import com.todoroo.astrid.data.Task; import com.todoroo.astrid.test.DatabaseTestCase; @@ -21,19 +22,25 @@ public class NewSyncTestCase extends DatabaseTestCase { protected TagOutstandingDao tagOutstandingDao; - protected Task createTask(String title) { + protected Task createTask(String title, boolean suppress) { Task task = new Task(); task.setValue(Task.TITLE, title); + if (suppress) + task.putTransitory(SyncFlags.ACTFM_SUPPRESS_OUTSTANDING_ENTRIES, true); taskDao.createNew(task); return task; } protected Task createTask() { - return createTask("new title"); + return createTask(false); } - protected TagData createTagData(String name) { + protected Task createTask(boolean suppress) { + return createTask("new title", suppress); + } + + protected TagData createTagData(String name, boolean suppress) { TagData tag = new TagData(); tag.setValue(TagData.NAME, name); @@ -42,6 +49,10 @@ public class NewSyncTestCase extends DatabaseTestCase { } protected TagData createTagData() { - return createTagData("new tag"); + return createTagData(false); + } + + protected TagData createTagData(boolean suppress) { + return createTagData("new tag", suppress); } } diff --git a/tests-sync/src/com/todoroo/astrid/sync/SyncMessageTest.java b/tests-sync/src/com/todoroo/astrid/sync/SyncMessageTest.java index 5f99c05bc..5d488c74d 100644 --- a/tests-sync/src/com/todoroo/astrid/sync/SyncMessageTest.java +++ b/tests-sync/src/com/todoroo/astrid/sync/SyncMessageTest.java @@ -1,6 +1,11 @@ package com.todoroo.astrid.sync; +import org.json.JSONException; +import org.json.JSONObject; + import com.todoroo.astrid.actfm.sync.messages.ChangesHappened; +import com.todoroo.astrid.actfm.sync.messages.NameMaps; +import com.todoroo.astrid.actfm.sync.messages.ServerToClientMessage; import com.todoroo.astrid.data.RemoteModel; import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.TaskOutstanding; @@ -19,4 +24,34 @@ public class SyncMessageTest extends NewSyncTestCase { } } + private static final String MAKE_CHANGES_TITLE = "Made changes to title"; + private JSONObject getMakeChanges() throws JSONException { + JSONObject makeChanges = new JSONObject(); + makeChanges.put("type", ServerToClientMessage.TYPE_MAKE_CHANGES); + makeChanges.put("table", NameMaps.SERVER_TABLE_TASKS); + JSONObject changes = new JSONObject(); + changes.put("title", MAKE_CHANGES_TITLE); + changes.put("importance", Task.IMPORTANCE_DO_OR_DIE); + makeChanges.put("changes", changes); + return makeChanges; + } + + public void testMakeChangesMakesChanges() { + Task t = createTask(); + try { + JSONObject makeChanges = getMakeChanges(); + makeChanges.put("uuid", t.getValue(Task.UUID)); + + ServerToClientMessage message = ServerToClientMessage.instantiateMessage(makeChanges); + message.processMessage(); + + t = taskDao.fetch(t.getId(), Task.TITLE, Task.IMPORTANCE); + assertEquals(MAKE_CHANGES_TITLE, t.getValue(Task.TITLE)); + assertEquals(Task.IMPORTANCE_DO_OR_DIE, t.getValue(Task.IMPORTANCE).intValue()); + } catch (JSONException e) { + e.printStackTrace(); + fail("JSONException"); + } + } + } diff --git a/tests-sync/src/com/todoroo/astrid/sync/SyncModelTest.java b/tests-sync/src/com/todoroo/astrid/sync/SyncModelTest.java index 53e6db200..bd2d35e37 100644 --- a/tests-sync/src/com/todoroo/astrid/sync/SyncModelTest.java +++ b/tests-sync/src/com/todoroo/astrid/sync/SyncModelTest.java @@ -6,6 +6,7 @@ import com.todoroo.andlib.data.TodorooCursor; import com.todoroo.andlib.sql.Criterion; import com.todoroo.andlib.sql.Query; import com.todoroo.astrid.data.RemoteModel; +import com.todoroo.astrid.data.SyncFlags; import com.todoroo.astrid.data.TagData; import com.todoroo.astrid.data.TagOutstanding; import com.todoroo.astrid.data.Task; @@ -84,4 +85,27 @@ public class SyncModelTest extends NewSyncTestCase { cursor.close(); } } + + public void testSuppressionFlagSuppressesOutstandingEntries() { + Task task = createTask(true); + TodorooCursor cursor = tagOutstandingDao.query(Query.select(TagOutstanding.PROPERTIES) + .where(TagOutstanding.TAG_DATA_ID.eq(task.getId()))); + try { + assertEquals(0, cursor.getCount()); + } finally { + cursor.close(); + } + + task.setValue(Task.TITLE, "new title"); + task.putTransitory(SyncFlags.ACTFM_SUPPRESS_OUTSTANDING_ENTRIES, true); + taskDao.save(task); + + cursor = tagOutstandingDao.query(Query.select(TagOutstanding.PROPERTIES) + .where(TagOutstanding.TAG_DATA_ID.eq(task.getId()))); + try { + assertEquals(0, cursor.getCount()); + } finally { + cursor.close(); + } + } }