forked from mirrors/gecko-dev
Bug 1129086 - Extend the profile client to allow fetching profile images r=markh
This commit is contained in:
parent
3154b578e0
commit
7e2d72c418
2 changed files with 38 additions and 1 deletions
|
|
@ -134,6 +134,18 @@ this.FxAccountsProfileClient.prototype = {
|
||||||
fetchProfile: function () {
|
fetchProfile: function () {
|
||||||
log.debug("FxAccountsProfileClient: Requested profile");
|
log.debug("FxAccountsProfileClient: Requested profile");
|
||||||
return this._createRequest("/profile", "GET");
|
return this._createRequest("/profile", "GET");
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve user's profile from the server
|
||||||
|
*
|
||||||
|
* @return Promise
|
||||||
|
* Resolves: {Object} Successful response from the '/avatar' endpoint.
|
||||||
|
* Rejects: {FxAccountsProfileClientError} profile client error.
|
||||||
|
*/
|
||||||
|
fetchProfileImage: function () {
|
||||||
|
log.debug("FxAccountsProfileClient: Requested avatar");
|
||||||
|
return this._createRequest("/avatar", "GET");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,9 @@ const STATUS_SUCCESS = 200;
|
||||||
* @returns {Function}
|
* @returns {Function}
|
||||||
*/
|
*/
|
||||||
let mockResponse = function (response) {
|
let mockResponse = function (response) {
|
||||||
return function () {
|
let Request = function (requestUri) {
|
||||||
|
// Store the request uri so tests can inspect it
|
||||||
|
Request._requestUri = requestUri;
|
||||||
return {
|
return {
|
||||||
setHeader: function () {},
|
setHeader: function () {},
|
||||||
get: function () {
|
get: function () {
|
||||||
|
|
@ -29,6 +31,8 @@ let mockResponse = function (response) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
return Request;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -60,6 +64,7 @@ add_test(function successfulResponse () {
|
||||||
client.fetchProfile()
|
client.fetchProfile()
|
||||||
.then(
|
.then(
|
||||||
function (result) {
|
function (result) {
|
||||||
|
do_check_eq(client._Request._requestUri, "http://127.0.0.1:1111/v1/profile");
|
||||||
do_check_eq(result.email, "someone@restmail.net");
|
do_check_eq(result.email, "someone@restmail.net");
|
||||||
do_check_eq(result.uid, "0d5c1a89b8c54580b8e3e8adadae864a");
|
do_check_eq(result.uid, "0d5c1a89b8c54580b8e3e8adadae864a");
|
||||||
run_next_test();
|
run_next_test();
|
||||||
|
|
@ -164,6 +169,26 @@ add_test(function onCompleteRequestError () {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
add_test(function fetchProfileImage_successfulResponse () {
|
||||||
|
let client = new FxAccountsProfileClient(PROFILE_OPTIONS);
|
||||||
|
let response = {
|
||||||
|
success: true,
|
||||||
|
status: STATUS_SUCCESS,
|
||||||
|
body: "{\"avatar\":\"http://example.com/image.jpg\",\"id\":\"0d5c1a89b8c54580b8e3e8adadae864a\"}",
|
||||||
|
};
|
||||||
|
|
||||||
|
client._Request = new mockResponse(response);
|
||||||
|
client.fetchProfileImage()
|
||||||
|
.then(
|
||||||
|
function (result) {
|
||||||
|
do_check_eq(client._Request._requestUri, "http://127.0.0.1:1111/v1/avatar");
|
||||||
|
do_check_eq(result.avatar, "http://example.com/image.jpg");
|
||||||
|
do_check_eq(result.id, "0d5c1a89b8c54580b8e3e8adadae864a");
|
||||||
|
run_next_test();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
add_test(function constructorTests() {
|
add_test(function constructorTests() {
|
||||||
validationHelper(undefined,
|
validationHelper(undefined,
|
||||||
"Error: Missing 'serverURL' or 'token' configuration option");
|
"Error: Missing 'serverURL' or 'token' configuration option");
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue