Fix `beginGetAreaLocations` (#567)
* Add null check + more clear type * Add test * Bump version to 12.1.1
This commit is contained in:
Родитель
55908ae28d
Коммит
fa534aef7d
|
@ -149,7 +149,7 @@ export class VsoClient {
|
|||
* @param area resource area name
|
||||
* @param locationId Guid of the location to get
|
||||
*/
|
||||
public beginGetLocation(area: string, locationId: string): Promise<ifm.ApiResourceLocation> {
|
||||
public beginGetLocation(area: string, locationId: string): Promise<ifm.ApiResourceLocation | undefined> {
|
||||
return this._initializationPromise.then(() => {
|
||||
return this.beginGetAreaLocations(area);
|
||||
}).then((areaLocations: VssApiResourceLocationLookup) => {
|
||||
|
@ -162,7 +162,11 @@ export class VsoClient {
|
|||
if (!areaLocationsPromise) {
|
||||
let requestUrl = this.resolveUrl(VsoClient.APIS_RELATIVE_PATH + "/" + area);
|
||||
areaLocationsPromise = this.restClient.options<any>(requestUrl)
|
||||
.then((res:restm.IRestResponse<any>) => {
|
||||
.then((res: restm.IRestResponse<any>) => {
|
||||
if (!res.result) {
|
||||
return {};
|
||||
}
|
||||
|
||||
let locationsLookup: VssApiResourceLocationLookup = {};
|
||||
let resourceLocations: ifm.ApiResourceLocation[] = res.result.value;
|
||||
let i;
|
||||
|
@ -190,7 +194,7 @@ export class VsoClient {
|
|||
}
|
||||
let queryString: string = '';
|
||||
|
||||
if (typeof(queryParams) !== 'string') {
|
||||
if (typeof (queryParams) !== 'string') {
|
||||
for (let property in queryParams) {
|
||||
if (queryParams.hasOwnProperty(property)) {
|
||||
const prop = queryParams[property];
|
||||
|
@ -200,14 +204,14 @@ export class VsoClient {
|
|||
}
|
||||
}
|
||||
|
||||
if (queryString === '' && prefix.length > 0){
|
||||
if (queryString === '' && prefix.length > 0) {
|
||||
// Date.prototype.toString() returns a string that is not valid for the REST API.
|
||||
// Need to specially call `toUTCString()` instead for such cases
|
||||
const queryValue = typeof queryParams === 'object' && 'toUTCString' in queryParams ? (queryParams as Date).toUTCString() : queryParams.toString();
|
||||
|
||||
|
||||
// Will always need to chop period off of end of prefix
|
||||
queryString = prefix.slice(0,-1) + '=' + encodeURIComponent(queryValue) + '&';
|
||||
queryString = prefix.slice(0, -1) + '=' + encodeURIComponent(queryValue) + '&';
|
||||
}
|
||||
return queryString;
|
||||
}
|
||||
|
@ -216,7 +220,7 @@ export class VsoClient {
|
|||
const queryString: string = '?' + this.queryParamsToStringHelper(queryParams, '');
|
||||
|
||||
// Will always need to slice either a ? or & off of the end
|
||||
return queryString.slice(0,-1);
|
||||
return queryString.slice(0, -1);
|
||||
}
|
||||
|
||||
protected getRequestUrl(routeTemplate: string, area: string, resource: string, routeValues: any, queryParams?: any): string {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "azure-devops-node-api",
|
||||
"version": "12.0.0",
|
||||
"version": "12.1.1",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "azure-devops-node-api",
|
||||
"description": "Node client for Azure DevOps and TFS REST APIs",
|
||||
"version": "12.1.0",
|
||||
"version": "12.1.1",
|
||||
"main": "./WebApi.js",
|
||||
"types": "./WebApi.d.ts",
|
||||
"scripts": {
|
||||
|
|
|
@ -228,6 +228,23 @@ describe('VSOClient Units', function () {
|
|||
//Assert
|
||||
assert(res.id === "testLocation");
|
||||
});
|
||||
|
||||
it('Returns \'undefined\' when the location is not found', async () => {
|
||||
nock('https://dev.azure.com/_apis/testArea8', {
|
||||
//Arrange
|
||||
reqheaders: {
|
||||
'accept': 'application/json',
|
||||
'user-agent': 'testAgent'
|
||||
}})
|
||||
.options('')
|
||||
.reply(404, 'Not Found"');
|
||||
|
||||
//Act
|
||||
const res = await vsoClient.beginGetLocation('testArea8', 'testLocation');
|
||||
|
||||
//Assert
|
||||
assert(res === undefined);
|
||||
})
|
||||
});
|
||||
|
||||
describe('WebApi Units', function () {
|
||||
|
|
Загрузка…
Ссылка в новой задаче