Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
jio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
18
Merge Requests
18
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
jio
Commits
1e991dc6
Commit
1e991dc6
authored
Feb 16, 2015
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add QueryStorage tests.
parent
41b69b80
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
677 additions
and
934 deletions
+677
-934
src/jio.storage/querystorage.js
src/jio.storage/querystorage.js
+26
-154
test/jio.storage/querystorage.tests.js
test/jio.storage/querystorage.tests.js
+636
-769
test/tests.html
test/tests.html
+15
-11
No files found.
src/jio.storage/querystorage.js
View file @
1e991dc6
/*jslint nomen: true
, maxlen: 200
*/
/*jslint nomen: true*/
/*global RSVP*/
/*global RSVP*/
(
function
(
jIO
)
{
(
function
(
jIO
,
RSVP
)
{
"
use strict
"
;
"
use strict
"
;
/**
/**
...
@@ -33,18 +33,10 @@
...
@@ -33,18 +33,10 @@
return
this
.
_sub_storage
.
putAttachment
.
apply
(
this
.
_sub_storage
,
arguments
);
return
this
.
_sub_storage
.
putAttachment
.
apply
(
this
.
_sub_storage
,
arguments
);
};
};
QueryStorage
.
prototype
.
removeAttachment
=
function
()
{
QueryStorage
.
prototype
.
removeAttachment
=
function
()
{
return
this
.
_sub_storage
.
removeAttachment
.
apply
(
this
.
_sub_storage
,
arguments
);
return
this
.
_sub_storage
.
removeAttachment
.
apply
(
this
.
_sub_storage
,
arguments
);
};
};
/**
* Retrieve documents.
* This method performs an .allDocs() call on the substorage,
* retrieving everything, then runs a query on the result.
*
* @method allDocs
* @param {Object} command The given parameters
* @param {Object} options The command options
*/
QueryStorage
.
prototype
.
hasCapacity
=
function
(
name
)
{
QueryStorage
.
prototype
.
hasCapacity
=
function
(
name
)
{
if
(
name
===
"
list
"
)
{
if
(
name
===
"
list
"
)
{
return
this
.
_sub_storage
.
hasCapacity
(
name
);
return
this
.
_sub_storage
.
hasCapacity
(
name
);
...
@@ -54,7 +46,6 @@
...
@@ -54,7 +46,6 @@
QueryStorage
.
prototype
.
buildQuery
=
function
(
options
)
{
QueryStorage
.
prototype
.
buildQuery
=
function
(
options
)
{
var
substorage
=
this
.
_sub_storage
,
var
substorage
=
this
.
_sub_storage
,
context
=
this
,
context
=
this
,
// sub_query_result,
sub_options
=
{},
sub_options
=
{},
is_manual_query_needed
=
false
,
is_manual_query_needed
=
false
,
is_manual_include_needed
=
false
;
is_manual_include_needed
=
false
;
...
@@ -63,17 +54,22 @@
...
@@ -63,17 +54,22 @@
// Can substorage handle the queries if needed?
// Can substorage handle the queries if needed?
try
{
try
{
if
(((
options
.
query
===
undefined
)
||
(
substorage
.
hasCapacity
(
"
query
"
)))
&&
if
(((
options
.
query
===
undefined
)
||
((
options
.
sort_on
===
undefined
)
||
(
substorage
.
hasCapacity
(
"
sort
"
)))
&&
(
substorage
.
hasCapacity
(
"
query
"
)))
&&
((
options
.
select_list
===
undefined
)
||
(
substorage
.
hasCapacity
(
"
select
"
)))
&&
((
options
.
sort_on
===
undefined
)
||
((
options
.
limit
===
undefined
)
||
(
substorage
.
hasCapacity
(
"
limit
"
))))
{
(
substorage
.
hasCapacity
(
"
sort
"
)))
&&
((
options
.
select_list
===
undefined
)
||
(
substorage
.
hasCapacity
(
"
select
"
)))
&&
((
options
.
limit
===
undefined
)
||
(
substorage
.
hasCapacity
(
"
limit
"
))))
{
sub_options
.
query
=
options
.
query
;
sub_options
.
query
=
options
.
query
;
sub_options
.
sort_on
=
options
.
sort_on
;
sub_options
.
sort_on
=
options
.
sort_on
;
sub_options
.
select_list
=
options
.
select_list
;
sub_options
.
select_list
=
options
.
select_list
;
sub_options
.
limit
=
options
.
limit
;
sub_options
.
limit
=
options
.
limit
;
}
}
}
catch
(
error
)
{
}
catch
(
error
)
{
if
((
error
instanceof
jIO
.
util
.
jIOError
)
&&
(
error
.
status_code
===
501
))
{
if
((
error
instanceof
jIO
.
util
.
jIOError
)
&&
(
error
.
status_code
===
501
))
{
is_manual_query_needed
=
true
;
is_manual_query_needed
=
true
;
}
else
{
}
else
{
throw
error
;
throw
error
;
...
@@ -82,18 +78,20 @@
...
@@ -82,18 +78,20 @@
// Can substorage include the docs if needed?
// Can substorage include the docs if needed?
try
{
try
{
if
((
is_manual_query_needed
||
(
options
.
include_docs
===
true
))
&&
(
!
substorage
.
hasCapacity
(
"
include
"
)))
{
if
((
is_manual_query_needed
||
sub_options
.
include_docs
=
options
.
include_docs
;
(
options
.
include_docs
===
true
))
&&
(
substorage
.
hasCapacity
(
"
include
"
)))
{
sub_options
.
include_docs
=
true
;
}
}
}
catch
(
error
)
{
}
catch
(
error
)
{
if
((
error
instanceof
jIO
.
util
.
jIOError
)
&&
(
error
.
status_code
===
501
))
{
if
((
error
instanceof
jIO
.
util
.
jIOError
)
&&
(
error
.
status_code
===
501
))
{
is_manual_include_needed
=
true
;
is_manual_include_needed
=
true
;
}
else
{
}
else
{
throw
error
;
throw
error
;
}
}
}
}
return
substorage
.
buildQuery
(
sub_options
)
return
substorage
.
buildQuery
(
sub_options
)
// Include docs if needed
// Include docs if needed
...
@@ -106,7 +104,8 @@
...
@@ -106,7 +104,8 @@
return
substorage
.
get
({
"
_id
"
:
result
[
j
].
id
})
return
substorage
.
get
({
"
_id
"
:
result
[
j
].
id
})
.
push
(
undefined
,
function
(
error
)
{
.
push
(
undefined
,
function
(
error
)
{
// Document may have been dropped after listing
// Document may have been dropped after listing
if
((
error
instanceof
jIO
.
util
.
jIOError
)
&&
(
error
.
status_code
===
404
))
{
if
((
error
instanceof
jIO
.
util
.
jIOError
)
&&
(
error
.
status_code
===
404
))
{
return
;
return
;
}
}
throw
error
;
throw
error
;
...
@@ -135,6 +134,7 @@
...
@@ -135,6 +134,7 @@
result
=
original_result
;
result
=
original_result
;
}
}
return
result
;
return
result
;
})
})
// Manual query if needed
// Manual query if needed
...
@@ -143,7 +143,6 @@
...
@@ -143,7 +143,6 @@
len
,
len
,
i
;
i
;
if
(
is_manual_query_needed
)
{
if
(
is_manual_query_needed
)
{
// sub_query_result = result;
len
=
result
.
length
;
len
=
result
.
length
;
for
(
i
=
0
;
i
<
len
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
len
;
i
+=
1
)
{
data_rows
.
push
(
result
[
i
].
doc
);
data_rows
.
push
(
result
[
i
].
doc
);
...
@@ -151,7 +150,8 @@
...
@@ -151,7 +150,8 @@
if
(
options
.
select_list
)
{
if
(
options
.
select_list
)
{
options
.
select_list
.
push
(
"
_id
"
);
options
.
select_list
.
push
(
"
_id
"
);
}
}
result
=
jIO
.
QueryFactory
.
create
(
options
.
query
||
""
,
context
.
_key_schema
).
result
=
jIO
.
QueryFactory
.
create
(
options
.
query
||
""
,
context
.
_key_schema
).
exec
(
data_rows
,
options
);
exec
(
data_rows
,
options
);
}
}
return
result
;
return
result
;
...
@@ -186,137 +186,9 @@
...
@@ -186,137 +186,9 @@
return
result
;
return
result
;
});
});
// if (options.include_docs) {
// for (i = 0, l = filtered_docs.length; i < l; i += 1) {
// filtered_docs[i] = {
// "id": filtered_docs[i]._id,
// "doc": docs[filtered_docs[i]._id],
// "value": options.select_list ? filtered_docs[i] : {}
// };
// delete filtered_docs[i].value._id;
// }
// } else {
// for (i = 0, l = filtered_docs.length; i < l; i += 1) {
// filtered_docs[i] = {
// "id": filtered_docs[i]._id,
// "value": options.select_list ? filtered_docs[i] : {}
// };
// delete filtered_docs[i].value._id;
// }
// }
// response.data.rows = filtered_docs;
// response.data.total_rows = filtered_docs.length;
// return response;
// });
// return jIO.QueryFactory.create(options.query || "", that._key_schema).
// exec(data_rows, options).
// then(function (filtered_docs) {
// // reconstruct filtered rows, preserving the order from docs
// if (options.include_docs) {
// for (i = 0, l = filtered_docs.length; i < l; i += 1) {
// filtered_docs[i] = {
// "id": filtered_docs[i]._id,
// "doc": docs[filtered_docs[i]._id],
// "value": options.select_list ? filtered_docs[i] : {}
// };
// delete filtered_docs[i].value._id;
// }
// } else {
// for (i = 0, l = filtered_docs.length; i < l; i += 1) {
// filtered_docs[i] = {
// "id": filtered_docs[i]._id,
// "value": options.select_list ? filtered_docs[i] : {}
// };
// delete filtered_docs[i].value._id;
// }
// }
// response.data.rows = filtered_docs;
// response.data.total_rows = filtered_docs.length;
// return response;
// });
}
}
// }).then(function (response) {
//
// ((options.include_docs === undefined) || context.hasCapacity("include")) &&
// }
//
// return context.buildQuery.apply(context, arguments);
// }
//
// // // we need the full documents in order to perform the query, will
// // // remove them later if they were not required.
// // include_docs = (options.include_docs || options.query) ? true : false;
//
// console.log("QueryStorage: calling substorage buildQuery");
// return substorage.buildQuery.apply(substorage, arguments);
// return substorage.buildQuery.apply(substorage, arguments)
// .push(function (result) {
// });
// substorage.allDocs({
// "include_docs": include_docs
// }).then(function (response) {
//
// var data_rows = response.data.rows, docs = {}, row, i, l;
//
// if (!include_docs) {
// return response;
// }
//
// if (options.include_docs) {
// for (i = 0, l = data_rows.length; i < l; i += 1) {
// row = data_rows[i];
// docs[row.id] = JSON.parse(JSON.stringify(row.doc));
// row.doc._id = row.id;
// data_rows[i] = row.doc;
// }
// } else {
// for (i = 0, l = data_rows.length; i < l; i += 1) {
// row = data_rows[i];
// row.doc._id = row.id;
// data_rows[i] = row.doc;
// }
// }
//
// if (options.select_list) {
// options.select_list.push("_id");
// }
//
// return jIO.QueryFactory.create(options.query || "", that._key_schema).
// exec(data_rows, options).
// then(function (filtered_docs) {
// // reconstruct filtered rows, preserving the order from docs
// if (options.include_docs) {
// for (i = 0, l = filtered_docs.length; i < l; i += 1) {
// filtered_docs[i] = {
// "id": filtered_docs[i]._id,
// "doc": docs[filtered_docs[i]._id],
// "value": options.select_list ? filtered_docs[i] : {}
// };
// delete filtered_docs[i].value._id;
// }
// } else {
// for (i = 0, l = filtered_docs.length; i < l; i += 1) {
// filtered_docs[i] = {
// "id": filtered_docs[i]._id,
// "value": options.select_list ? filtered_docs[i] : {}
// };
// delete filtered_docs[i].value._id;
// }
// }
// response.data.rows = filtered_docs;
// response.data.total_rows = filtered_docs.length;
// return response;
// });
//
// }).then(command.success, command.error, command.notify);
};
};
jIO
.
addStorage
(
'
query
'
,
QueryStorage
);
jIO
.
addStorage
(
'
query
'
,
QueryStorage
);
}(
jIO
));
}(
jIO
,
RSVP
));
test/jio.storage/querystorage.tests.js
View file @
1e991dc6
/*jslint nomen: true
, maxlen: 200
*/
/*jslint nomen: true*/
/*global Blob
, test_util, console
*/
/*global Blob*/
(
function
(
jIO
,
QUnit
)
{
(
function
(
jIO
,
QUnit
,
Blob
)
{
"
use strict
"
;
"
use strict
"
;
var
test
=
QUnit
.
test
,
var
test
=
QUnit
.
test
,
stop
=
QUnit
.
stop
,
stop
=
QUnit
.
stop
,
...
@@ -9,7 +9,8 @@
...
@@ -9,7 +9,8 @@
expect
=
QUnit
.
expect
,
expect
=
QUnit
.
expect
,
deepEqual
=
QUnit
.
deepEqual
,
deepEqual
=
QUnit
.
deepEqual
,
equal
=
QUnit
.
equal
,
equal
=
QUnit
.
equal
,
module
=
QUnit
.
module
;
module
=
QUnit
.
module
,
throws
=
QUnit
.
throws
;
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
// Custom test substorage definition
// Custom test substorage definition
...
@@ -17,31 +18,25 @@
...
@@ -17,31 +18,25 @@
function
Storage200
()
{
function
Storage200
()
{
return
this
;
return
this
;
}
}
Storage200
.
prototype
.
get
=
function
(
param
)
{
equal
(
param
.
_id
,
"
bar
"
,
"
get 200 called
"
);
return
{
title
:
"
foo
"
};
};
Storage200
.
prototype
.
put
=
function
(
param
)
{
deepEqual
(
param
,
{
"
_id
"
:
"
bar
"
,
"
title
"
:
"
foo
"
},
"
put 200 called
"
);
return
param
.
_id
;
};
Storage200
.
prototype
.
remove
=
function
(
param
)
{
deepEqual
(
param
,
{
"
_id
"
:
"
bar
"
},
"
remove 200 called
"
);
return
param
.
_id
;
};
Storage200
.
prototype
.
post
=
function
(
param
)
{
deepEqual
(
param
,
{
"
_id
"
:
"
bar
"
,
"
title
"
:
"
foo
"
},
"
post 200 called
"
);
return
param
.
_id
;
};
Storage200
.
prototype
.
buildQuery
=
function
(
options
)
{
console
.
log
(
"
Storage200: buildQuery
"
);
deepEqual
(
options
,
{
include_docs
:
true
,
query
:
'
title: "two"
'
},
"
buildQuery 200 called
"
);
console
.
log
(
"
Storage200: return
"
);
return
"
taboulet
"
;
};
jIO
.
addStorage
(
'
querystorage200
'
,
Storage200
);
jIO
.
addStorage
(
'
querystorage200
'
,
Storage200
);
/////////////////////////////////////////////////////////////////
// queryStorage.constructor
/////////////////////////////////////////////////////////////////
module
(
"
queryStorage.constructor
"
);
test
(
"
create substorage
"
,
function
()
{
var
jio
=
jIO
.
createJIO
({
type
:
"
query
"
,
sub_storage
:
{
type
:
"
querystorage200
"
}
});
ok
(
jio
.
__storage
.
_sub_storage
instanceof
jio
.
constructor
);
equal
(
jio
.
__storage
.
_sub_storage
.
__type
,
"
querystorage200
"
);
});
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
// queryStorage.get
// queryStorage.get
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
...
@@ -57,9 +52,15 @@
...
@@ -57,9 +52,15 @@
}
}
});
});
Storage200
.
prototype
.
get
=
function
(
param
)
{
equal
(
param
.
_id
,
"
bar
"
,
"
get 200 called
"
);
return
{
title
:
"
foo
"
};
};
jio
.
get
({
"
_id
"
:
"
bar
"
})
jio
.
get
({
"
_id
"
:
"
bar
"
})
.
then
(
function
(
result
)
{
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{
deepEqual
(
result
,
{
"
_id
"
:
"
bar
"
,
"
title
"
:
"
foo
"
"
title
"
:
"
foo
"
},
"
Check document
"
);
},
"
Check document
"
);
})
})
...
@@ -86,9 +87,14 @@
...
@@ -86,9 +87,14 @@
}
}
});
});
jio
.
post
({
"
_id
"
:
"
bar
"
,
"
title
"
:
"
foo
"
})
Storage200
.
prototype
.
post
=
function
(
param
)
{
deepEqual
(
param
,
{
"
title
"
:
"
foo
"
},
"
post 200 called
"
);
return
"
youhou
"
;
};
jio
.
post
({
"
title
"
:
"
foo
"
})
.
then
(
function
(
result
)
{
.
then
(
function
(
result
)
{
equal
(
result
,
"
bar
"
);
equal
(
result
,
"
youhou
"
);
})
})
.
fail
(
function
(
error
)
{
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
ok
(
false
,
error
);
...
@@ -112,6 +118,10 @@
...
@@ -112,6 +118,10 @@
type
:
"
querystorage200
"
type
:
"
querystorage200
"
}
}
});
});
Storage200
.
prototype
.
put
=
function
(
param
)
{
deepEqual
(
param
,
{
"
_id
"
:
"
bar
"
,
"
title
"
:
"
foo
"
},
"
put 200 called
"
);
return
param
.
_id
;
};
jio
.
put
({
"
_id
"
:
"
bar
"
,
"
title
"
:
"
foo
"
})
jio
.
put
({
"
_id
"
:
"
bar
"
,
"
title
"
:
"
foo
"
})
.
then
(
function
(
result
)
{
.
then
(
function
(
result
)
{
...
@@ -139,6 +149,10 @@
...
@@ -139,6 +149,10 @@
type
:
"
querystorage200
"
type
:
"
querystorage200
"
}
}
});
});
Storage200
.
prototype
.
remove
=
function
(
param
)
{
deepEqual
(
param
,
{
"
_id
"
:
"
bar
"
},
"
remove 200 called
"
);
return
param
.
_id
;
};
jio
.
remove
({
"
_id
"
:
"
bar
"
})
jio
.
remove
({
"
_id
"
:
"
bar
"
})
.
then
(
function
(
result
)
{
.
then
(
function
(
result
)
{
...
@@ -153,10 +167,78 @@
...
@@ -153,10 +167,78 @@
});
});
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
// queryStorage.allDocs
// queryStorage.getAttachment
/////////////////////////////////////////////////////////////////
module
(
"
queryStorage.getAttachment
"
);
test
(
"
getAttachment called substorage getAttachment
"
,
function
()
{
stop
();
expect
(
2
);
var
jio
=
jIO
.
createJIO
({
type
:
"
query
"
,
sub_storage
:
{
type
:
"
querystorage200
"
}
}),
blob
=
new
Blob
([
""
]);
Storage200
.
prototype
.
getAttachment
=
function
(
param
)
{
deepEqual
(
param
,
{
"
_id
"
:
"
bar
"
,
"
_attachment
"
:
"
foo
"
},
"
getAttachment 200 called
"
);
return
{
data
:
blob
};
};
jio
.
getAttachment
({
"
_id
"
:
"
bar
"
,
"
_attachment
"
:
"
foo
"
})
.
then
(
function
(
result
)
{
equal
(
result
.
data
,
blob
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
/////////////////////////////////////////////////////////////////
// queryStorage.putAttachment
/////////////////////////////////////////////////////////////////
module
(
"
queryStorage.putAttachment
"
);
test
(
"
putAttachment called substorage putAttachment
"
,
function
()
{
stop
();
expect
(
2
);
var
jio
=
jIO
.
createJIO
({
type
:
"
query
"
,
sub_storage
:
{
type
:
"
querystorage200
"
}
}),
blob
=
new
Blob
([
""
]);
Storage200
.
prototype
.
putAttachment
=
function
(
param
)
{
deepEqual
(
param
,
{
"
_id
"
:
"
bar
"
,
"
_attachment
"
:
"
foo
"
,
"
_blob
"
:
blob
},
"
putAttachment 200 called
"
);
return
"
OK
"
;
};
jio
.
putAttachment
({
"
_id
"
:
"
bar
"
,
"
_attachment
"
:
"
foo
"
,
"
_blob
"
:
blob
})
.
then
(
function
(
result
)
{
equal
(
result
,
"
OK
"
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
/////////////////////////////////////////////////////////////////
// queryStorage.removeAttachment
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
module
(
"
queryStorage.
allDocs
"
);
module
(
"
queryStorage.
removeAttachment
"
);
test
(
"
allDocs called substorage allDocs
"
,
function
()
{
test
(
"
removeAttachment called substorage removeAttachment
"
,
function
()
{
stop
();
stop
();
expect
(
2
);
expect
(
2
);
...
@@ -167,16 +249,303 @@
...
@@ -167,16 +249,303 @@
}
}
});
});
Storage200
.
prototype
.
removeAttachment
=
function
(
param
)
{
deepEqual
(
param
,
{
"
_id
"
:
"
bar
"
,
"
_attachment
"
:
"
foo
"
},
"
removeAttachment 200 called
"
);
return
"
Removed
"
;
};
jio
.
removeAttachment
({
"
_id
"
:
"
bar
"
,
"
_attachment
"
:
"
foo
"
})
.
then
(
function
(
result
)
{
equal
(
result
,
"
Removed
"
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
/////////////////////////////////////////////////////////////////
// queryStorage.hasCapacity
/////////////////////////////////////////////////////////////////
module
(
"
queryStorage.hasCapacity
"
);
test
(
"
hasCapacity is true by default
"
,
function
()
{
var
jio
=
jIO
.
createJIO
({
type
:
"
query
"
,
sub_storage
:
{
type
:
"
querystorage200
"
}
});
equal
(
jio
.
hasCapacity
(
"
foo
"
),
true
);
});
test
(
"
hasCapacity list return substorage value
"
,
function
()
{
var
jio
=
jIO
.
createJIO
({
type
:
"
query
"
,
sub_storage
:
{
type
:
"
querystorage200
"
}
});
throws
(
function
()
{
jio
.
hasCapacity
(
"
list
"
);
},
function
(
error
)
{
ok
(
error
instanceof
jIO
.
util
.
jIOError
);
equal
(
error
.
status_code
,
501
);
equal
(
error
.
message
,
"
Capacity 'list' is not implemented on 'querystorage200'
"
);
return
true
;
}
);
});
/////////////////////////////////////////////////////////////////
// queryStorage.buildQuery
/////////////////////////////////////////////////////////////////
module
(
"
queryStorage.buildQuery
"
);
test
(
"
substorage should have 'list' capacity
"
,
function
()
{
stop
();
expect
(
3
);
var
jio
=
jIO
.
createJIO
({
type
:
"
query
"
,
sub_storage
:
{
type
:
"
querystorage200
"
}
});
jio
.
allDocs
({
jio
.
allDocs
({
include_docs
:
true
,
include_docs
:
true
,
query
:
'
title: "two"
'
query
:
'
title: "two"
'
})
.
then
(
function
()
{
ok
(
false
);
})
.
fail
(
function
(
error
)
{
ok
(
error
instanceof
jIO
.
util
.
jIOError
);
equal
(
error
.
status_code
,
501
);
equal
(
error
.
message
,
"
Capacity 'list' is not implemented on 'querystorage200'
"
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
no manual query if substorage handle everything
"
,
function
()
{
stop
();
expect
(
2
);
function
StorageAllDocsNoGet
()
{
return
this
;
}
StorageAllDocsNoGet
.
prototype
.
get
=
function
()
{
throw
new
Error
(
"
Unexpected get call
"
);
};
StorageAllDocsNoGet
.
prototype
.
hasCapacity
=
function
(
capacity
)
{
if
((
capacity
===
"
list
"
)
||
(
capacity
===
"
sort
"
)
||
(
capacity
===
"
select
"
)
||
(
capacity
===
"
limit
"
)
||
(
capacity
===
"
query
"
))
{
return
true
;
}
throw
new
Error
(
"
Unexpected
"
+
capacity
+
"
capacity check
"
);
};
StorageAllDocsNoGet
.
prototype
.
buildQuery
=
function
(
options
)
{
deepEqual
(
options
,
{
sort_on
:
[[
"
title
"
,
"
ascending
"
]],
limit
:
[
5
],
select_list
:
[
"
title
"
,
"
id
"
],
query
:
'
title: "two"
'
},
"
buildQuery called
"
);
return
"
taboulet
"
;
};
jIO
.
addStorage
(
'
querystoragealldocsnoget
'
,
StorageAllDocsNoGet
);
var
jio
=
jIO
.
createJIO
({
type
:
"
query
"
,
sub_storage
:
{
type
:
"
querystoragealldocsnoget
"
}
});
jio
.
allDocs
({
include_docs
:
false
,
sort_on
:
[[
"
title
"
,
"
ascending
"
]],
limit
:
[
5
],
select_list
:
[
"
title
"
,
"
id
"
],
query
:
'
title: "two"
'
})
})
.
then
(
function
(
result
)
{
.
then
(
function
(
result
)
{
equal
(
result
,
"
bar
"
);
deepEqual
(
result
,
{
data
:
{
rows
:
"
taboulet
"
,
total_rows
:
8
}
});
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
manual query used if substorage does not handle sort
"
,
function
()
{
stop
();
expect
(
4
);
function
StorageNoSortCapacity
()
{
return
this
;
}
StorageNoSortCapacity
.
prototype
.
get
=
function
(
options
)
{
if
(
options
.
_id
===
"
foo
"
)
{
equal
(
options
.
_id
,
"
foo
"
,
"
Get foo
"
);
}
else
{
equal
(
options
.
_id
,
"
bar
"
,
"
Get bar
"
);
}
return
{
title
:
options
.
_id
,
id
:
"
ID
"
+
options
.
_id
,
"
another
"
:
"
property
"
};
};
StorageNoSortCapacity
.
prototype
.
hasCapacity
=
function
(
capacity
)
{
if
((
capacity
===
"
list
"
)
||
(
capacity
===
"
select
"
)
||
(
capacity
===
"
limit
"
)
||
(
capacity
===
"
query
"
))
{
return
true
;
}
return
false
;
};
StorageNoSortCapacity
.
prototype
.
buildQuery
=
function
(
options
)
{
deepEqual
(
options
,
{},
"
No query parameter
"
);
var
result2
=
[{
id
:
"
foo
"
,
value
:
{}
},
{
id
:
"
bar
"
,
value
:
{}
}];
return
result2
;
};
jIO
.
addStorage
(
'
querystoragenosortcapacity
'
,
StorageNoSortCapacity
);
var
jio
=
jIO
.
createJIO
({
type
:
"
query
"
,
sub_storage
:
{
type
:
"
querystoragenosortcapacity
"
}
});
jio
.
allDocs
({
include_docs
:
false
,
sort_on
:
[[
"
title
"
,
"
ascending
"
]],
limit
:
[
0
,
5
],
select_list
:
[
"
title
"
,
"
id
"
],
query
:
'
title: "foo"
'
})
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{
data
:
{
rows
:
[{
id
:
"
foo
"
,
doc
:
{},
value
:
{
title
:
"
foo
"
,
id
:
"
ID foo
"
}
}],
total_rows
:
1
}
});
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
manual query used if substorage does not handle select
"
,
function
()
{
stop
();
expect
(
4
);
function
StorageNoSelectCapacity
()
{
return
this
;
}
StorageNoSelectCapacity
.
prototype
.
get
=
function
(
options
)
{
if
(
options
.
_id
===
"
foo
"
)
{
equal
(
options
.
_id
,
"
foo
"
,
"
Get foo
"
);
}
else
{
equal
(
options
.
_id
,
"
bar
"
,
"
Get bar
"
);
}
return
{
title
:
options
.
_id
,
id
:
"
ID
"
+
options
.
_id
,
"
another
"
:
"
property
"
};
};
StorageNoSelectCapacity
.
prototype
.
hasCapacity
=
function
(
capacity
)
{
if
((
capacity
===
"
list
"
)
||
(
capacity
===
"
sort
"
)
||
(
capacity
===
"
limit
"
)
||
(
capacity
===
"
query
"
))
{
return
true
;
}
return
false
;
};
StorageNoSelectCapacity
.
prototype
.
buildQuery
=
function
(
options
)
{
deepEqual
(
options
,
{},
"
No query parameter
"
);
var
result2
=
[{
id
:
"
foo
"
,
value
:
{}
},
{
id
:
"
bar
"
,
value
:
{}
}];
return
result2
;
};
jIO
.
addStorage
(
'
querystoragenoselectcapacity
'
,
StorageNoSelectCapacity
);
var
jio
=
jIO
.
createJIO
({
type
:
"
query
"
,
sub_storage
:
{
type
:
"
querystoragenoselectcapacity
"
}
});
jio
.
allDocs
({
include_docs
:
false
,
sort_on
:
[[
"
title
"
,
"
ascending
"
]],
limit
:
[
0
,
5
],
select_list
:
[
"
title
"
,
"
id
"
],
query
:
'
title: "foo"
'
})
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{
data
:
{
rows
:
[{
id
:
"
foo
"
,
doc
:
{},
value
:
{
title
:
"
foo
"
,
id
:
"
ID foo
"
}
}],
total_rows
:
1
}
});
})
})
.
fail
(
function
(
error
)
{
.
fail
(
function
(
error
)
{
console
.
error
(
error
);
console
.
error
(
error
.
stack
);
ok
(
false
,
error
);
ok
(
false
,
error
);
})
})
.
always
(
function
()
{
.
always
(
function
()
{
...
@@ -184,737 +553,235 @@
...
@@ -184,737 +553,235 @@
});
});
});
});
// function createQueryStorage(name, key_schema) {
test
(
"
manual query used if substorage does not handle limit
"
,
function
()
{
// // var local_description = local_storage.createDescription(name,
stop
();
// // name,
expect
(
4
);
// // 'memory');
// return jIO.createJIO({
function
StorageNoLimitCapacity
()
{
// type: 'query',
return
this
;
// sub_storage: {
}
// type: name
StorageNoLimitCapacity
.
prototype
.
get
=
function
(
options
)
{
// },
if
(
options
.
_id
===
"
foo
"
)
{
// key_schema: key_schema
equal
(
options
.
_id
,
"
foo
"
,
"
Get foo
"
);
// }, {
}
else
{
// workspace: {}
equal
(
options
.
_id
,
"
bar
"
,
"
Get bar
"
);
// });
}
// }
return
{
title
:
options
.
_id
,
id
:
"
ID
"
+
options
.
_id
,
//
"
another
"
:
"
property
"
};
//
};
//
StorageNoLimitCapacity
.
prototype
.
hasCapacity
=
function
(
capacity
)
{
// /*
if
((
capacity
===
"
list
"
)
||
// * What follows is almost a replica of the local storage tests,
(
capacity
===
"
select
"
)
||
// * plus a couple of schema queries.
(
capacity
===
"
sort
"
)
||
// * This is redundant, but guarantees that the storage is working
(
capacity
===
"
query
"
))
{
// * under all circumstances.
return
true
;
// */
}
//
return
false
;
//
};
// function success(promise) {
StorageNoLimitCapacity
.
prototype
.
buildQuery
=
function
(
options
)
{
// return new RSVP.Promise(function (resolve, reject, notify) {
deepEqual
(
options
,
{},
"
No query parameter
"
);
// /*jslint unparam: true*/
var
result2
=
[{
// promise.then(resolve, resolve, notify);
id
:
"
foo
"
,
// }, function () {
value
:
{}
// promise.cancel();
},
{
// });
id
:
"
bar
"
,
// }
value
:
{}
//
}];
//
return
result2
;
// function unexpectedError(error) {
};
// if (error instanceof Error) {
// deepEqual([
jIO
.
addStorage
(
'
querystoragenolimitcapacity
'
,
StorageNoLimitCapacity
);
// error.name + ": " + error.message,
// error
var
jio
=
jIO
.
createJIO
({
// ], "UNEXPECTED ERROR", "Unexpected error");
type
:
"
query
"
,
// } else {
sub_storage
:
{
// deepEqual(error, "UNEXPECTED ERROR", "Unexpected error");
type
:
"
querystoragenolimitcapacity
"
// }
}
// }
});
//
//
jio
.
allDocs
({
// test("post & get", 6, function () {
include_docs
:
false
,
// var jio = createQueryStorage('post-get');
sort_on
:
[[
"
title
"
,
"
ascending
"
]],
//
limit
:
[
0
,
5
],
// stop();
select_list
:
[
"
title
"
,
"
id
"
],
//
query
:
'
title: "foo"
'
// function getMissingDocument() {
})
// return success(jio.get({_id: 'inexistent'}));
.
then
(
function
(
result
)
{
// }
deepEqual
(
result
,
{
//
data
:
{
// function getMissingDocumentTest(answer) {
rows
:
[{
// deepEqual(answer, {
id
:
"
foo
"
,
// "error": "not_found",
doc
:
{},
// "id": "inexistent",
value
:
{
// "message": "Cannot find document",
title
:
"
foo
"
,
// "method": "get",
id
:
"
ID foo
"
// "reason": "missing",
}
// "result": "error",
}],
// "status": 404,
total_rows
:
1
// "statusText": "Not Found"
}
// }, "Get inexistent document");
});
// }
})
//
.
fail
(
function
(
error
)
{
// function postWithoutID() {
ok
(
false
,
error
);
// return jio.post({});
})
// }
.
always
(
function
()
{
//
start
();
// function postWithoutIDTest(answer) {
});
// var uuid = answer.id;
});
//
// delete answer.id;
test
(
"
manual query used if substorage does not handle query
"
,
function
()
{
// deepEqual(answer, {
stop
();
// "method": "post",
expect
(
4
);
// "result": "success",
// "status": 201,
function
StorageNoQueryCapacity
()
{
// "statusText": "Created"
return
this
;
// });
}
// ok(test_util.isUuid(uuid), "Uuid should look like " +
StorageNoQueryCapacity
.
prototype
.
get
=
function
(
options
)
{
// "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx : " + uuid);
if
(
options
.
_id
===
"
foo
"
)
{
// }
equal
(
options
.
_id
,
"
foo
"
,
"
Get foo
"
);
//
}
else
{
// function postNonEmptyDocument() {
equal
(
options
.
_id
,
"
bar
"
,
"
Get bar
"
);
// return jio.post({"_id": "post1", "title": "myPost1"});
}
// }
return
{
title
:
options
.
_id
,
id
:
"
ID
"
+
options
.
_id
,
//
"
another
"
:
"
property
"
};
// function postNonEmptyDocumentTest(answer) {
};
// deepEqual(answer, {
StorageNoQueryCapacity
.
prototype
.
hasCapacity
=
function
(
capacity
)
{
// "id": "post1",
if
((
capacity
===
"
list
"
)
||
// "method": "post",
(
capacity
===
"
select
"
)
||
// "result": "success",
(
capacity
===
"
limit
"
)
||
// "status": 201,
(
capacity
===
"
sort
"
))
{
// "statusText": "Created"
return
true
;
// });
}
// }
return
false
;
//
};
// function getNonEmptyDocument() {
StorageNoQueryCapacity
.
prototype
.
buildQuery
=
function
(
options
)
{
// return jio.get({"_id": "post1"});
deepEqual
(
options
,
{},
"
No query parameter
"
);
// }
var
result2
=
[{
//
id
:
"
foo
"
,
// function getNonEmptyDocumentTest(answer) {
value
:
{}
// deepEqual(answer, {
},
{
// "data": {
id
:
"
bar
"
,
// "_id": "post1",
value
:
{}
// "title": "myPost1"
}];
// },
return
result2
;
// "id": "post1",
};
// "method": "get",
// "result": "success",
jIO
.
addStorage
(
'
querystoragenoquerycapacity
'
,
StorageNoQueryCapacity
);
// "status": 200,
// "statusText": "Ok"
var
jio
=
jIO
.
createJIO
({
// });
type
:
"
query
"
,
// }
sub_storage
:
{
//
type
:
"
querystoragenoquerycapacity
"
// function postExistingDocument() {
}
// return success(jio.post({"_id": "post1", "title": "myPost2"}));
});
// }
//
jio
.
allDocs
({
// function postExistingDocumentTest(answer) {
include_docs
:
false
,
// deepEqual(answer, {
sort_on
:
[[
"
title
"
,
"
ascending
"
]],
// "error": "conflict",
limit
:
[
0
,
5
],
// "id": "post1",
select_list
:
[
"
title
"
,
"
id
"
],
// "message": "Cannot create a new document",
query
:
'
title: "foo"
'
// "method": "post",
})
// "reason": "document exists",
.
then
(
function
(
result
)
{
// "result": "error",
deepEqual
(
result
,
{
// "status": 409,
data
:
{
// "statusText": "Conflict"
rows
:
[{
// });
id
:
"
foo
"
,
// }
doc
:
{},
//
value
:
{
// getMissingDocument().then(getMissingDocumentTest).
title
:
"
foo
"
,
// then(postWithoutID).then(postWithoutIDTest).
id
:
"
ID foo
"
// then(postNonEmptyDocument).then(postNonEmptyDocumentTest).
}
// then(getNonEmptyDocument).then(getNonEmptyDocumentTest).
}],
// then(postExistingDocument).then(postExistingDocumentTest).
total_rows
:
1
// fail(unexpectedError).
}
// always(start);
});
// });
})
//
.
fail
(
function
(
error
)
{
//
ok
(
false
,
error
);
//
})
// test("put & get", 4, function () {
.
always
(
function
()
{
// var jio = createQueryStorage('put-get');
start
();
//
});
// stop();
});
//
// function putNonEmptyDocument() {
test
(
"
does not fetch doc one by one if substorage handle include_docs
"
,
// return jio.put({"_id": "put1", "title": "myPut1"});
function
()
{
// }
stop
();
//
expect
(
2
);
// function putNonEmptyDocumentTest(answer) {
// deepEqual(answer, {
function
StorageIncludeDocsCapacity
()
{
// "id": "put1",
return
this
;
// "method": "put",
}
// "result": "success",
StorageIncludeDocsCapacity
.
prototype
.
hasCapacity
=
function
(
capacity
)
{
// "status": 201,
if
((
capacity
===
"
list
"
)
||
// "statusText": "Created"
(
capacity
===
"
include
"
))
{
// });
return
true
;
// }
}
//
return
false
;
// function getNonEmptyDocument() {
};
// return jio.get({"_id": "put1"});
StorageIncludeDocsCapacity
.
prototype
.
buildQuery
=
function
(
options
)
{
// }
deepEqual
(
options
,
{
include_docs
:
true
},
"
Include docs parameter
"
);
//
var
result2
=
[{
// function getNonEmptyDocumentTest(answer) {
id
:
"
foo
"
,
// deepEqual(answer, {
value
:
{},
// "data": {
doc
:
{
// "_id": "put1",
title
:
"
foo
"
,
// "title": "myPut1"
id
:
"
ID foo
"
,
// },
_id
:
"
foo
"
,
// "id": "put1",
another
:
"
property
"
// "method": "get",
}
// "result": "success",
},
{
// "status": 200,
id
:
"
bar
"
,
// "statusText": "Ok"
value
:
{},
// });
doc
:
{
// }
title
:
"
bar
"
,
//
id
:
"
ID bar
"
,
// function putExistingDocument() {
_id
:
"
bar
"
,
// return success(jio.put({"_id": "put1", "title": "myPut2"}));
another
:
"
property
"
// }
}
//
}];
// function putExistingDocumentTest(answer) {
return
result2
;
// deepEqual(answer, {
};
// "id": "put1",
// "method": "put",
jIO
.
addStorage
(
'
querystorageincludedocscapacity
'
,
// "result": "success",
StorageIncludeDocsCapacity
);
// "status": 204,
// "statusText": "No Content"
var
jio
=
jIO
.
createJIO
({
// });
type
:
"
query
"
,
// }
sub_storage
:
{
//
type
:
"
querystorageincludedocscapacity
"
// function getNonEmptyDocument2() {
}
// return jio.get({"_id": "put1"});
});
// }
//
jio
.
allDocs
({
// function getNonEmptyDocument2Test(answer) {
include_docs
:
false
,
// deepEqual(answer, {
sort_on
:
[[
"
title
"
,
"
ascending
"
]],
// "data": {
limit
:
[
0
,
5
],
// "_id": "put1",
select_list
:
[
"
title
"
,
"
id
"
],
// "title": "myPut2"
query
:
'
title: "foo"
'
// },
})
// "id": "put1",
.
then
(
function
(
result
)
{
// "method": "get",
deepEqual
(
result
,
{
// "result": "success",
data
:
{
// "status": 200,
rows
:
[{
// "statusText": "Ok"
id
:
"
foo
"
,
// });
doc
:
{},
// }
value
:
{
//
title
:
"
foo
"
,
// putNonEmptyDocument().then(putNonEmptyDocumentTest).
id
:
"
ID foo
"
// then(getNonEmptyDocument).then(getNonEmptyDocumentTest).
}
// then(putExistingDocument).then(putExistingDocumentTest).
}],
// then(getNonEmptyDocument2).then(getNonEmptyDocument2Test).
total_rows
:
1
// fail(unexpectedError).
}
// always(start);
});
// });
})
//
.
fail
(
function
(
error
)
{
//
ok
(
false
,
error
);
// test("putAttachment & get & getAttachment", 9, function () {
})
// var jio = createQueryStorage('putattachment-get-getattachment');
.
always
(
function
()
{
//
start
();
// stop();
});
//
});
// function getAttachmentMissingDocument() {
// return success(jio.getAttachment({
}(
jIO
,
QUnit
,
Blob
));
// "_id": "inexistent",
// "_attachment": "a"
// }));
// }
//
// function getAttachmentMissingDocumentTest(answer) {
// deepEqual(answer, {
// "attachment": "a",
// "error": "not_found",
// "id": "inexistent",
// "message": "Cannot find document",
// "method": "getAttachment",
// "reason": "missing document",
// "result": "error",
// "status": 404,
// "statusText": "Not Found"
// });
// }
//
// function getAttachmentFromEmptyDocument() {
// var promise = jio.put({"_id": "b"}).
// then(function () {
// return jio.getAttachment({"_id": "b", "_attachment": "inexistent"});
// });
// return success(promise);
// }
//
// function getAttachmentFromEmptyDocumentTest(answer) {
// deepEqual(answer, {
// "attachment": "inexistent",
// "error": "not_found",
// "id": "b",
// "message": "Cannot find attachment",
// "method": "getAttachment",
// "reason": "missing attachment",
// "result": "error",
// "status": 404,
// "statusText": "Not Found"
// });
// }
//
// function putAttachmentMissingDocument() {
// return success(jio.putAttachment({
// "_id": "inexistent",
// "_attachment": "putattmt2",
// "_data": ""
// }));
// }
//
// function putAttachmentMissingDocumentTest(answer) {
// deepEqual(answer, {
// "attachment": "putattmt2",
// "error": "not_found",
// "id": "inexistent",
// "message": "Impossible to add attachment",
// "method": "putAttachment",
// "reason": "missing",
// "result": "error",
// "status": 404,
// "statusText": "Not Found"
// });
// }
//
// function addAttachment() {
// var promise = jio.put({"_id": "putattmt1", "title": "myPutAttmt1"}).
// then(function () {
// return jio.putAttachment({
// "_id": "putattmt1",
// "_attachment": "putattmt2",
// "_data": ""
// });
// });
// return success(promise);
// }
//
// function addAttachmentTest(answer) {
// deepEqual(answer, {
// "attachment": "putattmt2",
// "digest": "sha256-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b93" +
// "4ca495991b7852b855",
// "id": "putattmt1",
// "method": "putAttachment",
// "result": "success",
// "status": 201,
// "statusText": "Created"
// });
// }
//
// function checkDocumentAndAttachment() {
// return RSVP.all([
// jio.get({"_id": "putattmt1"}),
// jio.getAttachment({"_id": "putattmt1", "_attachment": "putattmt2"})
// ]);
// }
//
// function checkDocumentAndAttachmentTest(answers) {
// deepEqual(answers[0], {
// "data": {
// "_attachments": {
// "putattmt2": {
// "content_type": "",
// "digest": "sha256-e3b0c44298fc1c149afbf4c8996fb92427ae41e4" +
// "649b934ca495991b7852b855",
// "length": 0
// }
// },
// "_id": "putattmt1",
// "title": "myPutAttmt1"
// },
// "id": "putattmt1",
// "method": "get",
// "result": "success",
// "status": 200,
// "statusText": "Ok"
// });
//
// ok(answers[1].data instanceof Blob, "Data is Blob");
// deepEqual(answers[1].data.type, "", "Check mimetype");
// deepEqual(answers[1].data.size, 0, "Check size");
//
// delete answers[1].data;
// deepEqual(answers[1], {
// "attachment": "putattmt2",
// "id": "putattmt1",
// "digest": "sha256-e3b0c44298fc1c149afbf4c8996fb9242" +
// "7ae41e4649b934ca495991b7852b855",
// "method": "getAttachment",
// "result": "success",
// "status": 200,
// "statusText": "Ok"
// }, "Get Attachment, Check Response");
// }
//
// getAttachmentMissingDocument().then(getAttachmentMissingDocumentTest).
// then(getAttachmentFromEmptyDocument).
// then(getAttachmentFromEmptyDocumentTest).
// then(putAttachmentMissingDocument).
// then(putAttachmentMissingDocumentTest).
// then(addAttachment).then(addAttachmentTest).
// then(checkDocumentAndAttachment).then(checkDocumentAndAttachmentTest).
// fail(unexpectedError).
// always(start);
// });
//
//
// test("remove & removeAttachment", 5, function () {
// var jio = createQueryStorage('remove-removeattachment');
//
// stop();
//
// function putAttachment() {
// var promise = jio.put({"_id": "a"}).
// then(function () {
// return jio.putAttachment({
// "_id": "a",
// "_attachment": "b",
// "_data": "c"
// });
// });
//
// return promise;
// }
//
// function putAttachmentTest(answer) {
// deepEqual(answer, {
// "attachment": "b",
// "digest": "sha256-2e7d2c03a9507ae265ecf5b5356885a53" +
// "393a2029d241394997265a1a25aefc6",
// "id": "a",
// "method": "putAttachment",
// "result": "success",
// "status": 201,
// "statusText": "Created"
// });
// }
//
// function removeAttachment() {
// return success(jio.removeAttachment({"_id": "a", "_attachment": "b"}));
// }
//
// function removeAttachmentTest(answer) {
// deepEqual(answer, {
// "attachment": "b",
// "id": "a",
// "method": "removeAttachment",
// "result": "success",
// "status": 204,
// "statusText": "No Content"
// });
// }
//
// function removeAttachmentAgainTest(answer) {
// deepEqual(answer, {
// "attachment": "b",
// "error": "not_found",
// "id": "a",
// "message": "Attachment not found",
// "method": "removeAttachment",
// "reason": "missing attachment",
// "result": "error",
// "status": 404,
// "statusText": "Not Found"
// });
// }
//
// function removeDocument() {
// return success(jio.remove({"_id": "a"}));
// }
//
// function removeDocumentTest(answer) {
// deepEqual(answer, {
// "id": "a",
// "method": "remove",
// "result": "success",
// "status": 204,
// "statusText": "No Content"
// });
// }
//
// function removeDocumentAgainTest(answer) {
// deepEqual(answer, {
// "error": "not_found",
// "id": "a",
// "message": "Document not found",
// "method": "remove",
// "reason": "missing",
// "result": "error",
// "status": 404,
// "statusText": "Not Found"
// });
// }
//
// putAttachment().then(putAttachmentTest).
// then(removeAttachment).then(removeAttachmentTest).
// then(removeAttachment).then(removeAttachmentAgainTest).
// then(removeDocument).then(removeDocumentTest).
// then(removeDocument).then(removeDocumentAgainTest).
// fail(unexpectedError).
// always(start);
// });
//
//
// test("allDocs", 5, function () {
// var jio = createQueryStorage('alldocs'),
// key_schema = {
// key_set: {
// case_insensitive_title: {
// read_from: 'title',
// equal_match: function (object_value, value) {
// return (object_value.toLowerCase() === value.toLowerCase());
// }
// }
// }
// };
//
// stop();
//
//
// function putDocuments() {
// var date_a = new Date(0),
// date_b = new Date(1234567890000);
//
// return RSVP.all([
// jio.put({
// "_id": "a",
// "title": "one",
// "date": date_a
// }).then(function () {
// return jio.putAttachment({
// "_id": "a",
// "_attachment": "aa",
// "_data": "aaa"
// });
// }),
// jio.put({"_id": "b", "title": "two", "date": date_a}),
// jio.put({"_id": "c", "title": "one", "date": date_b}),
// jio.put({"_id": "d", "title": "two", "date": date_b})
// ]);
// }
//
// function putDocumentsTest(answer) {
// // sort answer rows for comparison
// if (answer.data && answer.data.rows) {
// answer.data.rows.sort(function (a, b) {
// return a.id < b.id ? -1 : a.id > b.id ? 1 : 0;
// });
// }
//
// deepEqual(answer, [
// {
// "attachment": "aa",
// "digest": "sha256-9834876dcfb05cb167a5c24953eba58" +
// "c4ac89b1adf57f28f2f9d09af107ee8f0",
// "id": "a",
// "method": "putAttachment",
// "result": "success",
// "status": 201,
// "statusText": "Created"
// },
// {
// "id": "b",
// "method": "put",
// "result": "success",
// "status": 201,
// "statusText": "Created"
// },
// {
// "id": "c",
// "method": "put",
// "result": "success",
// "status": 201,
// "statusText": "Created"
// },
// {
// "id": "d",
// "method": "put",
// "result": "success",
// "status": 201,
// "statusText": "Created"
// }
// ]);
//
// }
//
//
// function listDocuments() {
// return jio.allDocs();
// }
//
// function listDocumentsTest(answer) {
// deepEqual(answer, {
// "data": {
// "rows": [
// {
// "id": "a",
// "key": "a",
// "value": {}
// },
// {
// "id": "b",
// "key": "b",
// "value": {}
// },
// {
// "id": "c",
// "key": "c",
// "value": {}
// },
// {
// "id": "d",
// "key": "d",
// "value": {}
// }
// ],
// "total_rows": 4
// },
// "method": "allDocs",
// "result": "success",
// "status": 200,
// "statusText": "Ok"
// });
// }
//
// function listDocumentsQuery() {
// return jio.allDocs({
// "include_docs": true,
// "query": "title: \"two\""
// });
// }
//
//
// function listDocumentsQueryTest(answer) {
// deepEqual(answer, {
// "data": {
// "rows": [
// {
// "doc": {
// "_id": "b",
// "date": "1970-01-01T00:00:00.000Z",
// "title": "two"
// },
// "id": "b",
// "value": {}
// },
// {
// "doc": {
// "_id": "d",
// "date": "2009-02-13T23:31:30.000Z",
// "title": "two"
// },
// "id": "d",
// "value": {}
// }
// ],
// "total_rows": 2
// },
// "method": "allDocs",
// "result": "success",
// "status": 200,
// "statusText": "Ok"
// });
// }
//
// function listDocumentSchemaQueryNoDocs() {
// var jio_schema = createQueryStorage('alldocs', key_schema);
// return jio_schema.allDocs({
// "include_docs": false,
// "query": "case_insensitive_title: \"oNe\""
// });
// }
//
// function listDocumentSchemaQueryNoDocsTest(answer) {
// deepEqual(answer, {
// "data": {
// "rows": [
// {
// "id": "a",
// "value": {}
// },
// {
// "id": "c",
// "value": {}
// }
// ],
// "total_rows": 2
// },
// "method": "allDocs",
// "result": "success",
// "status": 200,
// "statusText": "Ok"
// });
// }
//
//
// function listDocumentSchemaQueryWithDocs() {
// var jio_schema = createQueryStorage('alldocs', key_schema);
// return jio_schema.allDocs({
// "include_docs": true,
// "query": "case_insensitive_title: \"oNe\""
// });
// }
//
// function listDocumentSchemaQueryWithDocsTest(answer) {
// deepEqual(answer, {
// "data": {
// "rows": [
// {
// "doc": {
// "_attachments": {
// "aa": {
// "content_type": "",
// "digest": "sha256-9834876dcfb05cb167a5c24953eba58c" +
// "4ac89b1adf57f28f2f9d09af107ee8f0",
// "length": 3
// }
// },
// "_id": "a",
// "date": "1970-01-01T00:00:00.000Z",
// "title": "one"
// },
// "id": "a",
// "value": {}
// },
// {
// "doc": {
// "_id": "c",
// "date": "2009-02-13T23:31:30.000Z",
// "title": "one"
// },
// "id": "c",
// "value": {}
// }
// ],
// "total_rows": 2
// },
// "method": "allDocs",
// "result": "success",
// "status": 200,
// "statusText": "Ok"
// });
// }
//
//
//
// putDocuments().then(putDocumentsTest).
// then(listDocuments).then(listDocumentsTest).
// then(listDocumentsQuery).then(listDocumentsQueryTest).
// then(listDocumentSchemaQueryNoDocs).
// then(listDocumentSchemaQueryNoDocsTest).
// then(listDocumentSchemaQueryWithDocs).
// then(listDocumentSchemaQueryWithDocsTest).
// fail(unexpectedError).
// always(start);
// });
//
//
//
// // XXX check/repair not tested yet, may change soon btw
// // test("check & repair", 18, function () {
// // })
}(
jIO
,
QUnit
));
test/tests.html
View file @
1e991dc6
...
@@ -3,13 +3,14 @@
...
@@ -3,13 +3,14 @@
<head>
<head>
<meta
charset=
"utf-8"
/>
<meta
charset=
"utf-8"
/>
<title>
JIO Qunit/Sinon Unit Tests
</title>
<title>
JIO Qunit/Sinon Unit Tests
</title>
<script
src=
"../node_modules/rsvp/dist/rsvp-2.0.4.js"
></script>
<script
src=
"../dist/jio-latest.js"
></script>
<link
rel=
"stylesheet"
href=
"../node_modules/grunt-contrib-qunit/test/libs/qunit.css"
type=
"text/css"
media=
"screen"
/>
<link
rel=
"stylesheet"
href=
"../node_modules/grunt-contrib-qunit/test/libs/qunit.css"
type=
"text/css"
media=
"screen"
/>
<script
src=
"../node_modules/grunt-contrib-qunit/test/libs/qunit.js"
type=
"text/javascript"
></script>
<script
src=
"../node_modules/grunt-contrib-qunit/test/libs/qunit.js"
type=
"text/javascript"
></script>
<script
src=
"../node_modules/rsvp/dist/rsvp-2.0.4.js"
></script>
<script
src=
"../node_modules/sinon/pkg/sinon.js"
type=
"text/javascript"
></script>
<script
src=
"../node_modules/sinon/pkg/sinon.js"
type=
"text/javascript"
></script>
<script
src=
"../dist/jio-latest.js"
></script>
<
script
src=
"html5.js"
></script
>
<
!--script src="html5.js"></script--
>
<!--script src="jio/util.js"></script-->
<!--script src="jio/util.js"></script-->
<!--script src="jio/fakestorage.js"></script>
<!--script src="jio/fakestorage.js"></script>
<script src="jio/tests.js"></script-->
<script src="jio/tests.js"></script-->
...
@@ -22,24 +23,27 @@
...
@@ -22,24 +23,27 @@
<script
src=
"queries/jiodate.tests.js"
></script>
<script
src=
"queries/jiodate.tests.js"
></script>
<script
src=
"queries/key-jiodate.tests.js"
></script>
<script
src=
"queries/key-jiodate.tests.js"
></script>
<
script
src=
"queries/key-localstorage.tests.js"
></script
>
<
!--script src="queries/key-localstorage.tests.js"></script--
>
<script
src=
"jio.storage/localstorage.tests.js"
></script>
<script
src=
"jio.storage/memorystorage.tests.js"
></script>
<script
src=
"jio.storage/querystorage.tests.js"
></script>
<!--script src="jio.storage/localstorage.tests.js"></script>
<script src="jio.storage/davstorage.tests.js"></script>
<script src="jio.storage/davstorage.tests.js"></script>
<script
src=
"jio.storage/indexeddbstorage.tests.js"
></script>
<script src="jio.storage/unionstorage.tests.js"></script>
<script src="jio.storage/unionstorage.tests.js"></script>
<script
src=
"jio.storage/querystorage.tests.js"
></script>
<script src="jio.storage/querystorage.tests.js"></script-->
<script
src=
"jio.storage/dropboxstorage.tests.js"
></script>
<!--script src="jio.storage/indexeddbstorage.tests.js"></script-->
<!--script src="jio.storage/indexstorage.tests.js"></script-->
<!--script src="jio.storage/dropboxstorage.tests.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-->
<!--script src="../src/jio.storage/indexstorage.js"></script>
<script src="jio.storage/indexstorage.tests.js"></script>
<script src="../src/jio.storage/gidstorage.js"></script>
<
!--
script src="../src/jio.storage/gidstorage.js"></script>
<script src="../test/jio.storage/gidstorage.tests.js"></script>
<script src="../test/jio.storage/gidstorage.tests.js"></script>
<script src="../src/jio.storage/revisionstorage.js"></script>
<script src="../src/jio.storage/revisionstorage.js"></script>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment