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
46b74188
Commit
46b74188
authored
Oct 11, 2017
by
Aurélien Vermylen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Major rehaul of automaticapi storage: list by device and not user.
parent
b7a612ea
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
137 additions
and
104 deletions
+137
-104
dist/jio-v3.23.1.js
dist/jio-v3.23.1.js
+33
-31
dist/jio-v3.23.1.min.js
dist/jio-v3.23.1.min.js
+2
-2
src/jio.storage/automaticapistorage.js
src/jio.storage/automaticapistorage.js
+33
-31
test/jio.storage/automaticapistorage.tests.js
test/jio.storage/automaticapistorage.tests.js
+69
-40
No files found.
dist/jio-v3.23.1.js
View file @
46b74188
...
...
@@ -14498,12 +14498,12 @@ return new Parser;
var
result
=
[],
type
=
endpoint
.
split
(
'
/
'
)[
1
],
promises
,
usr
=
filters
.
user
||
'
all
'
,
dev
=
filters
.
device
||
'
all
'
,
isId
=
checkEndpointAsId
(
endpoint
),
user
_dict
=
{},
device
_dict
=
{},
i
;
// Remove '
user
' filter which should not be put in Automatic request.
delete
filters
.
user
;
// Remove '
device
' filter which should not be put in Automatic request.
delete
filters
.
device
;
// Check endpoint validity.
if
(
!
checkEndpoint
(
endpoint
))
{
throw
new
jIO
.
util
.
jIOError
(
'
Wrong Automatic API query. (usually
'
+
...
...
@@ -14512,7 +14512,7 @@ return new Parser;
// Promise chain to handle multi-part response ("_metadata"->"next" parts).
function
treatNext
(
returned
)
{
var
data
,
user
_id
,
device
_id
,
next
;
// If the returned value was an error, return it (-> quite nasty design
// to have to return errors, but this is in order for all RSVP.all() to
...
...
@@ -14521,7 +14521,7 @@ return new Parser;
return
returned
;
}
data
=
returned
[
0
];
user_id
=
user
_dict
[
returned
[
1
]];
device_id
=
device
_dict
[
returned
[
1
]];
data
=
[
data
];
if
(
!
isId
)
{
if
(
data
[
0
].
_metadata
===
undefined
)
{
...
...
@@ -14536,16 +14536,16 @@ return new Parser;
path
=
URI
(
dat
.
url
).
path
();
temp
=
{
'
automatic_path
'
:
path
,
'
reference
'
:
'
/
'
+
user
_id
+
path
,
'
id
'
:
'
/
'
+
user
_id
+
path
,
'
reference
'
:
'
/
'
+
device
_id
+
path
,
'
id
'
:
'
/
'
+
device
_id
+
path
,
'
type
'
:
type
,
'
start_date
'
:
dat
.
started_at
||
null
,
'
stop_date
'
:
dat
.
ended_at
||
null
,
'
automatic_
user
'
:
user
_id
'
automatic_
device
'
:
device
_id
};
result
.
push
(
temp
);
return
jio
.
_cache
.
put
(
'
/
'
+
user
_id
+
path
,
temp
).
push
(
function
()
{
return
jio
.
_cache
.
putAttachment
(
'
/
'
+
user
_id
+
path
,
'
data
'
,
return
jio
.
_cache
.
put
(
'
/
'
+
device
_id
+
path
,
temp
).
push
(
function
()
{
return
jio
.
_cache
.
putAttachment
(
'
/
'
+
device
_id
+
path
,
'
data
'
,
new
Blob
([
JSON
.
stringify
(
dat
)],
{
type
:
'
text/plain
'
}));
});
...
...
@@ -14578,13 +14578,15 @@ return new Parser;
return
new
RSVP
.
Queue
().
push
(
function
()
{
return
jIO
.
util
.
ajax
({
'
type
'
:
'
GET
'
,
'
url
'
:
automatic_template
.
expand
({
endpoint
:
[
'
user
'
,
'
me
'
,
''
]}),
'
url
'
:
automatic_template
.
expand
({
endpoint
:
[
'
user
'
,
'
me
'
,
'
device
'
,
''
]}),
'
headers
'
:
{
'
Authorization
'
:
'
Bearer
'
+
token
}
//'xhrFields': {withCredentials: true}
});
}).
push
(
function
(
respusr
)
{
user_dict
[
token
]
=
JSON
.
parse
(
respusr
.
target
.
responseText
).
id
;
if
(
usr
===
'
all
'
||
usr
===
user_dict
[
token
])
{
}).
push
(
function
(
respdev
)
{
device_dict
[
token
]
=
JSON
.
parse
(
respdev
.
target
.
responseText
).
results
[
0
].
id
;
if
(
dev
===
'
all
'
||
dev
===
device_dict
[
token
])
{
return
jIO
.
util
.
ajax
({
'
type
'
:
'
GET
'
,
'
url
'
:
URI
(
automatic_template
.
expand
({
endpoint
:
...
...
@@ -14610,7 +14612,7 @@ return new Parser;
return
RSVP
.
all
(
promises
);
}).
push
(
function
(
trueOrErrorArray
)
{
// If we queried an id, return results should be length 1
if
(
isId
&&
(
usr
!==
'
all
'
))
{
if
(
isId
&&
(
dev
!==
'
all
'
))
{
if
(
result
.
length
===
1
)
{
return
result
[
0
];
}
...
...
@@ -14620,7 +14622,7 @@ return new Parser;
}
// Result is empty, so we throw the correct token error.
i
=
jio
.
_access_tokens
.
map
(
function
(
token
)
{
if
(
user_dict
[
token
]
===
usr
)
{
if
(
device_dict
[
token
]
===
dev
)
{
return
true
;
}
return
false
;
...
...
@@ -14630,8 +14632,8 @@ return new Parser;
throw
trueOrErrorArray
[
i
];
}
// If we didn't find the error in the promise returns, we don't have
// a token for
user usr
.
throw
new
jIO
.
util
.
jIOError
(
'
No valid token for
user:
'
+
usr
,
400
);
// a token for
device dev
.
throw
new
jIO
.
util
.
jIOError
(
'
No valid token for
device:
'
+
dev
,
400
);
}
// Otherwise return results and errors and let caller handle.
return
result
;
...
...
@@ -14662,8 +14664,8 @@ return new Parser;
AutomaticAPIStorage
.
prototype
.
get
=
function
(
id
)
{
var
self
=
this
,
endpoint
=
id
.
split
(
'
/
'
),
usr
;
usr
=
endpoint
.
splice
(
1
,
1
)[
0
];
dev
;
dev
=
endpoint
.
splice
(
1
,
1
)[
0
];
endpoint
=
endpoint
.
join
(
'
/
'
);
if
(
id
.
indexOf
(
'
/
'
)
!==
0
)
{
throw
new
jIO
.
util
.
jIOError
(
'
id
'
+
id
+
...
...
@@ -14676,13 +14678,13 @@ return new Parser;
if
(
!
checkEndpointAsId
(
endpoint
))
{
throw
new
jIO
.
util
.
jIOError
(
'
Invalid id.
'
,
400
);
}
if
(
usr
===
'
all
'
)
{
if
(
dev
===
'
all
'
)
{
throw
new
jIO
.
util
.
jIOError
(
'
Invalid id.
'
,
400
);
}
return
this
.
_cache
.
get
(
id
).
push
(
function
(
res
)
{
return
res
;
},
function
()
{
return
_queryAutomaticAPI
(
endpoint
,
{
'
user
'
:
usr
},
self
)
return
_queryAutomaticAPI
(
endpoint
,
{
'
device
'
:
dev
},
self
)
.
push
(
function
(
res
)
{
return
res
;
},
function
(
err
)
{
...
...
@@ -14715,8 +14717,8 @@ return new Parser;
AutomaticAPIStorage
.
prototype
.
getAttachment
=
function
(
id
,
name
,
options
)
{
var
self
=
this
,
endpoint
=
id
.
split
(
'
/
'
),
usr
;
usr
=
endpoint
.
splice
(
1
,
1
)[
0
];
dev
;
dev
=
endpoint
.
splice
(
1
,
1
)[
0
];
endpoint
=
endpoint
.
join
(
'
/
'
);
if
(
id
.
indexOf
(
'
/
'
)
!==
0
)
{
throw
new
jIO
.
util
.
jIOError
(
'
id
'
+
id
+
...
...
@@ -14729,7 +14731,7 @@ return new Parser;
if
(
!
checkEndpointAsId
(
endpoint
))
{
throw
new
jIO
.
util
.
jIOError
(
'
Invalid id.
'
,
400
);
}
if
(
usr
===
'
all
'
)
{
if
(
dev
===
'
all
'
)
{
throw
new
jIO
.
util
.
jIOError
(
'
Invalid id.
'
,
400
);
}
return
this
.
_cache
.
get
(
id
).
push
(
function
()
{
...
...
@@ -14759,8 +14761,8 @@ return new Parser;
AutomaticAPIStorage
.
prototype
.
allAttachments
=
function
(
id
)
{
var
endpoint
=
id
.
split
(
'
/
'
),
usr
;
usr
=
endpoint
.
splice
(
1
,
1
)[
0
];
dev
;
dev
=
endpoint
.
splice
(
1
,
1
)[
0
];
endpoint
=
endpoint
.
join
(
'
/
'
);
if
(
id
.
indexOf
(
'
/
'
)
!==
0
)
{
throw
new
jIO
.
util
.
jIOError
(
'
id
'
+
id
+
...
...
@@ -14773,7 +14775,7 @@ return new Parser;
if
(
!
checkEndpointAsId
(
endpoint
))
{
throw
new
jIO
.
util
.
jIOError
(
'
Invalid id.
'
,
400
);
}
if
(
usr
===
'
all
'
)
{
if
(
dev
===
'
all
'
)
{
throw
new
jIO
.
util
.
jIOError
(
'
Invalid id.
'
,
400
);
}
return
{
data
:
null
};
...
...
@@ -14793,9 +14795,9 @@ return new Parser;
key_list
,
automatic_filters
=
{},
simplequery_type_value
,
intercept_keys
=
[
'
start_date
'
,
'
stop_date
'
,
'
automatic_
user
'
,
intercept_keys
=
[
'
start_date
'
,
'
stop_date
'
,
'
automatic_
device
'
,
'
vehicle
'
],
intercept_keys_automatic_name
=
[
'
started_at
'
,
'
ended_at
'
,
'
user
'
,
intercept_keys_automatic_name
=
[
'
started_at
'
,
'
ended_at
'
,
'
device
'
,
'
vehicle
'
],
intercept_accepted_operators
=
[[
'
>
'
,
'
>=
'
,
'
<
'
,
'
<=
'
],
[
'
>
'
,
'
>=
'
,
'
<
'
,
'
<=
'
],
[
'
=
'
],
[
'
=
'
]],
...
...
dist/jio-v3.23.1.min.js
View file @
46b74188
This source diff could not be displayed because it is too large. You can
view the blob
instead.
src/jio.storage/automaticapistorage.js
View file @
46b74188
...
...
@@ -56,12 +56,12 @@
var
result
=
[],
type
=
endpoint
.
split
(
'
/
'
)[
1
],
promises
,
usr
=
filters
.
user
||
'
all
'
,
dev
=
filters
.
device
||
'
all
'
,
isId
=
checkEndpointAsId
(
endpoint
),
user
_dict
=
{},
device
_dict
=
{},
i
;
// Remove '
user
' filter which should not be put in Automatic request.
delete
filters
.
user
;
// Remove '
device
' filter which should not be put in Automatic request.
delete
filters
.
device
;
// Check endpoint validity.
if
(
!
checkEndpoint
(
endpoint
))
{
throw
new
jIO
.
util
.
jIOError
(
'
Wrong Automatic API query. (usually
'
+
...
...
@@ -70,7 +70,7 @@
// Promise chain to handle multi-part response ("_metadata"->"next" parts).
function
treatNext
(
returned
)
{
var
data
,
user
_id
,
device
_id
,
next
;
// If the returned value was an error, return it (-> quite nasty design
// to have to return errors, but this is in order for all RSVP.all() to
...
...
@@ -79,7 +79,7 @@
return
returned
;
}
data
=
returned
[
0
];
user_id
=
user
_dict
[
returned
[
1
]];
device_id
=
device
_dict
[
returned
[
1
]];
data
=
[
data
];
if
(
!
isId
)
{
if
(
data
[
0
].
_metadata
===
undefined
)
{
...
...
@@ -94,16 +94,16 @@
path
=
URI
(
dat
.
url
).
path
();
temp
=
{
'
automatic_path
'
:
path
,
'
reference
'
:
'
/
'
+
user
_id
+
path
,
'
id
'
:
'
/
'
+
user
_id
+
path
,
'
reference
'
:
'
/
'
+
device
_id
+
path
,
'
id
'
:
'
/
'
+
device
_id
+
path
,
'
type
'
:
type
,
'
start_date
'
:
dat
.
started_at
||
null
,
'
stop_date
'
:
dat
.
ended_at
||
null
,
'
automatic_
user
'
:
user
_id
'
automatic_
device
'
:
device
_id
};
result
.
push
(
temp
);
return
jio
.
_cache
.
put
(
'
/
'
+
user
_id
+
path
,
temp
).
push
(
function
()
{
return
jio
.
_cache
.
putAttachment
(
'
/
'
+
user
_id
+
path
,
'
data
'
,
return
jio
.
_cache
.
put
(
'
/
'
+
device
_id
+
path
,
temp
).
push
(
function
()
{
return
jio
.
_cache
.
putAttachment
(
'
/
'
+
device
_id
+
path
,
'
data
'
,
new
Blob
([
JSON
.
stringify
(
dat
)],
{
type
:
'
text/plain
'
}));
});
...
...
@@ -136,13 +136,15 @@
return
new
RSVP
.
Queue
().
push
(
function
()
{
return
jIO
.
util
.
ajax
({
'
type
'
:
'
GET
'
,
'
url
'
:
automatic_template
.
expand
({
endpoint
:
[
'
user
'
,
'
me
'
,
''
]}),
'
url
'
:
automatic_template
.
expand
({
endpoint
:
[
'
user
'
,
'
me
'
,
'
device
'
,
''
]}),
'
headers
'
:
{
'
Authorization
'
:
'
Bearer
'
+
token
}
//'xhrFields': {withCredentials: true}
});
}).
push
(
function
(
respusr
)
{
user_dict
[
token
]
=
JSON
.
parse
(
respusr
.
target
.
responseText
).
id
;
if
(
usr
===
'
all
'
||
usr
===
user_dict
[
token
])
{
}).
push
(
function
(
respdev
)
{
device_dict
[
token
]
=
JSON
.
parse
(
respdev
.
target
.
responseText
).
results
[
0
].
id
;
if
(
dev
===
'
all
'
||
dev
===
device_dict
[
token
])
{
return
jIO
.
util
.
ajax
({
'
type
'
:
'
GET
'
,
'
url
'
:
URI
(
automatic_template
.
expand
({
endpoint
:
...
...
@@ -168,7 +170,7 @@
return
RSVP
.
all
(
promises
);
}).
push
(
function
(
trueOrErrorArray
)
{
// If we queried an id, return results should be length 1
if
(
isId
&&
(
usr
!==
'
all
'
))
{
if
(
isId
&&
(
dev
!==
'
all
'
))
{
if
(
result
.
length
===
1
)
{
return
result
[
0
];
}
...
...
@@ -178,7 +180,7 @@
}
// Result is empty, so we throw the correct token error.
i
=
jio
.
_access_tokens
.
map
(
function
(
token
)
{
if
(
user_dict
[
token
]
===
usr
)
{
if
(
device_dict
[
token
]
===
dev
)
{
return
true
;
}
return
false
;
...
...
@@ -188,8 +190,8 @@
throw
trueOrErrorArray
[
i
];
}
// If we didn't find the error in the promise returns, we don't have
// a token for
user usr
.
throw
new
jIO
.
util
.
jIOError
(
'
No valid token for
user:
'
+
usr
,
400
);
// a token for
device dev
.
throw
new
jIO
.
util
.
jIOError
(
'
No valid token for
device:
'
+
dev
,
400
);
}
// Otherwise return results and errors and let caller handle.
return
result
;
...
...
@@ -220,8 +222,8 @@
AutomaticAPIStorage
.
prototype
.
get
=
function
(
id
)
{
var
self
=
this
,
endpoint
=
id
.
split
(
'
/
'
),
usr
;
usr
=
endpoint
.
splice
(
1
,
1
)[
0
];
dev
;
dev
=
endpoint
.
splice
(
1
,
1
)[
0
];
endpoint
=
endpoint
.
join
(
'
/
'
);
if
(
id
.
indexOf
(
'
/
'
)
!==
0
)
{
throw
new
jIO
.
util
.
jIOError
(
'
id
'
+
id
+
...
...
@@ -234,13 +236,13 @@
if
(
!
checkEndpointAsId
(
endpoint
))
{
throw
new
jIO
.
util
.
jIOError
(
'
Invalid id.
'
,
400
);
}
if
(
usr
===
'
all
'
)
{
if
(
dev
===
'
all
'
)
{
throw
new
jIO
.
util
.
jIOError
(
'
Invalid id.
'
,
400
);
}
return
this
.
_cache
.
get
(
id
).
push
(
function
(
res
)
{
return
res
;
},
function
()
{
return
_queryAutomaticAPI
(
endpoint
,
{
'
user
'
:
usr
},
self
)
return
_queryAutomaticAPI
(
endpoint
,
{
'
device
'
:
dev
},
self
)
.
push
(
function
(
res
)
{
return
res
;
},
function
(
err
)
{
...
...
@@ -273,8 +275,8 @@
AutomaticAPIStorage
.
prototype
.
getAttachment
=
function
(
id
,
name
,
options
)
{
var
self
=
this
,
endpoint
=
id
.
split
(
'
/
'
),
usr
;
usr
=
endpoint
.
splice
(
1
,
1
)[
0
];
dev
;
dev
=
endpoint
.
splice
(
1
,
1
)[
0
];
endpoint
=
endpoint
.
join
(
'
/
'
);
if
(
id
.
indexOf
(
'
/
'
)
!==
0
)
{
throw
new
jIO
.
util
.
jIOError
(
'
id
'
+
id
+
...
...
@@ -287,7 +289,7 @@
if
(
!
checkEndpointAsId
(
endpoint
))
{
throw
new
jIO
.
util
.
jIOError
(
'
Invalid id.
'
,
400
);
}
if
(
usr
===
'
all
'
)
{
if
(
dev
===
'
all
'
)
{
throw
new
jIO
.
util
.
jIOError
(
'
Invalid id.
'
,
400
);
}
return
this
.
_cache
.
get
(
id
).
push
(
function
()
{
...
...
@@ -317,8 +319,8 @@
AutomaticAPIStorage
.
prototype
.
allAttachments
=
function
(
id
)
{
var
endpoint
=
id
.
split
(
'
/
'
),
usr
;
usr
=
endpoint
.
splice
(
1
,
1
)[
0
];
dev
;
dev
=
endpoint
.
splice
(
1
,
1
)[
0
];
endpoint
=
endpoint
.
join
(
'
/
'
);
if
(
id
.
indexOf
(
'
/
'
)
!==
0
)
{
throw
new
jIO
.
util
.
jIOError
(
'
id
'
+
id
+
...
...
@@ -331,7 +333,7 @@
if
(
!
checkEndpointAsId
(
endpoint
))
{
throw
new
jIO
.
util
.
jIOError
(
'
Invalid id.
'
,
400
);
}
if
(
usr
===
'
all
'
)
{
if
(
dev
===
'
all
'
)
{
throw
new
jIO
.
util
.
jIOError
(
'
Invalid id.
'
,
400
);
}
return
{
data
:
null
};
...
...
@@ -351,9 +353,9 @@
key_list
,
automatic_filters
=
{},
simplequery_type_value
,
intercept_keys
=
[
'
start_date
'
,
'
stop_date
'
,
'
automatic_
user
'
,
intercept_keys
=
[
'
start_date
'
,
'
stop_date
'
,
'
automatic_
device
'
,
'
vehicle
'
],
intercept_keys_automatic_name
=
[
'
started_at
'
,
'
ended_at
'
,
'
user
'
,
intercept_keys_automatic_name
=
[
'
started_at
'
,
'
ended_at
'
,
'
device
'
,
'
vehicle
'
],
intercept_accepted_operators
=
[[
'
>
'
,
'
>=
'
,
'
<
'
,
'
<=
'
],
[
'
>
'
,
'
>=
'
,
'
<
'
,
'
<=
'
],
[
'
=
'
],
[
'
=
'
]],
...
...
test/jio.storage/automaticapistorage.tests.js
View file @
46b74188
...
...
@@ -85,11 +85,14 @@
});
test
(
"
get inexistent document
"
,
function
()
{
var
url
=
"
https://api.automatic.com/user/me/
"
;
var
url
=
"
https://api.automatic.com/user/me/
device/
"
;
this
.
server
.
respondWith
(
"
GET
"
,
url
,
[
200
,
{
"
Content-Encoding
"
:
"
gzip
"
,
"
Content-Type
"
:
"
application/json
"
},
'
{"id": "usertest"}
'
]);
},
'
{"_metadata": {"count": 1, "next": null, "previous": null},
'
+
'
"results": [{"id": "devicetest",
'
+
'
"url": "https://api.automatic.com/user/usertest/
'
+
'
device/devicetest/", "version": 5}]}
'
]);
url
=
"
https://api.automatic.com/trip/T_inexistent/
"
;
this
.
server
.
respondWith
(
"
GET
"
,
url
,
[
404
,
{
"
Content-Encoding
"
:
"
gzip
"
,
...
...
@@ -98,11 +101,11 @@
stop
();
expect
(
3
);
this
.
jio
.
get
(
"
/
user
test/trip/T_inexistent/
"
)
this
.
jio
.
get
(
"
/
device
test/trip/T_inexistent/
"
)
.
fail
(
function
(
error
)
{
ok
(
error
instanceof
jIO
.
util
.
jIOError
);
equal
(
error
.
message
,
'
Cannot find document:
'
+
'
/
user
test/trip/T_inexistent/, Error:
'
+
'
/
device
test/trip/T_inexistent/, Error:
'
+
'
{"error": "err_object_not_found"}
'
);
equal
(
error
.
status_code
,
404
);
})
...
...
@@ -160,20 +163,24 @@
this
.
server
.
respondWith
(
"
GET
"
,
url
,
[
401
,
{
"
Content-Type
"
:
"
application/json
"
},
'
{"error":"err_unauthorized","detail":"Invalid token."}
\n
'
]);
url
=
"
https://api.automatic.com/user/me/
"
;
url
=
"
https://api.automatic.com/user/me/
device/
"
;
this
.
server
.
respondWith
(
"
GET
"
,
url
,
[
200
,
{
"
Content-Encoding
"
:
"
gzip
"
,
"
Content-Type
"
:
"
application/json
"
},
'
{"id": "usertest2"}
'
]);
},
'
{"_metadata": {"count": 1, "next": null, "previous": null},
'
+
'
"results": [{"id": "devicetest2",
'
+
'
"url": "https://api.automatic.com/user/usertest/
'
+
'
device/devicetest2/", "version": 5}]}
'
]);
stop
();
expect
(
3
);
this
.
jio
.
get
(
"
/
user
test/trip/T_whatever/
"
)
this
.
jio
.
get
(
"
/
device
test/trip/T_whatever/
"
)
.
fail
(
function
(
error
)
{
ok
(
error
instanceof
jIO
.
util
.
jIOError
);
equal
(
error
.
message
,
"
Cannot find document: /usertest/trip/T_whatever/
"
+
"
, Error: No valid token for user: usertest
"
);
equal
(
error
.
message
,
"
Cannot find document: /devicetest/trip/T_whatever/
"
+
"
, Error: No valid token for device: devicetest
"
);
equal
(
error
.
status_code
,
404
);
})
.
fail
(
function
(
error
)
{
...
...
@@ -200,24 +207,27 @@
xhr
.
respond
(
404
,
{
"
Content-Type
"
:
"
application/json
"
},
'
{"error":"err_unauthorized","detail":"Invalid token."}
\n
'
);
});
url
=
"
https://api.automatic.com/user/me/
"
;
url
=
"
https://api.automatic.com/user/me/
device/
"
;
this
.
server
.
respondWith
(
"
GET
"
,
url
,
[
200
,
{
"
Content-Encoding
"
:
"
gzip
"
,
"
Content-Type
"
:
"
application/json
"
},
'
{"id": "usertest"}
'
]);
},
'
{"_metadata": {"count": 1, "next": null, "previous": null},
'
+
'
"results": [{"id": "devicetest",
'
+
'
"url": "https://api.automatic.com/user/usertest/
'
+
'
device/devicetest/", "version": 5}]}
'
]);
stop
();
expect
(
1
);
this
.
jio
.
get
(
"
/
user
test/trip/T_randomtrip/
"
)
this
.
jio
.
get
(
"
/
device
test/trip/T_randomtrip/
"
)
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{
'
automatic_path
'
:
'
/trip/T_randomtrip/
'
,
'
reference
'
:
'
/
user
test/trip/T_randomtrip/
'
,
'
id
'
:
'
/
user
test/trip/T_randomtrip/
'
,
'
reference
'
:
'
/
device
test/trip/T_randomtrip/
'
,
'
id
'
:
'
/
device
test/trip/T_randomtrip/
'
,
'
type
'
:
'
trip
'
,
'
start_date
'
:
null
,
'
stop_date
'
:
null
,
'
automatic_
user
'
:
'
user
test
'
'
automatic_
device
'
:
'
device
test
'
},
"
Check single element type
"
);
})
.
fail
(
function
(
error
)
{
...
...
@@ -286,11 +296,14 @@
});
test
(
"
get inexistent document's attachment
"
,
function
()
{
var
url
=
"
https://api.automatic.com/user/me/
"
;
var
url
=
"
https://api.automatic.com/user/me/
device/
"
;
this
.
server
.
respondWith
(
"
GET
"
,
url
,
[
200
,
{
"
Content-Encoding
"
:
"
gzip
"
,
"
Content-Type
"
:
"
application/json
"
},
'
{"id": "usertest"}
'
]);
},
'
{"_metadata": {"count": 1, "next": null, "previous": null},
'
+
'
"results": [{"id": "devicetest",
'
+
'
"url": "https://api.automatic.com/user/usertest/
'
+
'
device/devicetest/", "version": 5}]}
'
]);
url
=
"
https://api.automatic.com/trip/T_inexistent/
"
;
this
.
server
.
respondWith
(
"
GET
"
,
url
,
[
404
,
{
"
Content-Encoding
"
:
"
gzip
"
,
...
...
@@ -299,11 +312,11 @@
stop
();
expect
(
3
);
this
.
jio
.
getAttachment
(
"
/
user
test/trip/T_inexistent/
"
,
'
whatever
'
)
this
.
jio
.
getAttachment
(
"
/
device
test/trip/T_inexistent/
"
,
'
whatever
'
)
.
fail
(
function
(
error
)
{
ok
(
error
instanceof
jIO
.
util
.
jIOError
);
equal
(
error
.
message
,
'
Cannot find document:
'
+
'
/
user
test/trip/T_inexistent/, Error:
'
+
'
/
device
test/trip/T_inexistent/, Error:
'
+
'
{"error": "err_object_not_found"}
'
);
equal
(
error
.
status_code
,
404
);
})
...
...
@@ -361,20 +374,24 @@
this
.
server
.
respondWith
(
"
GET
"
,
url
,
[
401
,
{
"
Content-Type
"
:
"
application/json
"
},
'
{"error":"err_unauthorized","detail":"Invalid token."}
\n
'
]);
url
=
"
https://api.automatic.com/user/me/
"
;
url
=
"
https://api.automatic.com/user/me/
device/
"
;
this
.
server
.
respondWith
(
"
GET
"
,
url
,
[
200
,
{
"
Content-Encoding
"
:
"
gzip
"
,
"
Content-Type
"
:
"
application/json
"
},
'
{"id": "usertest2"}
'
]);
},
'
{"_metadata": {"count": 1, "next": null, "previous": null},
'
+
'
"results": [{"id": "devicetest2",
'
+
'
"url": "https://api.automatic.com/user/usertest/
'
+
'
device/devicetest2/", "version": 5}]}
'
]);
stop
();
expect
(
3
);
this
.
jio
.
getAttachment
(
"
/
user
test/trip/T_whatever/
"
,
'
whatever
'
)
this
.
jio
.
getAttachment
(
"
/
device
test/trip/T_whatever/
"
,
'
whatever
'
)
.
fail
(
function
(
error
)
{
ok
(
error
instanceof
jIO
.
util
.
jIOError
);
equal
(
error
.
message
,
"
Cannot find document: /usertest/trip/T_whatever/
"
+
"
, Error: No valid token for user: usertest
"
);
equal
(
error
.
message
,
"
Cannot find document: /devicetest/trip/T_whatever/
"
+
"
, Error: No valid token for device: devicetest
"
);
equal
(
error
.
status_code
,
404
);
})
.
fail
(
function
(
error
)
{
...
...
@@ -401,15 +418,18 @@
xhr
.
respond
(
404
,
{
"
Content-Type
"
:
"
application/json
"
},
'
{"error":"err_unauthorized","detail":"Invalid token."}
\n
'
);
});
url
=
"
https://api.automatic.com/user/me/
"
;
url
=
"
https://api.automatic.com/user/me/
device/
"
;
this
.
server
.
respondWith
(
"
GET
"
,
url
,
[
200
,
{
"
Content-Encoding
"
:
"
gzip
"
,
"
Content-Type
"
:
"
application/json
"
},
'
{"id": "usertest"}
'
]);
},
'
{"_metadata": {"count": 1, "next": null, "previous": null},
'
+
'
"results": [{"id": "devicetest",
'
+
'
"url": "https://api.automatic.com/user/usertest/
'
+
'
device/devicetest/", "version": 5}]}
'
]);
stop
();
expect
(
1
);
this
.
jio
.
getAttachment
(
"
/
user
test/trip/T_randomtrip/
"
,
'
data
'
,
{
format
:
this
.
jio
.
getAttachment
(
"
/
device
test/trip/T_randomtrip/
"
,
'
data
'
,
{
format
:
'
text
'
}).
then
(
function
(
result
)
{
deepEqual
(
result
,
'
{"id":"T_randomtrip",
'
+
'
"url":"https://api.automatic.com/trip/T_randomtrip/"}
'
,
...
...
@@ -439,7 +459,7 @@
stop
();
expect
(
1
);
this
.
jio
.
allAttachments
(
'
/
user
test/trip/T_trip/
'
).
then
(
function
(
result
)
{
this
.
jio
.
allAttachments
(
'
/
device
test/trip/T_trip/
'
).
then
(
function
(
result
)
{
deepEqual
(
result
,
{
data
:
null
});
}).
fail
(
function
(
error
)
{
ok
(
false
,
error
);
...
...
@@ -489,11 +509,14 @@
'
{"_metadata":{"count":0,"next":null,"previous":null},
'
+
'
"results":[]}
'
);
});
url
=
"
https://api.automatic.com/user/me/
"
;
url
=
"
https://api.automatic.com/user/me/
device/
"
;
this
.
server
.
respondWith
(
"
GET
"
,
url
,
[
200
,
{
"
Content-Encoding
"
:
"
gzip
"
,
"
Content-Type
"
:
"
application/json
"
},
'
{"id": "0"}
'
]);
},
'
{"_metadata": {"count": 1, "next": null, "previous": null},
'
+
'
"results": [{"id": "0",
'
+
'
"url": "https://api.automatic.com/user/usertest/
'
+
'
device/0/", "version": 5}]}
'
]);
stop
();
expect
(
4
);
...
...
@@ -520,7 +543,7 @@
'
type
'
:
'
trip
'
,
'
start_date
'
:
"
2017-06-17T16:45:41Z
"
,
'
stop_date
'
:
"
2017-06-17T16:46:38Z
"
,
'
automatic_
user
'
:
'
0
'
'
automatic_
device
'
:
'
0
'
}],
"
Check trip is returned in result
"
);
})
.
fail
(
function
(
error
)
{
...
...
@@ -558,7 +581,7 @@
'
type
'
:
'
trip
'
,
'
start_date
'
:
"
2017-06-17T16:45:41Z
"
,
'
stop_date
'
:
"
2017-06-17T16:46:38Z
"
,
'
automatic_
user
'
:
'
0
'
'
automatic_
device
'
:
'
0
'
}],
"
Check trip is returned in result
"
);
})
.
fail
(
function
(
error
)
{
...
...
@@ -590,11 +613,14 @@
'
{"_metadata":{"count":0,"next":null,"previous":null},
'
+
'
"results":[]}
'
);
});
url
=
"
https://api.automatic.com/user/me/
"
;
url
=
"
https://api.automatic.com/user/me/
device/
"
;
this
.
server
.
respondWith
(
"
GET
"
,
url
,
[
200
,
{
"
Content-Encoding
"
:
"
gzip
"
,
"
Content-Type
"
:
"
application/json
"
},
'
{"id": "0"}
'
]);
},
'
{"_metadata": {"count": 1, "next": null, "previous": null},
'
+
'
"results": [{"id": "0",
'
+
'
"url": "https://api.automatic.com/user/usertest/
'
+
'
device/0/", "version": 5}]}
'
]);
stop
();
expect
(
1
);
...
...
@@ -609,7 +635,7 @@
'
type
'
:
'
vehicle
'
,
'
start_date
'
:
null
,
'
stop_date
'
:
null
,
'
automatic_
user
'
:
'
0
'
'
automatic_
device
'
:
'
0
'
}],
"
Check vehicle list is returned
"
);
})
.
fail
(
function
(
error
)
{
...
...
@@ -638,7 +664,7 @@
'
{"_metadata":{"count":0,"next":null,"previous":null},
'
+
'
"results":[]}
'
);
});
url
=
"
https://api.automatic.com/user/me/
"
;
url
=
"
https://api.automatic.com/user/me/
device/
"
;
this
.
server
.
respondWith
(
"
GET
"
,
url
,
[
404
,
{
"
Content-Encoding
"
:
"
gzip
"
,
"
Content-Type
"
:
"
application/json
"
...
...
@@ -679,11 +705,14 @@
'
{"_metadata":{"count":0,"next":null,"previous":null},
'
+
'
"results":[]}
'
);
});
url
=
"
https://api.automatic.com/user/me/
"
;
url
=
"
https://api.automatic.com/user/me/
device/
"
;
this
.
server
.
respondWith
(
"
GET
"
,
url
,
[
200
,
{
"
Content-Encoding
"
:
"
gzip
"
,
"
Content-Type
"
:
"
application/json
"
},
'
{"id": "0"}
'
]);
},
'
{"_metadata": {"count": 1, "next": null, "previous": null},
'
+
'
"results": [{"id": "0",
'
+
'
"url": "https://api.automatic.com/user/usertest/
'
+
'
device/0/", "version": 5}]}
'
]);
url
=
"
https://api.automatic.com/specific/nexturl/
"
;
this
.
server
.
respondWith
(
"
GET
"
,
url
,
[
200
,
{
"
Content-Encoding
"
:
"
gzip
"
,
...
...
@@ -705,7 +734,7 @@
'
type
'
:
'
vehicle
'
,
'
start_date
'
:
null
,
'
stop_date
'
:
null
,
'
automatic_
user
'
:
'
0
'
'
automatic_
device
'
:
'
0
'
},
{
'
automatic_path
'
:
'
/vehicle/V_example2/
'
,
'
reference
'
:
'
/0/vehicle/V_example2/
'
,
...
...
@@ -713,7 +742,7 @@
'
type
'
:
'
vehicle
'
,
'
start_date
'
:
null
,
'
stop_date
'
:
null
,
'
automatic_
user
'
:
'
0
'
'
automatic_
device
'
:
'
0
'
}],
"
Check vehicle list is returned
"
);
})
.
fail
(
function
(
error
)
{
...
...
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