Merge "Use Accept JSON Header when fetching detail, account"
This commit is contained in:
@@ -349,11 +349,7 @@
|
|||||||
* @param {Defs.FetchJSONRequest} req
|
* @param {Defs.FetchJSONRequest} req
|
||||||
*/
|
*/
|
||||||
_fetchJSON(req) {
|
_fetchJSON(req) {
|
||||||
if (!req.fetchOptions) req.fetchOptions = {};
|
req = this._addAcceptJsonHeader(req);
|
||||||
if (!req.fetchOptions.headers) req.fetchOptions.headers = new Headers();
|
|
||||||
if (!req.fetchOptions.headers.has('Accept')) {
|
|
||||||
req.fetchOptions.headers.append('Accept', 'application/json');
|
|
||||||
}
|
|
||||||
return this._fetchRawJSON(req).then(response => {
|
return this._fetchRawJSON(req).then(response => {
|
||||||
if (!response) {
|
if (!response) {
|
||||||
return;
|
return;
|
||||||
@@ -425,6 +421,19 @@
|
|||||||
return JSON.parse(source.substring(JSON_PREFIX.length));
|
return JSON.parse(source.substring(JSON_PREFIX.length));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Defs.FetchJSONRequest} req
|
||||||
|
* @return {Defs.FetchJSONRequest}
|
||||||
|
*/
|
||||||
|
_addAcceptJsonHeader(req) {
|
||||||
|
if (!req.fetchOptions) req.fetchOptions = {};
|
||||||
|
if (!req.fetchOptions.headers) req.fetchOptions.headers = new Headers();
|
||||||
|
if (!req.fetchOptions.headers.has('Accept')) {
|
||||||
|
req.fetchOptions.headers.append('Accept', 'application/json');
|
||||||
|
}
|
||||||
|
return req;
|
||||||
|
},
|
||||||
|
|
||||||
getConfig(noCache) {
|
getConfig(noCache) {
|
||||||
if (!noCache) {
|
if (!noCache) {
|
||||||
return this._fetchSharedCacheURL({
|
return this._fetchSharedCacheURL({
|
||||||
@@ -1126,7 +1135,8 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this._credentialCheck.checking = true;
|
this._credentialCheck.checking = true;
|
||||||
const req = {url: '/accounts/self/detail', reportUrlAsIs: true};
|
let req = {url: '/accounts/self/detail', reportUrlAsIs: true};
|
||||||
|
req = this._addAcceptJsonHeader(req);
|
||||||
// Skip the REST response cache.
|
// Skip the REST response cache.
|
||||||
return this._fetchRawJSON(req).then(res => {
|
return this._fetchRawJSON(req).then(res => {
|
||||||
if (!res) { return; }
|
if (!res) { return; }
|
||||||
@@ -1399,7 +1409,7 @@
|
|||||||
return this.getChangeActionURL(changeNum, null, '/detail').then(url => {
|
return this.getChangeActionURL(changeNum, null, '/detail').then(url => {
|
||||||
const urlWithParams = this._urlWithParams(url, optionsHex);
|
const urlWithParams = this._urlWithParams(url, optionsHex);
|
||||||
const params = {O: optionsHex};
|
const params = {O: optionsHex};
|
||||||
const req = {
|
let req = {
|
||||||
url,
|
url,
|
||||||
errFn: opt_errFn,
|
errFn: opt_errFn,
|
||||||
cancelCondition: opt_cancelCondition,
|
cancelCondition: opt_cancelCondition,
|
||||||
@@ -1407,6 +1417,7 @@
|
|||||||
fetchOptions: this._etags.getOptions(urlWithParams),
|
fetchOptions: this._etags.getOptions(urlWithParams),
|
||||||
anonymizedUrl: '/changes/*~*/detail?O=' + optionsHex,
|
anonymizedUrl: '/changes/*~*/detail?O=' + optionsHex,
|
||||||
};
|
};
|
||||||
|
req = this._addAcceptJsonHeader(req);
|
||||||
return this._fetchRawJSON(req).then(response => {
|
return this._fetchRawJSON(req).then(response => {
|
||||||
if (response && response.status === 304) {
|
if (response && response.status === 304) {
|
||||||
return Promise.resolve(this._parsePrefixedJSON(
|
return Promise.resolve(this._parsePrefixedJSON(
|
||||||
|
@@ -575,6 +575,15 @@ limitations under the License.
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('checkCredentials accepts only json', () => {
|
||||||
|
const authFetchStub = sandbox.stub(element._auth, 'fetch')
|
||||||
|
.returns(Promise.resolve());
|
||||||
|
element.checkCredentials();
|
||||||
|
assert.isTrue(authFetchStub.called);
|
||||||
|
assert.equal(authFetchStub.lastCall.args[1].headers.get('Accept'),
|
||||||
|
'application/json');
|
||||||
|
});
|
||||||
|
|
||||||
test('legacy n,z key in change url is replaced', () => {
|
test('legacy n,z key in change url is replaced', () => {
|
||||||
const stub = sandbox.stub(element, '_fetchJSON')
|
const stub = sandbox.stub(element, '_fetchJSON')
|
||||||
.returns(Promise.resolve([]));
|
.returns(Promise.resolve([]));
|
||||||
@@ -1227,6 +1236,16 @@ limitations under the License.
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('_getChangeDetail accepts only json', () => {
|
||||||
|
const authFetchStub = sandbox.stub(element._auth, 'fetch')
|
||||||
|
.returns(Promise.resolve());
|
||||||
|
const errFn = sinon.stub();
|
||||||
|
element._getChangeDetail(123, '516714', errFn);
|
||||||
|
assert.isTrue(authFetchStub.called);
|
||||||
|
assert.equal(authFetchStub.lastCall.args[1].headers.get('Accept'),
|
||||||
|
'application/json');
|
||||||
|
});
|
||||||
|
|
||||||
test('_getChangeDetail populates _projectLookup', () => {
|
test('_getChangeDetail populates _projectLookup', () => {
|
||||||
sandbox.stub(element, 'getChangeActionURL')
|
sandbox.stub(element, 'getChangeActionURL')
|
||||||
.returns(Promise.resolve(''));
|
.returns(Promise.resolve(''));
|
||||||
|
Reference in New Issue
Block a user