Commit ddf61098 authored by Vincent Bechu's avatar Vincent Bechu Committed by Vincent Bechu

[test] Add scenarii to test and update saferepair storage to pass them

parent 5d6e60dd
/*global console, btoa, Blob*/ /*global console, btoa, Blob, RSVP*/
/*jslint nomen: true, maxlen: 200*/ /*jslint nomen: true, maxlen: 200*/
(function (window, QUnit, jIO, rJS) { (function (window, QUnit, jIO, rJS) {
"use strict"; "use strict";
...@@ -8,225 +8,71 @@ ...@@ -8,225 +8,71 @@
ok = QUnit.ok, ok = QUnit.ok,
stop = QUnit.stop, stop = QUnit.stop,
start = QUnit.start, start = QUnit.start,
deepEqual = QUnit.deepEqual; module = QUnit.module,
deepEqual = QUnit.deepEqual,
global = {defer: RSVP.defer()};
rJS(window) rJS(window)
.ready(function (g) { .ready(function () {
///////////////////////////
// Local storage
///////////////////////////
// return g.run({
// type: "query",
// sub_storage: {
// type: "uuid",
// sub_storage: {
// type: "document",
// document_id: "/",
// sub_storage: {
// type: "zip",
// sub_storage: {
// type: "local"
// }
// }
// }
// }
// });
///////////////////////////
// Memory storage
///////////////////////////
return g.run({
type: "query",
sub_storage: {
type: "uuid",
sub_storage: {
type: "union",
storage_list: [{
type: "memory"
}]
}
}
});
///////////////////////////
// WebSQL storage
///////////////////////////
// return g.run({
// type: "query",
// sub_storage: {
// type: "uuid",
// sub_storage: {
// "type": "websql",
// "database": "test"
// }
// }
// });
///////////////////////////
// IndexedDB storage
///////////////////////////
// return g.run({
// type: "query",
// sub_storage: {
// type: "uuid",
// sub_storage: {
// "type": "indexeddb",
// "database": "test"
// }
// }
// });
///////////////////////////
// DAV storage
///////////////////////////
// return g.run({
// type: "query",
// sub_storage: {
// type: "uuid",
// sub_storage: {
// type: "drivetojiomapping",
// sub_storage: {
// "type": "dav",
// "url": "DAVURL",
// "basic_login": btoa("LOGIN:PASSWD")
// }
// }
// }
// });
///////////////////////////
// Dropbox storage
///////////////////////////
// return g.run({
// type: "query",
// sub_storage: {
// type: "uuid",
// sub_storage: {
// type: "drivetojiomapping",
// sub_storage: {
// "type": "dropbox",
// "access_token" : "TOKEN",
// "root" : "dropbox"
// }
// }
// }
// });
///////////////////////////
// Qiniu storage
///////////////////////////
// return g.run({
// type: "query",
// sub_storage: {
// type: "uuid",
// sub_storage: {
// "type": "qiniu",
// "bucket": "BUCKET",
// "access_key": "ACCESSKEY",
// "secret_key": "SECRETKEY"
// }
// }
// });
///////////////////////////
// Replicate storage
///////////////////////////
// return g.run({
// type: "query",
// sub_storage: {
// type: "uuid",
// sub_storage: {
// type: "replicate",
// local_sub_storage: {
// type: "memory"
// },
// remote_sub_storage: {
// "type": "memory"
// }
// }
// }
// });
///////////////////////////
// Crypt storage
///////////////////////////
// return g.run({
// type: "query",
// sub_storage: {
// type: "uuid",
// sub_storage: {
// type: "crypt",
// key: {"alg": "A256GCM", "ext": true,
// "k": "seeaLzpu8dHG07bO2ANH2GywbTqs_zrs4Vq8zmtYeE4",
// "key_ops": ["encrypt", "decrypt"], "kty": "oct"},
// sub_storage: {
// type: "indexeddb",
// database: "test427"
// }
// }
// }
// });
global.gadget = this;
global.defer.resolve();
}) })
.declareMethod('run', function (jio_options) { .declareMethod('run', function (jio_options) {
test('Test "' + jio_options.type + '"scenario', function () { var jio;
var jio;
stop();
expect(14);
try {
jio = jIO.createJIO(jio_options);
} catch (error) {
console.error(error.stack);
console.error(error);
throw error;
}
// Try to fetch inexistent document try {
jio.get("inexistent") jio = jIO.createJIO(jio_options);
.fail(function (error) { } catch (error) {
console.error(error); console.error(error.stack);
if (error.status_code !== 404) { console.error(error);
throw error; throw error;
} }
equal(error.status_code, 404, "404 if inexistent");
// Post a document without ID // Try to fetch inexistent document
return jio.post({"title": "I don't have ID éà&\n"}); jio.get("inexistent")
}) .fail(function (error) {
.then(function (doc_id) { console.error(error);
ok(doc_id, "Document without ID created (" + doc_id + ")"); if (error.status_code !== 404) {
// Fetch the newly created document throw error;
return RSVP.all([ }
jio.get(doc_id), equal(error.status_code, 404, "404 if inexistent");
doc_id
]); // Post a document without ID
}) return jio.post({"title": "I don't have ID éà&\n"});
.then(function (result_list) { })
var doc = result_list[0], .then(function (doc_id) {
doc_id = result_list[1]; ok(doc_id, "Document without ID created (" + doc_id + ")");
deepEqual(doc, {"title": "I don't have ID éà&\n"}, // Fetch the newly created document
"Document correctly fetched"); return RSVP.all([
// Remove the doc jio.get(doc_id),
return jio.remove(doc_id); doc_id
}) ]);
.then(function (doc_id) { })
ok(doc_id, "Document removed"); .then(function (result_list) {
// Create some documents to check allDocs var doc = result_list[0],
return RSVP.all([ doc_id = result_list[1];
jio.put("id1", {"title": "1 ID", "int_index": 1}), deepEqual(doc, {"title": "I don't have ID éà&\n"},
jio.put("id2", {"title": "2 ID", "int_index": 2}), "Document correctly fetched");
jio.put("id3", {"title": "3 ID", "int_index": 3}) // Remove the doc
]); return jio.remove(doc_id);
}) })
.then(function (all_doc_id) { .then(function (doc_id) {
equal(all_doc_id[0], "id1", "Document 1 correctly created"); ok(doc_id, "Document removed");
equal(all_doc_id[1], "id2", "Document 2 correctly created"); // Create some documents to check allDocs
equal(all_doc_id[2], "id3", "Document 3 correctly created"); return RSVP.all([
jio.put("id1", {"title": "1 ID", "int_index": 1}),
jio.put("id2", {"title": "2 ID", "int_index": 2}),
jio.put("id3", {"title": "3 ID", "int_index": 3})
]);
})
.then(function (all_doc_id) {
equal(all_doc_id[0], "id1", "Document 1 correctly created");
equal(all_doc_id[1], "id2", "Document 2 correctly created");
equal(all_doc_id[2], "id3", "Document 3 correctly created");
// // Default allDocs call // // Default allDocs call
// return jio.allDocs(); // return jio.allDocs();
...@@ -248,94 +94,311 @@ ...@@ -248,94 +94,311 @@
// } // }
// }, "default allDocs OK"); // }, "default allDocs OK");
// Filter the result // Filter the result
console.log("START ALLDOCS"); console.log("START ALLDOCS");
return jio.allDocs({ return jio.allDocs({
query: 'title: "2 ID"', query: 'title: "2 ID"',
select_list: ["int_index"] select_list: ["int_index"]
}); });
}) })
.then(function (result) { .then(function (result) {
deepEqual(result, { deepEqual(result, {
data: { data: {
rows: [{ rows: [{
doc: {}, doc: {},
id: "id2", id: "id2",
value: {int_index: 2} value: {int_index: 2}
}], }],
total_rows: 1 total_rows: 1
} }
}, "filter allDocs OK"); }, "filter allDocs OK");
// XXX Check include docs, sort, limit, select
})
.then(function () {
return jio.getAttachment("inexistent", "enclosure")
.fail(function (error) {
equal(error.status_code, 404, "404 if inexistent");
console.log(error);
});
})
.then(function () {
return jio.put("foo❤/test.txt", {});
})
.then(function () {
return jio.putAttachment(
"foo❤/test.txt",
"enclosure",
new Blob(["fooé\nbar测试四😈"], {type: "text/plain"})
);
})
.then(function () {
ok(true, "Attachment stored");
return jio.getAttachment("foo❤/test.txt", "enclosure");
})
.then(function (blob) {
return jIO.util.readBlobAsText(blob);
})
.then(function (result) {
equal(result.target.result, "fooé\nbar测试四😈", "Attachment correctly fetched");
return jio.get("foo❤/test.txt");
})
.then(function (doc) {
deepEqual(doc, {}, "Document correctly fetched");
return jio.allAttachments("foo❤/test.txt");
})
.then(function (doc) {
deepEqual(doc, {
enclosure: {}
},
"Attachment list correctly fetched");
return jio.removeAttachment("foo❤/test.txt", "enclosure");
})
.then(function () { // XXX Check include docs, sort, limit, select
ok("Attachment removed"); })
})
.then(function () { .then(function () {
return jio.repair(); return jio.getAttachment("inexistent", "enclosure")
}) .fail(function (error) {
equal(error.status_code, 404, "404 if inexistent");
console.log(error);
});
})
.then(function () {
return jio.put("foo❤/test.txt", {});
})
.then(function () {
return jio.putAttachment(
"foo❤/test.txt",
"enclosure",
new Blob(["fooé\nbar测试四😈"], {type: "text/plain"})
);
})
.then(function () {
ok(true, "Attachment stored");
return jio.getAttachment("foo❤/test.txt", "enclosure");
})
.then(function (blob) {
return jIO.util.readBlobAsText(blob);
})
.then(function (result) {
equal(result.target.result, "fooé\nbar测试四😈", "Attachment correctly fetched");
return jio.get("foo❤/test.txt");
})
.then(function (doc) {
deepEqual(doc, {}, "Document correctly fetched");
return jio.allAttachments("foo❤/test.txt");
})
.then(function (doc) {
deepEqual(doc, {
enclosure: {}
},
"Attachment list correctly fetched");
return jio.removeAttachment("foo❤/test.txt", "enclosure");
})
.then(function () {
ok("Attachment removed");
})
.then(function () {
return jio.repair();
})
.fail(function (error) {
console.error("---");
console.error(error.stack);
console.error(error);
ok(false, error);
})
.always(function () {
start();
});
});
.fail(function (error) { module("scenario");
console.error("---"); ///////////////////////////
console.error(error.stack); // Memory storage
console.error(error); ///////////////////////////
ok(false, error); test('Test Memory Storage scenario', function () {
}) stop();
.always(function () { expect(14);
start(); return global.defer.promise
}); .then(function () {
return global.gadget.run({
type: "query",
sub_storage: {
type: "uuid",
sub_storage: {
type: "union",
storage_list: [{
type: "memory"
}]
}
}
});
}); });
}); });
///////////////////////////
// Local storage
///////////////////////////
test('Test Local Storage scenario', function () {
stop();
expect(14);
return global.defer.promise
.then(function () {
return global.gadget.run({
type: "query",
sub_storage: {
type: "uuid",
sub_storage: {
type: "document",
document_id: "/",
sub_storage: {
type: "zip",
sub_storage: {
type: "local"
}
}
}
}
});
});
});
///////////////////////////
// WebSQL storage
///////////////////////////
test('Test WebSQL Storage scenario', function () {
stop();
expect(14);
return global.defer.promise
.then(function () {
return global.gadget.run({
type: "query",
sub_storage: {
type: "uuid",
sub_storage: {
"type": "websql",
"database": "test"
}
}
});
});
});
///////////////////////////
// IndexedDB storage
///////////////////////////
test('Test IndexedDB Storage scenario', function () {
stop();
expect(14);
return global.defer.promise
.then(function () {
return global.gadget.run({
type: "query",
sub_storage: {
type: "uuid",
sub_storage: {
"type": "indexeddb",
"database": "test"
}
}
});
});
});
///////////////////////////
// DAV storage
///////////////////////////
test('Test DAV Storage scenario', function () {
stop();
expect(14);
return global.defer.promise
.then(function () {
return global.gadget.run({
type: "query",
sub_storage: {
type: "uuid",
sub_storage: {
type: "drivetojiomapping",
sub_storage: {
"type": "dav",
"url": "DAVURL",
"basic_login": btoa("LOGIN:PASSWD")
}
}
}
});
});
});
///////////////////////////
// Dropbox storage
///////////////////////////
test('Test Dropbox Storage scenario', function () {
stop();
expect(14);
return global.defer.promise
.then(function () {
return global.gadget.run({
type: "query",
sub_storage: {
type: "uuid",
sub_storage: {
type: "drivetojiomapping",
sub_storage: {
"type": "dropbox",
"access_token" : "TOKEN",
"root" : "dropbox"
}
}
}
});
});
});
///////////////////////////
// Qiniu storage
///////////////////////////
/*
test('Test Qiniu Storage scenario', function () {
stop();
expect(14);
return global.defer.promise
.then(function () {
return global.gadget.run({
type: "query",
sub_storage: {
type: "uuid",
sub_storage: {
"type": "qiniu",
"bucket": "BUCKET",
"access_key": "ACCESSKEY",
"secret_key": "SECRETKEY"
}
}
});
});
});
*/
///////////////////////////
// Replicate storage
///////////////////////////
test('Test Replicate Storage scenario', function () {
stop();
expect(14);
return global.defer.promise
.then(function () {
return global.gadget.run({
type: "query",
sub_storage: {
type: "uuid",
sub_storage: {
type: "replicate",
local_sub_storage: {
type: "memory"
},
remote_sub_storage: {
"type": "memory"
}
}
}
});
});
});
///////////////////////////
// Crypt storage
///////////////////////////
test('Test Crypt Storage scenario', function () {
stop();
expect(14);
return global.defer.promise
.then(function () {
return global.gadget.run({
type: "query",
sub_storage: {
type: "uuid",
sub_storage: {
type: "crypt",
key: {"alg": "A256GCM", "ext": true,
"k": "seeaLzpu8dHG07bO2ANH2GywbTqs_zrs4Vq8zmtYeE4",
"key_ops": ["encrypt", "decrypt"], "kty": "oct"},
sub_storage: {
type: "indexeddb",
database: "test427"
}
}
}
});
});
});
}(window, QUnit, jIO, rJS)); }(window, QUnit, jIO, rJS, RSVP));
...@@ -12,13 +12,8 @@ ...@@ -12,13 +12,8 @@
module = QUnit.module, module = QUnit.module,
ATTACHMENT = 'data', ATTACHMENT = 'data',
i, i,
<<<<<<< HEAD
name_list = ['get', 'post', 'put', 'buildQuery',
=======
name_list = ['get', 'post', 'put', 'remove', 'buildQuery', name_list = ['get', 'post', 'put', 'remove', 'buildQuery',
>>>>>>> 7ed9424... Scenario: init officejs scenario
'putAttachment', 'getAttachment', 'allAttachments']; 'putAttachment', 'getAttachment', 'allAttachments'];
/////////////////////////////////////////////////////// ///////////////////////////////////////////////////////
// Fake Storage // Fake Storage
/////////////////////////////////////////////////////// ///////////////////////////////////////////////////////
...@@ -154,11 +149,8 @@ ...@@ -154,11 +149,8 @@
check_remote_attachment_creation: true, check_remote_attachment_creation: true,
check_remote_attachment_deletion: true, check_remote_attachment_deletion: true,
check_local_deletion: false, check_local_deletion: false,
<<<<<<< HEAD
parallel_operation_amount: 10, parallel_operation_amount: 10,
parallel_operation_attachment_amount: 10, parallel_operation_attachment_amount: 10,
=======
>>>>>>> 7ed9424... Scenario: init officejs scenario
local_sub_storage: { local_sub_storage: {
type: "query", type: "query",
sub_storage: { sub_storage: {
......
/*jslint nomen: true*/ /*jslint indent:2,maxlen:80,nomen:true*/
(function (jIO) { /*global jIO, RSVP*/
(function (jIO, RSVP) {
"use strict"; "use strict";
/** /**
...@@ -88,4 +89,4 @@ ...@@ -88,4 +89,4 @@
jIO.addStorage('saferepair', SafeRepairStorage); jIO.addStorage('saferepair', SafeRepairStorage);
}(jIO)); }(jIO, RSVP));
...@@ -53,6 +53,11 @@ ...@@ -53,6 +53,11 @@
<script src="jio.storage/zipstorage.tests.js"></script> <script src="jio.storage/zipstorage.tests.js"></script>
<script src="jio.storage/gdrivestorage.tests.js"></script> <script src="jio.storage/gdrivestorage.tests.js"></script>
<script src="jio.storage/websqlstorage.tests.js"></script> <script src="jio.storage/websqlstorage.tests.js"></script>
<script src="../node_modules/renderjs/dist/renderjs-latest.js"></script>
<script src="../examples/scenario.js"></script>
<script src="../examples/scenario_officejs.js"></script>
<!--script src="../lib/jquery/jquery.min.js"></script> <!--script src="../lib/jquery/jquery.min.js"></script>
<script src="../src/jio.storage/xwikistorage.js"></script> <script src="../src/jio.storage/xwikistorage.js"></script>
<script src="jio.storage/xwikistorage.tests.js"></script--> <script src="jio.storage/xwikistorage.tests.js"></script-->
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment