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
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Aurélien Vermylen
jio
Commits
aefd3402
Commit
aefd3402
authored
Sep 25, 2017
by
Aurélien Vermylen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Stash to fix mappingstorage tests.
parent
6caa5ab4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
167 additions
and
488 deletions
+167
-488
src/jio.storage/automaticapistorage.js
src/jio.storage/automaticapistorage.js
+92
-51
test/jio.storage/automaticapistorage.tests.js
test/jio.storage/automaticapistorage.tests.js
+75
-437
No files found.
src/jio.storage/automaticapistorage.js
View file @
aefd3402
...
...
@@ -21,57 +21,87 @@
'/user/{id}/', '/user/{user_id}/device/',
'/user/{user_id}/device/{device_id}/', '/vehicle/{id}/', '/vehicle/',
'/vehicle/{vehicle_id}/mil/'],*/
AUTOMATIC_VALID_ENDPOINT_REGEXES
=
[
/^
\/
trip
(\/
T_
\w
*|
)\/
$/
,
/^
\/
user
\/
me
(\/
device
(\/\w
*|
)
|
)\/
$/
,
/^
\/
vehicle
(\/
C_
\w
*
(\/
mil|
)
|
)\/
$/
],
AUTOMATIC_VALID_ENDPOINTID_REGEXES
=
[
/^
\/
trip
\/
T_
\w
*
\/
$/
,
/^
\/
user
\/
me
\/
device
\/\w
*
\/
$/
,
/^
\/
vehicle
\/
C_
\w
*
\/
$/
],
AUTOMATIC_VALID_ENDPOINT_REGEXES
=
[
/^
\/
(
U_
\w
*|all
)\/
trip
(\/
T_
\w
*|
)\/
$/
,
/^
\/
(
U_
\w
*|all
)\/
user
\/
me
(\/
device
(\/\w
*|
)
|
)\/
$/
,
/^
\/
(
U_
\w
*|all
)\/
vehicle
(\/
C_
\w
*
(\/
mil|
)
|
)\/
$/
],
AUTOMATIC_VALID_ENDPOINTID_REGEXES
=
[
/^
\/
(
U_
\w
*|all
)\/
trip
\/
T_
\w
*
\/
$/
,
/^
\/
(
U_
\w
*|all
)\/
user
\/
me
\/
device
\/\w
*
\/
$/
,
/^
\/
(
U_
\w
*|all
)\/
vehicle
\/
C_
\w
*
\/
$/
],
automatic_template
=
UriTemplate
.
parse
(
AUTOMATIC_BASE_URI
+
'
{endpoint}
'
);
// Check validity of endpoint.
function
checkEndpoint
(
endpoint
)
{
var
regex
;
for
(
regex
in
AUTOMATIC_VALID_ENDPOINT_REGEXES
)
{
if
(
AUTOMATIC_VALID_ENDPOINT_REGEXES
.
hasOwnProperty
(
regex
)
&&
regex
.
test
(
endpoint
))
{
return
true
;
}
}
return
false
;
}
// Check that ids match a valid Automatic API id
function
checkEndpointAsId
(
endpoint
)
{
var
regex
;
for
(
regex
in
AUTOMATIC_VALID_ENDPOINTID_REGEXES
)
{
if
(
AUTOMATIC_VALID_ENDPOINTID_REGEXES
.
hasOwnProperty
(
regex
)
&&
regex
.
test
(
endpoint
))
{
return
true
;
}
}
return
false
;
}
function
_queryAutomaticAPI
(
endpoint
,
filters
,
jio
)
{
var
result
=
[],
type
,
promises
,
user_dict
=
{},
temp
;
// Check validity of endpoint.
function
checkEndpoint
(
endpoint
)
{
var
regex
;
for
(
regex
in
AUTOMATIC_VALID_ENDPOINT_REGEXES
)
{
if
(
AUTOMATIC_VALID_ENDPOINT_REGEXES
.
hasOwnProperty
(
regex
)
&&
regex
.
test
(
endpoint
))
{
return
true
;
}
}
return
false
;
}
temp
,
i
;
if
(
!
checkEndpoint
(
endpoint
))
{
throw
new
jIO
.
util
.
jIOError
(
'
Wrong Automatic API query. (usually
'
+
'
caused by wrong "id" or "type")
'
,
400
);
}
type
=
endpoint
.
split
(
'
/
'
)[
1
];
type
=
endpoint
.
split
(
'
/
'
)[
2
];
// Promise chain to handle multi-part response ("_metadata"->"next" parts).
function
treatNext
(
returned
)
{
var
path
,
data
,
user_id
;
user_id
,
next
;
data
=
returned
[
0
];
user_id
=
user_dict
[
returned
[
1
]];
if
(
data
.
_metadata
===
undefined
)
{
throw
new
jIO
.
util
.
jIOError
(
'
Malformed Automatic API result.
'
,
500
);
if
(
data
.
error
===
'
err_unauthorized
'
)
{
throw
new
jIO
.
util
.
jIOError
(
'
Invalid token provided, Unauthorized.
'
,
401
);
}
path
=
URI
(
data
.
results
.
url
).
path
();
temp
=
{
'
path
'
:
path
,
'
type
'
:
type
,
'
started_at
'
:
data
.
results
.
started_at
||
null
,
'
ended_at
'
:
data
.
results
.
ended_at
||
null
,
'
user
'
:
user_id
};
result
.
push
(
temp
);
jio
.
_cache
.
put
(
'
/
'
+
user_id
+
path
,
temp
);
jio
.
_cache
.
putAttachment
(
'
/
'
,
''
,
JSON
.
stringify
(
data
.
results
));
if
(
data
.
_metadata
.
next
===
undefined
)
{
return
result
;
if
(
!
checkEndpointAsId
(
endpoint
))
{
if
(
data
.
_metadata
===
undefined
)
{
throw
new
jIO
.
util
.
jIOError
(
'
Malformed Automatic API result.
'
,
500
);
}
next
=
data
.
_metadata
.
next
;
data
=
data
.
results
;
}
for
(
i
=
0
;
i
<
data
.
length
;
i
+=
1
)
{
path
=
URI
(
data
[
i
].
url
).
path
();
temp
=
{
'
path
'
:
path
,
'
reference
'
:
user_id
+
path
,
'
type
'
:
type
,
'
started_at
'
:
data
[
i
].
started_at
||
null
,
'
ended_at
'
:
data
[
i
].
ended_at
||
null
,
'
user
'
:
user_id
};
result
.
push
(
temp
);
jio
.
_cache
.
put
(
'
/
'
+
user_id
+
path
,
temp
);
jio
.
_cache
.
putAttachment
(
'
/
'
+
user_id
+
path
,
'
data
'
,
new
Blob
([
JSON
.
stringify
(
data
[
i
].
results
)],
{
type
:
'
application/text
'
}));
}
if
(
next
===
undefined
)
{
return
true
;
}
return
jIO
.
util
.
ajax
({
'
type
'
:
'
GET
'
,
...
...
@@ -99,18 +129,24 @@
'
xhrFields
'
:
{
withCredentials
:
true
}
}).
push
(
function
(
usr
)
{
user_dict
[
token
]
=
JSON
.
parse
(
usr
).
id
;
return
jIO
.
util
.
ajax
({
'
type
'
:
'
GET
'
,
'
url
'
:
automatic_template
.
search
(
filters
).
expand
(
endpoint
),
'
headers
'
:
{
'
Authorization
'
:
'
Bearer
'
+
token
},
'
xhrFields
'
:
{
withCredentials
:
true
}
});
temp
=
endpoint
.
split
(
'
/
'
)[
1
];
if
(
temp
===
'
all
'
||
temp
===
user_dict
[
token
])
{
return
jIO
.
util
.
ajax
({
'
type
'
:
'
GET
'
,
'
url
'
:
automatic_template
.
search
(
filters
).
expand
(
endpoint
),
'
headers
'
:
{
'
Authorization
'
:
'
Bearer
'
+
token
},
'
xhrFields
'
:
{
withCredentials
:
true
}
});
}
throw
new
jIO
.
util
.
jIOError
(
'
Ignored.
'
,
200
);
}).
push
(
function
(
response
)
{
return
[
JSON
.
parse
(
response
.
target
.
responseText
),
token
];
}).
push
(
treatNext
);
});
});
return
RSVP
.
all
(
promises
);
return
RSVP
.
all
(
promises
).
push
(
function
()
{
return
result
;
});
}
/**
* The Automatic API Storage extension
...
...
@@ -126,7 +162,7 @@
for
(
i
=
0
;
i
<
spec
.
access_tokens
.
length
;
i
+=
1
)
{
if
(
typeof
spec
.
access_tokens
[
i
]
!==
'
string
'
||
!
spec
.
access_tokens
[
i
])
{
throw
new
jIO
.
util
.
jIOError
(
'
Access Tokens must be
'
+
'
an array of non-empty strings.
'
,
400
);
'
an array of non-empty strings.
'
,
400
);
}
}
...
...
@@ -135,15 +171,13 @@
}
AutomaticAPIStorage
.
prototype
.
get
=
function
(
id
)
{
function
checkEndpointAsId
(
endpoint
)
{
var
regex
;
for
(
regex
in
AUTOMATIC_VALID_ENDPOINTID_REGEXES
)
{
if
(
AUTOMATIC_VALID_ENDPOINTID_REGEXES
.
hasOwnProperty
(
regex
)
&&
regex
.
test
(
endpoint
))
{
return
true
;
}
}
return
false
;
if
(
id
.
indexOf
(
'
/
'
)
!==
0
)
{
throw
new
jIO
.
util
.
jIOError
(
'
id
'
+
id
+
'
is forbidden (not starting with /)
'
,
400
);
}
if
(
id
.
lastIndexOf
(
"
/
"
)
!==
(
id
.
length
-
1
))
{
throw
new
jIO
.
util
.
jIOError
(
'
id
'
+
id
+
'
is forbidden (not ending with /)
'
,
400
);
}
if
(
!
checkEndpointAsId
(
id
))
{
throw
new
jIO
.
util
.
jIOError
(
'
Invalid id.
'
,
400
);
...
...
@@ -151,7 +185,14 @@
return
this
.
_cache
.
get
(
id
).
push
(
function
(
res
)
{
return
res
;
},
function
()
{
_queryAutomaticAPI
(
id
,
{},
this
);
return
_queryAutomaticAPI
(
id
,
{},
this
).
push
(
function
(
res
)
{
if
(
typeof
res
===
'
object
'
&&
res
.
length
>
0
)
{
return
res
[
0
];
}
throw
new
jIO
.
util
.
jIOError
(
'
Cannot find document:
'
+
id
,
404
);
},
function
()
{
throw
new
jIO
.
util
.
jIOError
(
'
Cannot find document:
'
+
id
,
404
);
});
});
};
...
...
test/jio.storage/automaticapistorage.tests.js
View file @
aefd3402
...
...
@@ -13,14 +13,6 @@
//throws = QUnit.throws,
tokens
=
[
"
sample_token1
"
,
"
sample_token2
"
];
/////////////////////////////////////////////////////////////////
// Custom test substorage definition
/////////////////////////////////////////////////////////////////
function
Storage200
()
{
return
this
;
}
jIO
.
addStorage
(
'
querystorage200
'
,
Storage200
);
/////////////////////////////////////////////////////////////////
// AutomaticAPIStorage constructor
/////////////////////////////////////////////////////////////////
...
...
@@ -138,13 +130,25 @@
"
Content-Encoding
"
:
"
gzip
"
,
"
Content-Type
"
:
"
application/json
"
},
'
{"_metadata":{"count":1,"next":null,"previous":null},
'
+
'
"results":[{}]}
'
]);
'
"results":[{"id": "V_example"}]}
'
]);
url
=
"
https://api.automatic.com/users/me/
"
;
this
.
server
.
respondWith
(
"
GET
"
,
url
,
[
200
,
{
"
Content-Encoding
"
:
"
gzip
"
,
"
Content-Type
"
:
"
application/json
"
},
'
{"id": "0"}
'
]);
stop
();
expect
(
1
);
this
.
jio
.
get
(
"
/
0
/vehicle/
"
)
this
.
jio
.
get
(
"
/
all
/vehicle/
"
)
.
then
(
function
(
result
)
{
deepEqual
(
result
,
[{}],
"
Check list type
"
);
deepEqual
(
result
,
[{
'
path
'
:
'
/vehicle/V_example/
'
,
'
reference
'
:
'
/0/vehicle/V_example/
'
,
'
type
'
:
'
vehicle
'
,
'
started_at
'
:
null
,
'
ended_at
'
:
null
,
'
user
'
:
'
0
'
}],
"
Check list type
"
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
...
...
@@ -162,12 +166,24 @@
'
Content-Type
'
:
'
application/json
'
},
'
{"id":"T_randomtrip",
'
+
'
"url":"https://api.automatic.com/trip/T_randomtrip/"}
'
]);
url
=
"
https://api.automatic.com/users/me/
"
;
this
.
server
.
respondWith
(
"
GET
"
,
url
,
[
200
,
{
"
Content-Encoding
"
:
"
gzip
"
,
"
Content-Type
"
:
"
application/json
"
},
'
{"id": "0"}
'
]);
stop
();
expect
(
1
);
this
.
jio
.
get
(
"
/0/trip/T_randomtrip
"
)
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{},
"
Check single element type
"
);
deepEqual
(
result
,
{
'
path
'
:
'
/trip/T_randomtrip/
'
,
'
reference
'
:
'
/0/trip/T_randomtrip/
'
,
'
type
'
:
'
trip
'
,
'
started_at
'
:
null
,
'
ended_at
'
:
null
,
'
user
'
:
'
0
'
},
"
Check single element type
"
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
...
...
@@ -180,165 +196,43 @@
/////////////////////////////////////////////////////////////////
// AutomaticAPIStorage.buildQuery
/////////////////////////////////////////////////////////////////
module
(
"
queryStorage.buildQuery
"
);
test
(
"
substorage should have 'list' capacity
"
,
function
()
{
stop
();
expect
(
3
);
module
(
"
queryStorage.buildQuery
"
,
{
setup
:
function
()
{
var
jio
=
jIO
.
createJIO
({
type
:
"
query
"
,
sub_storage
:
{
type
:
"
querystorage200
"
}
});
this
.
server
=
sinon
.
fakeServer
.
create
();
this
.
server
.
autoRespond
=
true
;
this
.
server
.
autoRespondAfter
=
5
;
jio
.
allDocs
({
include_docs
:
true
,
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
();
this
.
jio
=
jIO
.
createJIO
({
type
:
"
automaticapi
"
,
access_token
:
tokens
});
});
test
(
"
no manual query if substorage handle everything
"
,
function
()
{
stop
();
expect
(
2
);
function
StorageAllDocsNoGet
()
{
return
this
;
},
teardown
:
function
()
{
this
.
server
.
restore
();
delete
this
.
server
;
}
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
({
sort_on
:
[[
"
title
"
,
"
ascending
"
]],
limit
:
[
5
],
select_list
:
[
"
title
"
,
"
id
"
],
query
:
'
title: "two"
'
})
.
then
(
function
(
result
)
{
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
()
{
test
(
"
query started_at, ended_at taken into account
"
,
function
()
{
var
url
=
"
https://api.automatic.com/trip/
"
;
this
.
server
.
respondWith
(
"
GET
"
,
url
,
[
200
,
{
'
Content-Encoding
'
:
'
gzip
'
,
'
Content-Type
'
:
'
application/json
'
},
'
{"_metadata":{"count":1,"next":null,"previous":null},
'
+
'
"results":[{"id": "T_example", "started_at": "2017-06-17T16:45:41Z"
'
+
'
, "ended_at": "2017-06-17T16:46:38Z"}]}
'
]);
url
=
"
https://api.automatic.com/users/me/
"
;
this
.
server
.
respondWith
(
"
GET
"
,
url
,
[
200
,
{
"
Content-Encoding
"
:
"
gzip
"
,
"
Content-Type
"
:
"
application/json
"
},
'
{"id": "0"}
'
]);
stop
();
expect
(
4
);
function
StorageNoSortCapacity
()
{
return
this
;
}
StorageNoSortCapacity
.
prototype
.
get
=
function
(
id
)
{
if
(
id
===
"
foo
"
)
{
equal
(
id
,
"
foo
"
,
"
Get foo
"
);
}
else
{
equal
(
id
,
"
bar
"
,
"
Get bar
"
);
}
return
{
title
:
id
,
id
:
"
ID
"
+
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
({
sort_on
:
[[
"
title
"
,
"
ascending
"
]],
limit
:
[
0
,
5
],
select_list
:
[
"
title
"
,
"
id
"
],
query
:
'
title: "foo"
'
})
this
.
jio
.
buildQuery
(
'
started_at > "2017-06-17T18:45:41Z"
'
)
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{
data
:
{
rows
:
[{
id
:
"
foo
"
,
doc
:
{},
value
:
{
title
:
"
foo
"
,
id
:
"
ID foo
"
}
}],
total_rows
:
1
}
});
deepEqual
(
result
,
[],
"
Check no result
"
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
...
...
@@ -346,74 +240,16 @@
.
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
(
id
)
{
if
(
id
===
"
foo
"
)
{
equal
(
id
,
"
foo
"
,
"
Get foo
"
);
}
else
{
equal
(
id
,
"
bar
"
,
"
Get bar
"
);
}
return
{
title
:
id
,
id
:
"
ID
"
+
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
({
sort_on
:
[[
"
title
"
,
"
ascending
"
]],
limit
:
[
0
,
5
],
select_list
:
[
"
title
"
,
"
id
"
],
query
:
'
title: "foo"
'
})
this
.
jio
.
buildQuery
(
'
started_at > "2017-06-17T14:45:41Z"
'
)
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{
data
:
{
rows
:
[{
id
:
"
foo
"
,
doc
:
{},
value
:
{
title
:
"
foo
"
,
id
:
"
ID foo
"
}
}],
total_rows
:
1
}
});
deepEqual
(
result
,
[{
'
path
'
:
'
/trip/T_example/
'
,
'
reference
'
:
'
/0/trip/T_example/
'
,
'
type
'
:
'
trip
'
,
'
started_at
'
:
"
2017-06-17T16:45:41Z
"
,
'
ended_at
'
:
"
2017-06-17T16:46:38Z
"
,
'
user
'
:
'
0
'
}],
"
Check trip is returned in result
"
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
...
...
@@ -421,74 +257,9 @@
.
always
(
function
()
{
start
();
});
});
test
(
"
manual query used if substorage does not handle limit
"
,
function
()
{
stop
();
expect
(
4
);
function
StorageNoLimitCapacity
()
{
return
this
;
}
StorageNoLimitCapacity
.
prototype
.
get
=
function
(
id
)
{
if
(
id
===
"
foo
"
)
{
equal
(
id
,
"
foo
"
,
"
Get foo
"
);
}
else
{
equal
(
id
,
"
bar
"
,
"
Get bar
"
);
}
return
{
title
:
id
,
id
:
"
ID
"
+
id
,
"
another
"
:
"
property
"
};
};
StorageNoLimitCapacity
.
prototype
.
hasCapacity
=
function
(
capacity
)
{
if
((
capacity
===
"
list
"
)
||
(
capacity
===
"
select
"
)
||
(
capacity
===
"
sort
"
)
||
(
capacity
===
"
query
"
))
{
return
true
;
}
return
false
;
};
StorageNoLimitCapacity
.
prototype
.
buildQuery
=
function
(
options
)
{
deepEqual
(
options
,
{},
"
No query parameter
"
);
var
result2
=
[{
id
:
"
foo
"
,
value
:
{}
},
{
id
:
"
bar
"
,
value
:
{}
}];
return
result2
;
};
jIO
.
addStorage
(
'
querystoragenolimitcapacity
'
,
StorageNoLimitCapacity
);
var
jio
=
jIO
.
createJIO
({
type
:
"
query
"
,
sub_storage
:
{
type
:
"
querystoragenolimitcapacity
"
}
});
jio
.
allDocs
({
sort_on
:
[[
"
title
"
,
"
ascending
"
]],
limit
:
[
0
,
5
],
select_list
:
[
"
title
"
,
"
id
"
],
query
:
'
title: "foo"
'
})
this
.
jio
.
buildQuery
(
'
ended_at > "2017-06-17T18:45:41Z"
'
)
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{
data
:
{
rows
:
[{
id
:
"
foo
"
,
doc
:
{},
value
:
{
title
:
"
foo
"
,
id
:
"
ID foo
"
}
}],
total_rows
:
1
}
});
deepEqual
(
result
,
[],
"
Check no result
"
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
...
...
@@ -496,74 +267,16 @@
.
always
(
function
()
{
start
();
});
});
test
(
"
manual query used if substorage does not handle query
"
,
function
()
{
stop
();
expect
(
4
);
function
StorageNoQueryCapacity
()
{
return
this
;
}
StorageNoQueryCapacity
.
prototype
.
get
=
function
(
id
)
{
if
(
id
===
"
foo
"
)
{
equal
(
id
,
"
foo
"
,
"
Get foo
"
);
}
else
{
equal
(
id
,
"
bar
"
,
"
Get bar
"
);
}
return
{
title
:
id
,
id
:
"
ID
"
+
id
,
"
another
"
:
"
property
"
};
};
StorageNoQueryCapacity
.
prototype
.
hasCapacity
=
function
(
capacity
)
{
if
((
capacity
===
"
list
"
)
||
(
capacity
===
"
select
"
)
||
(
capacity
===
"
limit
"
)
||
(
capacity
===
"
sort
"
))
{
return
true
;
}
return
false
;
};
StorageNoQueryCapacity
.
prototype
.
buildQuery
=
function
(
options
)
{
deepEqual
(
options
,
{},
"
No query parameter
"
);
var
result2
=
[{
id
:
"
foo
"
,
value
:
{}
},
{
id
:
"
bar
"
,
value
:
{}
}];
return
result2
;
};
jIO
.
addStorage
(
'
querystoragenoquerycapacity
'
,
StorageNoQueryCapacity
);
var
jio
=
jIO
.
createJIO
({
type
:
"
query
"
,
sub_storage
:
{
type
:
"
querystoragenoquerycapacity
"
}
});
jio
.
allDocs
({
sort_on
:
[[
"
title
"
,
"
ascending
"
]],
limit
:
[
0
,
5
],
select_list
:
[
"
title
"
,
"
id
"
],
query
:
'
title: "foo"
'
})
this
.
jio
.
buildQuery
(
'
ended_at < "2017-06-17T18:45:41Z"
'
)
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{
data
:
{
rows
:
[{
id
:
"
foo
"
,
doc
:
{},
value
:
{
title
:
"
foo
"
,
id
:
"
ID foo
"
}
}],
total_rows
:
1
}
});
deepEqual
(
result
,
[{
'
path
'
:
'
/trip/T_example/
'
,
'
reference
'
:
'
/0/trip/T_example/
'
,
'
type
'
:
'
trip
'
,
'
started_at
'
:
"
2017-06-17T16:45:41Z
"
,
'
ended_at
'
:
"
2017-06-17T16:46:38Z
"
,
'
user
'
:
'
0
'
}],
"
Check trip is returned in result
"
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
...
...
@@ -573,80 +286,5 @@
});
});
test
(
"
does not fetch doc one by one if substorage handle include_docs
"
,
function
()
{
stop
();
expect
(
2
);
function
StorageIncludeDocsCapacity
()
{
return
this
;
}
StorageIncludeDocsCapacity
.
prototype
.
hasCapacity
=
function
(
capacity
)
{
if
((
capacity
===
"
list
"
)
||
(
capacity
===
"
include
"
))
{
return
true
;
}
return
false
;
};
StorageIncludeDocsCapacity
.
prototype
.
buildQuery
=
function
(
options
)
{
deepEqual
(
options
,
{
include_docs
:
true
},
"
Include docs parameter
"
);
var
result2
=
[{
id
:
"
foo
"
,
value
:
{},
doc
:
{
title
:
"
foo
"
,
id
:
"
ID foo
"
,
another
:
"
property
"
}
},
{
id
:
"
bar
"
,
value
:
{},
doc
:
{
title
:
"
bar
"
,
id
:
"
ID bar
"
,
another
:
"
property
"
}
}];
return
result2
;
};
jIO
.
addStorage
(
'
querystorageincludedocscapacity
'
,
StorageIncludeDocsCapacity
);
var
jio
=
jIO
.
createJIO
({
type
:
"
query
"
,
sub_storage
:
{
type
:
"
querystorageincludedocscapacity
"
}
});
jio
.
allDocs
({
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
();
});
});
}(
jIO
,
QUnit
,
Blob
,
sinon
));
\ No newline at end of file
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