From 906fc127d476cd8b6af533d3800204ec741dcffc Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Wed, 9 Jan 2013 12:14:18 -0800 Subject: [PATCH] Added unit tests for MakeChanges to pushed_at --- .../todoroo/astrid/sync/SyncMessageTest.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests-sync/src/com/todoroo/astrid/sync/SyncMessageTest.java b/tests-sync/src/com/todoroo/astrid/sync/SyncMessageTest.java index 3ad68546d..2340c43f4 100644 --- a/tests-sync/src/com/todoroo/astrid/sync/SyncMessageTest.java +++ b/tests-sync/src/com/todoroo/astrid/sync/SyncMessageTest.java @@ -4,6 +4,8 @@ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; +import com.todoroo.andlib.utility.DateUtilities; +import com.todoroo.andlib.utility.Preferences; import com.todoroo.astrid.actfm.sync.ActFmSyncThread.ModelType; import com.todoroo.astrid.actfm.sync.messages.ChangesHappened; import com.todoroo.astrid.actfm.sync.messages.NameMaps; @@ -50,6 +52,22 @@ public class SyncMessageTest extends NewSyncTestCase { return makeChanges; } + private JSONObject getMakeChangesForPushedAt(long date) throws JSONException { + JSONObject makeChanges = new JSONObject(); + makeChanges.put("type", ServerToClientMessage.TYPE_MAKE_CHANGES); + makeChanges.put("table", NameMaps.TABLE_ID_PUSHED_AT); + makeChanges.put("uuid", NameMaps.TABLE_ID_TASKS); + + JSONArray changes = new JSONArray(); + JSONArray change1 = new JSONArray(); + change1.put("pushed_at"); + change1.put(date); + changes.put(change1); + + makeChanges.put("changes", changes); + return makeChanges; + } + public void testMakeChangesMakesChanges() { Task t = createTask(); try { @@ -68,6 +86,21 @@ public class SyncMessageTest extends NewSyncTestCase { } } + public void testMakeChangesToPushedAtValues() { + try { + long date = DateUtilities.now(); + JSONObject makeChanges = getMakeChangesForPushedAt(date); + + ServerToClientMessage message = ServerToClientMessage.instantiateMessage(makeChanges); + message.processMessage(); + + assertEquals(date, Preferences.getLong(NameMaps.PUSHED_AT_TASKS, 0)); + } catch (JSONException e) { + e.printStackTrace(); + fail("JSONException"); + } + } + public void testReplayOutstandingEntries() { Task t = createTask();