deal with new folder description format
authorMichiel de Jong <michiel@unhosted.org>
Fri, 22 Nov 2013 12:44:37 +0000 (12:44 +0000)
committerMichiel de Jong <michiel@unhosted.org>
Fri, 22 Nov 2013 12:44:37 +0000 (12:44 +0000)
src/wireclient.js
test/unit/wireclient-suite.js

index d0673f3..eb21b2b 100644 (file)
         return promise;
       } else {
         return promise.then(function(status, body, contentType, revision) {
+          var tmp;
           if (status === 200 && typeof(body) === 'object') {
             if (Object.keys(body).length === 0) {
               // no children (coerce response to 'not found')
               status = 404;
-            } else {
+            } else if((Object.keys(body).length === 2)
+                && (body['@context']==='http://remotestorage.io/spec/folder-description')
+                && (typeof(body['items'])=='object')){
+              tmp = {};
+              for(var key in body.items) {
+                this._revisionCache[path + key] = body.items[key].ETag;
+                tmp[key] = body.items[key].ETag;
+              }
+              body = tmp;
+            } else {//pre-02 server
               for(var key in body) {
                 this._revisionCache[path + key] = body[key];
               }
index 207f1d2..31665ae 100644 (file)
@@ -322,6 +322,55 @@ define(['requirejs'], function(requirejs, undefined) {
       },
 
       {
+        desc: "#get unpacks pre-02 directory listings",
+        run: function(env, test) {
+          env.connectedClient.get('/foo/01/').
+            then(function(status, body, contentType) {
+              test.assertAnd(status, 200);
+              test.assertAnd(body, { a: 'qwer', 'b/': 'asdf' });
+              test.assert(contentType, 'application/json; charset=UTF-8');
+            });
+          var req = XMLHttpRequest.instances.shift();
+          req._responseHeaders['Content-Type'] = 'application/json; charset=UTF-8';
+          req.status = 200;
+          req.responseText = '{"a":"qwer","b/":"asdf"}';
+          req._onload();
+        }
+      },
+
+
+      {
+        desc: "#get unpacks -02 directory listings",
+        run: function(env, test) {
+          env.connectedClient.get('/foo/01/').
+            then(function(status, body, contentType) {
+              test.assertAnd(status, 200);
+              test.assertAnd(body, { a: 'qwer', 'b/': 'asdf' });
+              test.assert(contentType, 'application/json; charset=UTF-8');
+            });
+          var req = XMLHttpRequest.instances.shift();
+          req._responseHeaders['Content-Type'] = 'application/json; charset=UTF-8';
+          req.status = 200;
+          req.responseText = JSON.stringify({
+            "@context": "http://remotestorage.io/spec/folder-description",
+            items: {
+              a: {
+                "ETag": "qwer",
+                "Content-Length": 5,
+                "Content-Type": "text/html"
+              },
+              "b/": {
+                "ETag": "asdf",
+                "Content-Type":"application/json",
+                "Content-Length": 137
+              }
+            }
+          });
+          req._onload();
+        }
+      },
+
+      {
         desc: "#put encodes special characters in the path",
         run: function(env, test) {
           env.connectedClient.configure(undefined, undefined, 'draft-dejong-remotestorage-01');