Skip to content

Commit 417f071

Browse files
author
damccorm
committed
Bump version
1 parent 65fa844 commit 417f071

4 files changed

Lines changed: 276 additions & 25 deletions

File tree

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "azure-devops-node-api",
33
"description": "Node client for Azure DevOps and TFS REST APIs",
4-
"version": "10.0.0",
4+
"version": "10.1.0",
55
"main": "./WebApi.js",
66
"types": "./WebApi.d.ts",
77
"scripts": {

test/package-lock.json

Lines changed: 0 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/units/tests.js

Lines changed: 274 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,274 @@
1+
"use strict";
2+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3+
return new (P || (P = Promise))(function (resolve, reject) {
4+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6+
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
7+
step((generator = generator.apply(thisArg, _arguments || [])).next());
8+
});
9+
};
10+
Object.defineProperty(exports, "__esModule", { value: true });
11+
const assert = require("assert");
12+
const fs = require("fs");
13+
const nock = require("nock");
14+
const os = require("os");
15+
const vsom = require("../../_build/VsoClient");
16+
const WebApi = require("../../_build/WebApi");
17+
const rm = require("../../_build/node_modules/typed-rest-client/RestClient");
18+
describe('VSOClient Units', function () {
19+
let rest;
20+
let vsoClient;
21+
const baseUrl = 'https://dev.azure.com/';
22+
before(() => {
23+
const userAgent = "testAgent";
24+
rest = new rm.RestClient(userAgent, null, []);
25+
vsoClient = new vsom.VsoClient(baseUrl, rest);
26+
});
27+
after(() => {
28+
});
29+
afterEach(() => {
30+
nock.cleanAll();
31+
vsoClient = new vsom.VsoClient(baseUrl, rest);
32+
});
33+
it('constructs', () => {
34+
//Arrange
35+
this.timeout(1000);
36+
const userAgent = "testAgent";
37+
const rest = new rm.RestClient(userAgent, null, []);
38+
//Act
39+
const vso = new vsom.VsoClient('https://microsoft.com', rest);
40+
//Assert
41+
assert(vso, 'VsoClient should not be null');
42+
});
43+
it('gets versioning data where the max version and released version are identical', () => __awaiter(this, void 0, void 0, function* () {
44+
//Arrange
45+
nock('https://dev.azure.com/_apis/testArea', {
46+
reqheaders: {
47+
'accept': 'application/json',
48+
'user-agent': 'testAgent'
49+
}
50+
})
51+
.options('')
52+
.reply(200, {
53+
value: [{ id: 'testLocation', maxVersion: '1', releasedVersion: '1', routeTemplate: 'testTemplate', area: 'testArea', resourceName: 'testName', resourceVersion: '1' }]
54+
});
55+
//Act
56+
const res = yield vsoClient.getVersioningData('1', 'testArea', 'testLocation', { 'testKey': 'testValue' }, null);
57+
//Assert
58+
assert(res.apiVersion === '1');
59+
assert(res.requestUrl === 'https://dev.azure.com/testTemplate');
60+
}));
61+
it('gets versioning data where ther requested version is greater than the max version', () => __awaiter(this, void 0, void 0, function* () {
62+
//Arrange
63+
nock('https://dev.azure.com/_apis/testArea2', {
64+
reqheaders: {
65+
'accept': 'application/json',
66+
'user-agent': 'testAgent'
67+
}
68+
})
69+
.options('')
70+
.reply(200, {
71+
value: [{ id: 'testLocation', maxVersion: '2', releasedVersion: '1', routeTemplate: 'testTemplate', area: 'testArea', resourceName: 'testName', resourceVersion: '1' }]
72+
});
73+
//Act
74+
const res = yield vsoClient.getVersioningData('3', 'testArea2', 'testLocation', { 'testKey': 'testValue' }, null);
75+
//Assert
76+
assert(res.apiVersion === '2-preview.1');
77+
assert(res.requestUrl === 'https://dev.azure.com/testTemplate');
78+
}));
79+
it('gets versioning data where ther requested version is less than the max version', () => __awaiter(this, void 0, void 0, function* () {
80+
//Arrange
81+
nock('https://dev.azure.com/_apis/testArea3', {
82+
reqheaders: {
83+
'accept': 'application/json',
84+
'user-agent': 'testAgent'
85+
}
86+
})
87+
.options('')
88+
.reply(200, {
89+
value: [{ id: 'testLocation', maxVersion: '2', releasedVersion: '2', routeTemplate: 'testTemplate', area: 'testArea', resourceName: 'testName', resourceVersion: '1' }]
90+
});
91+
//Act
92+
const res = yield vsoClient.getVersioningData('1', 'testArea3', 'testLocation', { 'testKey': 'testValue' }, null);
93+
//Assert
94+
assert(res.apiVersion === '1');
95+
assert(res.requestUrl === 'https://dev.azure.com/testTemplate');
96+
}));
97+
it('gets versioning data with simple query params', () => __awaiter(this, void 0, void 0, function* () {
98+
//Arrange
99+
nock('https://dev.azure.com/_apis/testArea4', {
100+
reqheaders: {
101+
'accept': 'application/json',
102+
'user-agent': 'testAgent'
103+
}
104+
})
105+
.options('')
106+
.reply(200, {
107+
value: [{ id: 'testLocation', maxVersion: '1', releasedVersion: '1', routeTemplate: 'testTemplate', area: 'testArea4', resourceName: 'testName', resourceVersion: '1' }]
108+
});
109+
//Act
110+
const queryParams = { status: 2 };
111+
const res = yield vsoClient.getVersioningData('1', 'testArea4', 'testLocation', { 'testKey': 'testValue' }, queryParams);
112+
//Assert
113+
assert(res.apiVersion === '1');
114+
assert(res.requestUrl === 'https://dev.azure.com/testTemplate?status=2');
115+
}));
116+
it('gets versioning data with nested query params', () => __awaiter(this, void 0, void 0, function* () {
117+
//Arrange
118+
nock('https://dev.azure.com/_apis/testArea5', {
119+
reqheaders: {
120+
'accept': 'application/json',
121+
'user-agent': 'testAgent'
122+
}
123+
})
124+
.options('')
125+
.reply(200, {
126+
value: [{ id: 'testLocation', maxVersion: '1', releasedVersion: '1', routeTemplate: 'testTemplate', area: 'testArea5', resourceName: 'testName', resourceVersion: '1' }]
127+
});
128+
//Act
129+
const queryParams = { status: { innerstatus: 2 } };
130+
const res = yield vsoClient.getVersioningData('1', 'testArea5', 'testLocation', { 'testKey': 'testValue' }, queryParams);
131+
//Assert
132+
assert(res.apiVersion === '1');
133+
assert(res.requestUrl === 'https://dev.azure.com/testTemplate?status.innerstatus=2');
134+
}));
135+
it('gets versioning data with complex nested query params', () => __awaiter(this, void 0, void 0, function* () {
136+
//Arrange
137+
nock('https://dev.azure.com/_apis/testArea5', {
138+
reqheaders: {
139+
'accept': 'application/json',
140+
'user-agent': 'testAgent'
141+
}
142+
})
143+
.options('')
144+
.reply(200, {
145+
value: [{ id: 'testLocation', maxVersion: '1', releasedVersion: '1', routeTemplate: 'testTemplate', area: 'testArea5', resourceName: 'testName', resourceVersion: '1' }]
146+
});
147+
//Act
148+
const queryParams = { status: { innerstatus: 2 }, version: '1', nestedObject: { nestedField: 'value', innerNestedObject: { key: 'val2' } } };
149+
const res = yield vsoClient.getVersioningData('1', 'testArea5', 'testLocation', { 'testKey': 'testValue' }, queryParams);
150+
//Assert
151+
assert.equal(res.apiVersion, '1');
152+
assert.equal(res.requestUrl, 'https://dev.azure.com/testTemplate?status.innerstatus=2&version=1&nestedObject.nestedField=value&nestedObject.innerNestedObject.key=val2');
153+
}));
154+
it('gets versioning datafor dates', () => __awaiter(this, void 0, void 0, function* () {
155+
//Arrange
156+
nock('https://dev.azure.com/_apis/testArea5', {
157+
reqheaders: {
158+
'accept': 'application/json',
159+
'user-agent': 'testAgent'
160+
}
161+
})
162+
.options('')
163+
.reply(200, {
164+
value: [{ id: 'testLocation', maxVersion: '1', releasedVersion: '1', routeTemplate: 'testTemplate', area: 'testArea5', resourceName: 'testName', resourceVersion: '1' }]
165+
});
166+
//Act
167+
const queryParams = { min: new Date(Date.UTC(208, 9, 19)) };
168+
const res = yield vsoClient.getVersioningData('1', 'testArea5', 'testLocation', { 'testKey': 'testValue' }, queryParams);
169+
//Assert
170+
assert.equal(res.apiVersion, '1');
171+
assert.equal(res.requestUrl, 'https://dev.azure.com/testTemplate?min=Wed%2C%2019%20Oct%200208%2000%3A00%3A00%20GMT');
172+
}));
173+
it('gets versioning data after an initialization promise', () => __awaiter(this, void 0, void 0, function* () {
174+
//Arrange
175+
nock('https://newbase.com/_apis/testArea6', {
176+
reqheaders: {
177+
'accept': 'application/json',
178+
'user-agent': 'testAgent'
179+
}
180+
})
181+
.options('')
182+
.reply(200, {
183+
value: [{ id: 'testLocation', maxVersion: '1', releasedVersion: '1', routeTemplate: 'testTemplate', area: 'testArea6', resourceName: 'testName', resourceVersion: '1' }]
184+
});
185+
//Act
186+
vsoClient._setInitializationPromise(new Promise(resolve => {
187+
vsoClient.baseUrl = 'https://newbase.com';
188+
resolve();
189+
}));
190+
const res = yield vsoClient.getVersioningData('1', 'testArea6', 'testLocation', { 'testKey': 'testValue' }, null);
191+
//Assert
192+
assert(res.apiVersion === '1');
193+
assert(res.requestUrl === 'https://newbase.com/testTemplate');
194+
}));
195+
it('gets the location', () => __awaiter(this, void 0, void 0, function* () {
196+
nock('https://dev.azure.com/_apis/testArea7', {
197+
//Arrange
198+
reqheaders: {
199+
'accept': 'application/json',
200+
'user-agent': 'testAgent'
201+
}
202+
})
203+
.options('')
204+
.reply(200, {
205+
value: [{ id: 'testLocation', maxVersion: '1', releasedVersion: '1', routeTemplate: 'testTemplate', area: 'testArea7', resourceName: 'testName', resourceVersion: '1' }]
206+
});
207+
//Act
208+
const res = yield vsoClient.beginGetLocation('testArea7', 'testLocation');
209+
//Assert
210+
assert(res.id === "testLocation");
211+
}));
212+
});
213+
describe('WebApi Units', function () {
214+
const osName = os.platform();
215+
const osVersion = os.release();
216+
const nodeApiName = 'azure-devops-node-api';
217+
const nodeApiVersion = JSON.parse(fs.readFileSync('package.json', 'utf8')).version;
218+
it('sets the user agent correctly when request settings are specified', () => __awaiter(this, void 0, void 0, function* () {
219+
const myWebApi = new WebApi.WebApi('https://microsoft.com', WebApi.getBasicHandler('user', 'password'), undefined, { productName: 'name', productVersion: '1.2.3' });
220+
const userAgent = `name/1.2.3 (${nodeApiName} ${nodeApiVersion}; ${osName} ${osVersion})`;
221+
assert.equal(userAgent, myWebApi.rest.client.userAgent, 'User agent should be: ' + userAgent);
222+
}));
223+
it('sets the user agent correctly when request settings are not specified', () => __awaiter(this, void 0, void 0, function* () {
224+
const myWebApi = new WebApi.WebApi('https://microsoft.com', WebApi.getBasicHandler('user', 'password'), undefined);
225+
const userAgent = `${nodeApiName}/${nodeApiVersion} (${osName} ${osVersion})`;
226+
assert.equal(userAgent, myWebApi.rest.client.userAgent, 'User agent should be: ' + userAgent);
227+
}));
228+
it('connects to the server with the correct user agent when request settings are specified', () => __awaiter(this, void 0, void 0, function* () {
229+
const myWebApi = new WebApi.WebApi('https://dev.azure.com/', WebApi.getBasicHandler('user', 'password'), undefined, { productName: 'name', productVersion: '1.2.3' });
230+
const userAgent = `name/1.2.3 (${nodeApiName} ${nodeApiVersion}; ${osName} ${osVersion})`;
231+
nock('https://dev.azure.com/_apis/testArea', {
232+
reqheaders: {
233+
'accept': 'application/json',
234+
'user-agent': userAgent
235+
}
236+
})
237+
.options('')
238+
.reply(200, {
239+
value: [{ id: 'testLocation', maxVersion: '1', releasedVersion: '1', routeTemplate: 'testTemplate', area: 'testArea', resourceName: 'testName', resourceVersion: '1' }]
240+
});
241+
// Act
242+
const res = yield myWebApi.vsoClient.getVersioningData('1', 'testArea', 'testLocation', { 'testKey': 'testValue' }, null);
243+
// Assert
244+
assert.equal(res.apiVersion, '1');
245+
assert.equal(res.requestUrl, 'https://dev.azure.com/testTemplate');
246+
}));
247+
it('connects to the server with the correct user agent when request settings are not specified', () => __awaiter(this, void 0, void 0, function* () {
248+
// Arrange
249+
const myWebApi = new WebApi.WebApi('https://dev.azure.com/', WebApi.getBasicHandler('user', 'password'), null);
250+
const userAgent = `${nodeApiName}/${nodeApiVersion} (${osName} ${osVersion})`;
251+
nock('https://dev.azure.com/_apis/testArea', {
252+
reqheaders: {
253+
'accept': 'application/json',
254+
'user-agent': userAgent
255+
}
256+
})
257+
.options('')
258+
.reply(200, {
259+
value: [{ id: 'testLocation', maxVersion: '1', releasedVersion: '1', routeTemplate: 'testTemplate', area: 'testArea', resourceName: 'testName', resourceVersion: '1' }]
260+
});
261+
// Act
262+
const res = yield myWebApi.vsoClient.getVersioningData('1', 'testArea', 'testLocation', { 'testKey': 'testValue' }, null);
263+
// Assert
264+
assert.equal(res.apiVersion, '1');
265+
assert.equal(res.requestUrl, 'https://dev.azure.com/testTemplate');
266+
}));
267+
it('supports no_proxy environment variable', () => __awaiter(this, void 0, void 0, function* () {
268+
const myWebApi = new WebApi.WebApi('https://dev.azure.com/', WebApi.getBasicHandler('user', 'password'), null);
269+
process.env.no_proxy = 'dev.azure.com,my-tfs-instance.host';
270+
assert.equal(myWebApi.isNoProxyHost('https://dev.azure.com/myproject'), true);
271+
assert.equal(myWebApi.isNoProxyHost('https://my-tfs-instance.host/myproject'), true);
272+
assert.equal(myWebApi.isNoProxyHost('https://my-other-tfs-instance.host/myproject'), false);
273+
}));
274+
});

0 commit comments

Comments
 (0)