Bug 1129086 - Extend the profile client to allow fetching profile images r=markh

This commit is contained in:
Zachary Carter 2015-02-05 13:32:04 -08:00
Родитель 3154b578e0
Коммит 7e2d72c418
2 изменённых файлов: 38 добавлений и 1 удалений

Просмотреть файл

@ -134,6 +134,18 @@ this.FxAccountsProfileClient.prototype = {
fetchProfile: function () {
log.debug("FxAccountsProfileClient: Requested profile");
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}
*/
let mockResponse = function (response) {
return function () {
let Request = function (requestUri) {
// Store the request uri so tests can inspect it
Request._requestUri = requestUri;
return {
setHeader: function () {},
get: function () {
@ -29,6 +31,8 @@ let mockResponse = function (response) {
}
};
};
return Request;
};
/**
@ -60,6 +64,7 @@ add_test(function successfulResponse () {
client.fetchProfile()
.then(
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.uid, "0d5c1a89b8c54580b8e3e8adadae864a");
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() {
validationHelper(undefined,
"Error: Missing 'serverURL' or 'token' configuration option");