From 76420add0ba31269cc1644c6aac79a351817d332 Mon Sep 17 00:00:00 2001
From: Lloyd Hilaiel <lloyd@hilaiel.com>
Date: Wed, 2 May 2012 22:22:32 -0600
Subject: [PATCH] add tests and update documentation of new storage. functions
 to support interaction data collection

---
 resources/static/shared/storage.js            | 15 ++++----
 resources/static/test/cases/shared/storage.js | 35 +++++++++++++++++++
 2 files changed, 43 insertions(+), 7 deletions(-)

diff --git a/resources/static/shared/storage.js b/resources/static/shared/storage.js
index 16cd8cd13..f87cff944 100644
--- a/resources/static/shared/storage.js
+++ b/resources/static/shared/storage.js
@@ -505,30 +505,31 @@ BrowserID.Storage = (function() {
 
     interactionData: {
       /**
-       * add a data interaction blob to localstorage
+       * add a new interaction blob to localstorage, this will *push* any stored
+       * blobs to the 'completed' backlog, and happens when a new dialog interaction
+       * begins.
        * @param {object} data - an object to push onto the queue
        * @method interactionData.push()
        * @returns nada
        */
       push: pushInteractionData,
       /**
-       * read the current interaction data blob (the one on the top of the
-       * stack)
+       * read the interaction data blob associated with the current interaction
        * @method interactionData.current()
        * @returns a JSON object containing the latest interaction data blob
        */
       current: currentInteractionData,
       /**
-       * overwrite the current interaction data blob (the one on the top of the
-       * stack)
+       * overwrite the interaction data blob associated with the current interaction
        * @param {object} data - the object to overwrite current with
        * @method interactionData.setCurrent()
        */
       setCurrent: setCurrentInteractionData,
       /**
-       * get all the saved interaction data (returned as a JSON array)
+       * get all past saved interaction data (returned as a JSON array), excluding
+       * the "current" data (that which is being collected now).
        * @method interactionData.get()
-       * @returns an array, possibly of length zero if no interaction data is
+       * @returns an array, possibly of length zero if no past interaction data is
        * available
        */
       get: getAllInteractionData,
diff --git a/resources/static/test/cases/shared/storage.js b/resources/static/test/cases/shared/storage.js
index d9852da09..5bab4b78e 100644
--- a/resources/static/test/cases/shared/storage.js
+++ b/resources/static/test/cases/shared/storage.js
@@ -164,5 +164,40 @@
     storage.signInEmail.remove();
     equal(typeof storage.signInEmail.get(), "undefined", "after remove, signInEmail is empty");
   });
+
+  test("push interaction data and get current", function() {
+    storage.interactionData.push({ foo: "bar" });
+    equal(storage.interactionData.current().foo, "bar",
+          "after pushing new interaction data, it's returned from .current()");
+  });
+
+  test("set interaction data overwrites current", function() {
+    storage.interactionData.clear();
+    storage.interactionData.push({ foo: "bar" });
+    storage.interactionData.setCurrent({ foo: "baz" });
+    equal(storage.interactionData.current().foo, "baz",
+          "overwriting current interaction data works");
+    equal(storage.interactionData.get().length, 1,
+          "overwriting doesn't append");
+  });
+
+  test("clear interaction data", function() {
+    storage.interactionData.push({ foo: "bar" });
+    storage.interactionData.push({ foo: "bar" });
+    storage.interactionData.clear();
+    equal(storage.interactionData.get().length, 0,
+          "after clearing, interaction data is zero length");
+  });
+
+  test("get interaction data returns everything except current (in-progress) data", function() {
+    storage.interactionData.push({ foo: "old2" });
+    storage.interactionData.clear();
+    storage.interactionData.push({ foo: "old1" });
+    storage.interactionData.push({ foo: "current" });
+    var d = storage.interactionData.get();
+    equal(d.length, 2, "get() returns complete unpublished data blobs");
+    equal(d[0].foo, 'old1', "get() returns complete unpublished data blobs");
+    equal(d[1].foo, 'old2', "get() returns complete unpublished data blobs");
+  });
 }());
 
-- 
GitLab