Commit fa6ae79d authored by Sven Franck's avatar Sven Franck Committed by Sebastien Robin

jslint pass dummystorages.js

parent a497d65a
/*global window, define */
// Adds 5 dummy storages to JIO // Adds 5 dummy storages to JIO
// type: // type:
// - dummyallok // - dummyallok
...@@ -6,19 +7,23 @@ ...@@ -6,19 +7,23 @@
// - dummyall3tries // - dummyall3tries
// - dummyalldocs // - dummyalldocs
// - dummyallfound // - dummyallfound
(function () { var jioDummyStorageLoader = function ( jIO ) { (function () {
'use strict';
var jioDummyStorageLoader = function (jIO) {
//////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Dummy Storage 1 : all ok // Dummy Storage 1 : all ok
var newDummyStorageAllOk = function ( spec, my ) { var newDummyStorageAllOk = function (spec, my) {
var that = my.basicStorage( spec, my ); var that = my.basicStorage(spec, my);
that.specToStore = function () { that.specToStore = function () {
return {"username":spec.username}; return {
"username": spec.username
};
}; };
that.post = function (command) { that.post = function (command) {
setTimeout (function () { window.setTimeout(function () {
that.success({ that.success({
"ok": true, "ok": true,
"id": command.getDocId() "id": command.getDocId()
...@@ -27,8 +32,8 @@ ...@@ -27,8 +32,8 @@
}; // end post }; // end post
that.put = function (command) { that.put = function (command) {
setTimeout (function () { window.setTimeout(function () {
that.success ({ that.success({
"ok": true, "ok": true,
"id": command.getDocId() "id": command.getDocId()
}); });
...@@ -36,44 +41,48 @@ ...@@ -36,44 +41,48 @@
}; // end put }; // end put
that.putAttachment = function (command) { that.putAttachment = function (command) {
setTimeout (function () { window.setTimeout(function () {
that.success ({ that.success({
"ok": true, "ok": true,
"id": command.getDocId()+"/"+command.getAttachmentId() "id": command.getDocId() + "/" +
command.getAttachmentId()
}); });
}, 100); // 100 ms, for jiotests simple job waiting }, 100); // 100 ms, for jiotests simple job waiting
}; // end putAttachment }; // end putAttachment
that.get = function (command) { that.get = function (command) {
setTimeout(function () { window.setTimeout(function () {
if (command.getAttachmentId()) { if (command.getAttachmentId()) {
return that.success ('0123456789'); return that.success('0123456789');
} }
that.success ({ that.success({
"_id": command.getDocId(), "_id": command.getDocId(),
"title":'get_title' "title": 'get_title'
}); });
}, 100); // 100 ms, for jiotests simple job waiting }, 100); // 100 ms, for jiotests simple job waiting
}; // end get }; // end get
that.allDocs = function (command) { that.allDocs = function (command) {
setTimeout(function () { window.setTimeout(function () {
that.error({ that.error({
"status": 405, "status": 405,
"statusText": "Method Not Allowed", "statusText": "Method Not Allowed",
"error": "method_not_allowed", "error": "method_not_allowed",
"message": "Your are not allowed to use this command", "message": "Your are not allowed to use" +
"reason": "LocalStorage forbids AllDocs command executions" "this command",
"reason": "LocalStorage forbids AllDocs" +
"command executions"
}); });
}); });
}; // end allDocs }; // end allDocs
that.remove = function (command) { that.remove = function (command) {
setTimeout (function () { window.setTimeout(function () {
if (command.getAttachmentId()) { if (command.getAttachmentId()) {
that.success({ that.success({
"ok": true, "ok": true,
"id": command.getDocId()+"/"+command.getAttachmentId() "id": command.getDocId() + "/" +
command.getAttachmentId()
}); });
} else { } else {
that.success({ that.success({
...@@ -87,19 +96,24 @@ ...@@ -87,19 +96,24 @@
return that; return that;
}, },
// end Dummy Storage All Ok // end Dummy Storage All Ok
////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
// Dummy Storage 2 : all fail // Dummy Storage 2 : all fail
newDummyStorageAllFail = function ( spec, my ) { newDummyStorageAllFail = function (spec, my) {
var that = my.basicStorage( spec, my ), priv = {}; var that = my.basicStorage(spec, my),
priv = {};
priv.error = function () { priv.error = function () {
setTimeout (function () { window.setTimeout(function () {
that.error ({status:0,statusText:'Unknown Error', that.error({
error:'unknown_error', status: 0,
message:'Execution encountred an error.', statusText: 'Unknown Error',
reason:'Execution encountred an error'}); error: 'unknown_error',
message: 'Execution encountred an error.',
reason: 'Execution encountred an error'
});
}, 100); }, 100);
}; };
...@@ -120,13 +134,15 @@ ...@@ -120,13 +134,15 @@
}; // end get }; // end get
that.allDocs = function (command) { that.allDocs = function (command) {
setTimeout(function () { window.setTimeout(function () {
that.error({ that.error({
"status": 405, "status": 405,
"statusText": "Method Not Allowed", "statusText": "Method Not Allowed",
"error": "method_not_allowed", "error": "method_not_allowed",
"message": "Your are not allowed to use this command", "message": "Your are not allowed to use" +
"reason": "LocalStorage forbids AllDocs command executions" "this command",
"reason": "LocalStorage forbids AllDocs" +
"command executions"
}); });
}); });
}; // end allDocs }; // end allDocs
...@@ -137,16 +153,16 @@ ...@@ -137,16 +153,16 @@
return that; return that;
}, },
// end Dummy Storage All Fail // end Dummy Storage All Fail
//////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Dummy Storage 3 : all not found // Dummy Storage 3 : all not found
newDummyStorageAllNotFound = function ( spec, my ) { newDummyStorageAllNotFound = function (spec, my) {
var that = my.basicStorage( spec, my ); var that = my.basicStorage(spec, my);
that.post = function (command) { that.post = function (command) {
setTimeout (function () { window.setTimeout(function () {
that.success ({ that.success({
"ok": true, "ok": true,
"id": command.getDocId() "id": command.getDocId()
}); });
...@@ -154,8 +170,8 @@ ...@@ -154,8 +170,8 @@
}; // end post }; // end post
that.put = function (command) { that.put = function (command) {
setTimeout (function () { window.setTimeout(function () {
that.success ({ that.success({
"ok": true, "ok": true,
"id": command.getDocId() "id": command.getDocId()
}); });
...@@ -163,80 +179,82 @@ ...@@ -163,80 +179,82 @@
}; // end put }; // end put
that.putAttachment = function (command) { that.putAttachment = function (command) {
setTimeout (function () { window.setTimeout(function () {
that.success ({ that.success({
"ok": true, "ok": true,
"id": command.getDocId()+"/"+command.getAttachmentId() "id": command.getDocId() + "/" +
command.getAttachmentId()
}); });
}, 100); }, 100);
}; // end put }; // end put
that.get = function (command) { that.get = function (command) {
setTimeout(function () { window.setTimeout(function () {
that.error ({ that.error({
"status": 404, "status": 404,
"statusText": "Not Found", "statusText": "Not Found",
"error": "not_found", "error": "not_found",
"message": "Document '"+ command.getDocId() + "message": "Document '" + command.getDocId() +
"' not found", "' not found",
"reason": "Document '"+ command.getDocId() + "reason": "Document '" + command.getDocId() +
"' does not exist" "'does not exist"
}); });
}, 100); }, 100);
}; // end get }; // end get
that.allDocs = function (command) { that.allDocs = function (command) {
setTimeout(function () { window.setTimeout(function () {
that.error({ that.error({
"status": 405, "status": 405,
"statusText": "Method Not Allowed", "statusText": "Method Not Allowed",
"error": "method_not_allowed", "error": "method_not_allowed",
"message": "Your are not allowed to use this command", "message": "Your are not allowed to use" +
"reason": "LocalStorage forbids AllDocs command executions" "this command",
"reason": "LocalStorage forbids AllDocs" +
"command executions"
}); });
}); });
}; // end allDocs }; // end allDocs
that.remove = function (command) { that.remove = function (command) {
setTimeout (function () { window.setTimeout(function () {
that.error ({ that.error({
"status": 404, "status": 404,
"statusText": "Not Found", "statusText": "Not Found",
"error": "not_found", "error": "not_found",
"message": "Cannot remove an unexistant document", "message": "Cannot remove an unexistant" +
"document",
"reason": "missing" // or deleted "reason": "missing" // or deleted
}); });
}, 100); }, 100);
}; // end remove }; // end remove
return that; return that;
}, },
// end Dummy Storage All Not Found // end Dummy Storage All Not Found
//////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Dummy Storage 4 : all 3 tries // Dummy Storage 4 : all 3 tries
newDummyStorageAll3Tries = function ( spec, my ) { newDummyStorageAll3Tries = function (spec, my) {
var that = my.basicStorage( spec, my ), priv = {}; var that = my.basicStorage(spec, my),
priv = {};
// this specToStore method is used to make simple difference between // this specToStore method is used to make simple
// two dummyall3tries storages: // difference between two dummyall3tries storages:
// so {type:'dummyall3tries',a:'b'} differs from // so {type:'dummyall3tries',a:'b'} differs from
// {type:'dummyall3tries',c:'d'}. // {type:'dummyall3tries',c:'d'}.
that.specToStore = function () { that.specToStore = function () {
return {"application_name": spec.application_name}; return {
"application_name": spec.application_name
}; };
};
priv.doJob = function (command,if_ok_return) { priv.doJob = function (command, if_ok_return) {
// wait a little in order to simulate asynchronous operation // wait a little to simulate asynchronous operation
setTimeout(function () { window.setTimeout(function () {
priv.Try3OKElseFail (command.getTried(),if_ok_return); priv.Try3OKElseFail(command.getTried(),
if_ok_return);
}, 100); }, 100);
}; };
priv.Try3OKElseFail = function (tries, if_ok_return) {
priv.Try3OKElseFail = function (tries,if_ok_return) { if (tries === 'undefined') {
if ( typeof tries === 'undefined' ) { return that.error({
return that.error ({
"status": 0, "status": 0,
"statusText": "Unknown Error", "statusText": "Unknown Error",
"error": "unknown_error", "error": "unknown_error",
...@@ -244,15 +262,16 @@ ...@@ -244,15 +262,16 @@
"reason": "Unknown" "reason": "Unknown"
}); });
} }
if ( tries < 3 ) { if (tries < 3) {
return that.retry ( return that.retry({
{message:'' + (3 - tries) + ' tries left.'}); message: 'Now' + (3 - tries) + ' tries left.'
});
} }
if ( tries === 3 ) { if (tries === 3) {
return that.success (if_ok_return); return that.success(if_ok_return);
} }
if ( tries > 3 ) { if (tries > 3) {
return that.error ({ return that.error({
"status": 1, "status": 1,
"statusText": "Too Much Tries", "statusText": "Too Much Tries",
"error": "too_much_tries", "error": "too_much_tries",
...@@ -261,112 +280,116 @@ ...@@ -261,112 +280,116 @@
}); });
} }
}; };
that.post = function (command) { that.post = function (command) {
priv.doJob (command,{"ok": true,"id": command.getDocId()}); priv.doJob(command, {
"ok": true,
"id": command.getDocId()
});
}; // end post }; // end post
that.put = function (command) { that.put = function (command) {
priv.doJob (command,{"ok": true,"id": command.getDocId()}); priv.doJob(command, {
"ok": true,
"id": command.getDocId()
});
}; // end put }; // end put
that.putAttachment = function (command) { that.putAttachment = function (command) {
priv.doJob (command,{ priv.doJob(command, {
"ok": true, "ok": true,
"id": command.getDocId()+"/"+command.getAttachmentId() "id": command.getDocId() + "/" +
command.getAttachmentId()
}); });
}; // end put }; // end put
that.get = function (command) { that.get = function (command) {
if (command.getAttachmentId()) { if (command.getAttachmentId()) {
priv.doJob (command,"0123456789"); priv.doJob(command, "0123456789");
} else { } else {
priv.doJob (command,{ priv.doJob(command, {
"_id": command.getDocId(), "_id": command.getDocId(),
"title": 'Title of '+command.getDocId(), "title": 'Title of ' + command.getDocId()
}); });
} }
}; // end get }; // end get
that.allDocs = function (command) { that.allDocs = function (command) {
setTimeout(function () { window.setTimeout(function () {
that.error({ that.error({
"status": 405, "status": 405,
"statusText": "Method Not Allowed", "statusText": "Method Not Allowed",
"error": "method_not_allowed", "error": "method_not_allowed",
"message": "Your are not allowed to use this command", "message": "Your are not allowed to use" +
"reason": "LocalStorage forbids AllDocs command executions" "this command",
"reason": "LocalStorage forbids AllDocs" +
"command executions"
}); });
}); });
}; // end allDocs }; // end allDocs
that.remove = function (command) { that.remove = function (command) {
if (command.getAttachmentId()) { if (command.getAttachmentId()) {
priv.doJob(command,{ priv.doJob(command, {
"ok": true, "ok": true,
"id": command.getDocId()+"/"+command.getAttachmentId() "id": command.getDocId() + "/" +
command.getAttachmentId()
}); });
} else { } else {
priv.doJob(command,{"ok": true,"id": command.getDocId()}); priv.doJob(command, {
"ok": true,
"id": command.getDocId()
});
} }
}; // end remove }; // end remove
return that; return that;
}, },
// end Dummy Storage All 3 Tries // end Dummy Storage All 3 Tries
//////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Dummy Storage 5 : all docs // Dummy Storage 5 : all docs
newDummyStorageAllDocs = function (spec, my) { newDummyStorageAllDocs = function (spec, my) {
var that = my.basicStorage(spec, my); var that = my.basicStorage(spec, my);
that.specToStore = function () { that.specToStore = function () {
return {"username": spec.username}; return {
"username": spec.username
};
}; };
that.post = function (command) { that.post = function (command) {
setTimeout (function () { window.setTimeout(function () {
that.success({ that.success({
"ok": true, "ok": true,
"id": command.getDocId() "id": command.getDocId()
}); });
}, 100); // 100 ms, for jiotests simple job waiting }, 100); // 100 ms, for jiotests simple job waiting
}; // end post }; // end post
that.put = function (command) { that.put = function (command) {
setTimeout (function () { window.setTimeout(function () {
that.success ({ that.success({
"ok": true, "ok": true,
"id": command.getDocId() "id": command.getDocId()
}); });
}, 100); // 100 ms, for jiotests simple job waiting }, 100); // 100 ms, for jiotests simple job waiting
}; // end put }; // end put
that.putAttachment = function (command) { that.putAttachment = function (command) {
setTimeout (function () { window.setTimeout(function () {
that.success ({ that.success({
"ok": true, "ok": true,
"id": command.getDocId()+"/"+command.getAttachmentId() "id": command.getDocId() + "/" +
command.getAttachmentId()
}); });
}, 100); // 100 ms, for jiotests simple job waiting }, 100); // 100 ms, for jiotests simple job waiting
}; // end putAttachment }; // end putAttachment
that.get = function (command) { that.get = function (command) {
setTimeout(function () { window.setTimeout(function () {
if (command.getAttachmentId()) { if (command.getAttachmentId()) {
return that.success ('0123456789'); return that.success('0123456789');
} }
that.success ({ that.success({
"_id": command.getDocId(), "_id": command.getDocId(),
"title": "get_title" "title": "get_title"
}); });
}, 100); // 100 ms, for jiotests simple job waiting }, 100); // 100 ms, for jiotests simple job waiting
}; // end get }; // end get
that.allDocs = function (command) { that.allDocs = function (command) {
setTimeout(function () { window.setTimeout(function () {
var addRow, o = { var addRow,
o = {
"total_rows": 0, "total_rows": 0,
"rows": [] "rows": []
}; };
...@@ -377,33 +400,31 @@ ...@@ -377,33 +400,31 @@
"value": {} "value": {}
}; };
if (command.getOption("include_docs")) { if (command.getOption("include_docs")) {
row["doc"] = doc; row.doc = doc;
} }
o.rows.push(row); o.rows.push(row);
o.total_rows += 1; o.total_rows += 1;
}; };
addRow("file", "file", { addRow("file", "file", {
"_id": "file", "_id": "file",
"Title": "myFile", "Title": "myFile"
}); });
addRow( addRow("mylongtitledfilethatidontliketowriteby" +
"mylongtitledfilethatidontliketowritebyhandonablackboard", "handonablackboard", "mylongtialias1", {
"mylongti.alias1", "_id": "mylongtitledfilethatidontlike" +
{ "towritebyhandonablackboard",
"_id": "mylongtitledfilethatidontliketowritebyhandonablackboard", "Title": "myLongFile"
"Title": "myLongFile", });
}
);
that.success(o); that.success(o);
}); });
}; // end allDocs }; // end allDocs
that.remove = function (command) { that.remove = function (command) {
setTimeout (function () { window.setTimeout(function () {
if (command.getAttachmentId()) { if (command.getAttachmentId()) {
that.success({ that.success({
"ok": true, "ok": true,
"id": command.getDocId()+"/"+command.getAttachmentId() "id": command.getDocId() + "/" +
command.getAttachmentId()
}); });
} else { } else {
that.success({ that.success({
...@@ -413,19 +434,18 @@ ...@@ -413,19 +434,18 @@
} }
}, 100); // 100 ms, for jiotests simple job waiting }, 100); // 100 ms, for jiotests simple job waiting
}; // end remove }; // end remove
return that; return that;
}; },
// end Dummy Storage All Docs // end Dummy Storage All Docs
//////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Dummy Storage 6 : all found // Dummy Storage 6 : all found
newDummyStorageAllFound = function ( spec, my ) { newDummyStorageAllFound = function (spec, my) {
var that = my.basicStorage( spec, my ); var that = my.basicStorage(spec, my);
that.post = function (command) { that.post = function (command) {
setTimeout (function () { window.setTimeout(function () {
that.error({ that.error({
"status": 409, "status": 409,
"statusText": "Conflicts", "statusText": "Conflicts",
...@@ -435,55 +455,54 @@ ...@@ -435,55 +455,54 @@
}); });
}, 100); }, 100);
}; // end post }; // end post
that.put = function (command) { that.put = function (command) {
setTimeout (function () { window.setTimeout(function () {
that.success ({ that.success({
"ok": true, "ok": true,
"id": command.getDocId() "id": command.getDocId()
}); });
}, 100); }, 100);
}; // end put }; // end put
that.putAttachment = function (command) { that.putAttachment = function (command) {
setTimeout (function () { window.setTimeout(function () {
that.success ({ that.success({
"ok": true, "ok": true,
"id": command.getDocId()+"/"+command.getAttachmentId() "id": command.getDocId() + "/" +
command.getAttachmentId()
}); });
}, 100); }, 100);
}; // end put }; // end put
that.get = function (command) { that.get = function (command) {
setTimeout(function () { window.setTimeout(function () {
if (command.getAttachmentId()) { if (command.getAttachmentId()) {
return that.success ('0123456789'); return that.success('0123456789');
} }
that.success ({ that.success({
"_id": command.getDocId(), "_id": command.getDocId(),
"title":'get_title' "title": 'get_title'
}); });
}, 100); // 100 ms, for jiotests simple job waiting }, 100); // 100 ms, for jiotests simple job waiting
}; // end get }; // end get
that.allDocs = function (command) { that.allDocs = function (command) {
setTimeout(function () { window.setTimeout(function () {
that.error({ that.error({
"status": 405, "status": 405,
"statusText": "Method Not Allowed", "statusText": "Method Not Allowed",
"error": "method_not_allowed", "error": "method_not_allowed",
"message": "Your are not allowed to use this command", "message": "Your are not allowed to use" +
"reason": "LocalStorage forbids AllDocs command executions" "this command",
"reason": "LocalStorage forbids AllDocs" +
"command executions"
}); });
}); });
}; // end allDocs }; // end allDocs
that.remove = function (command) { that.remove = function (command) {
setTimeout (function () { window.setTimeout(function () {
if (command.getAttachmentId()) { if (command.getAttachmentId()) {
that.success({ that.success({
"ok": true, "ok": true,
"id": command.getDocId()+"/"+command.getAttachmentId() "id": command.getDocId() + "/" +
command.getAttachmentId()
}); });
} else { } else {
that.success({ that.success({
...@@ -493,26 +512,22 @@ ...@@ -493,26 +512,22 @@
} }
}, 100); // 100 ms, for jiotests simple job waiting }, 100); // 100 ms, for jiotests simple job waiting
}; // end remove }; // end remove
return that; return that;
}, };
// end Dummy Storage All Not Found // end Dummy Storage All Not Found
//////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// add key to storageObjectType of global jio // add key to storageObjectType of global jio
jIO.addStorageType('dummyallok', newDummyStorageAllOk); jIO.addStorageType('dummyallok', newDummyStorageAllOk);
jIO.addStorageType('dummyallfail', newDummyStorageAllFail); jIO.addStorageType('dummyallfail', newDummyStorageAllFail);
jIO.addStorageType('dummyallnotfound', newDummyStorageAllNotFound); jIO.addStorageType('dummyallnotfound',
newDummyStorageAllNotFound);
jIO.addStorageType('dummyall3tries', newDummyStorageAll3Tries); jIO.addStorageType('dummyall3tries', newDummyStorageAll3Tries);
jIO.addStorageType('dummyalldocs', newDummyStorageAllDocs); jIO.addStorageType('dummyalldocs', newDummyStorageAllDocs);
jIO.addStorageType('dummyallfound', newDummyStorageAllFound); jIO.addStorageType('dummyallfound', newDummyStorageAllFound);
};
}; if (window.requirejs) {
define('JIODummyStorages', ['jIO'], jioDummyStorageLoader);
if (window.requirejs) { } else {
define ('JIODummyStorages',['jIO'], jioDummyStorageLoader); jioDummyStorageLoader(jIO);
} else { }
jioDummyStorageLoader ( jIO );
}
}()); }());
\ No newline at end of file
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