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