Skip to content

Commit

Permalink
Responding to feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Danny McCormick committed Sep 18, 2018
1 parent d4799db commit 08ad406
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 55 deletions.
4 changes: 3 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ $ npm run build

## Test

You should test with node 4.x, 6.x and 8.x LTS. We recommend using nvm ([linux](https://github.com/creationix/nvm) / [windows](https://github.com/coreybutler/nvm-windows)). To run units:
You should test with node 4.x, 6.x and 8.x LTS. We recommend using nvm ([linux](https://github.com/creationix/nvm) / [windows](https://github.com/coreybutler/nvm-windows)).

To run units:

```
npm units
Expand Down
14 changes: 2 additions & 12 deletions make.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ target.build = function() {


target.units = function() {
pushd('test')
pushd('test');
run('npm install ../_build');
popd();

Expand All @@ -52,17 +52,7 @@ target.units = function() {
}

target.test = function() {
pushd('test')
run('npm install ../_build');
popd();

console.log("-------Unit Tests-------");
run('tsc -p ./test/units');
run('mocha test/units');

console.log("-------Other Tests-------");
run('tsc -p ./test/tests');
run('mocha test/tests');
target.units();
}

target.samples = function() {
Expand Down
8 changes: 0 additions & 8 deletions test/tests/tsconfig.json

This file was deleted.

9 changes: 0 additions & 9 deletions test/tests/vsoClientTests.ts

This file was deleted.

82 changes: 57 additions & 25 deletions test/units/vsoClientTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import nock = require('nock');
import vsom = require('../../api/VsoClient');
import * as rm from 'typed-rest-client/RestClient';
import { resolve } from 'path';
import { ApiResourceLocation } from '../../api/interfaces/common/VsoBaseInterfaces';

describe('VSOClient Units', function () {
let rest: rm.RestClient;
let vsoClient: vsom.VsoClient
const baseUrl = 'https://dev.azure.com/';
const baseUrl: string = 'https://dev.azure.com/';
before(() => {
const userAgent = "testAgent";
const handlers = [];
const options = null;
rest = new rm.RestClient(userAgent, null, handlers, options);
const userAgent: string = "testAgent";
rest = new rm.RestClient(userAgent, null, []);
vsoClient = new vsom.VsoClient(baseUrl, rest);
});

Expand All @@ -26,15 +26,15 @@ describe('VSOClient Units', function () {
it('constructs', () => {
this.timeout(1000);
const baseUrl = 'https://dev.azure.com/';
const userAgent = "testAgent";
const handlers = [];
const options = null;
const rest = new rm.RestClient(userAgent, null, handlers, options);
const userAgent: string = "testAgent";
const rest: rm.RestClient = new rm.RestClient(userAgent, null, []);
const vso: vsom.VsoClient = new vsom.VsoClient('https://microsoft.com', rest);

assert(vso, 'VsoClient should not be null');
});

it('gets versioning data where the max version and released version are identical', async () => {
//Arrange
nock('https://dev.azure.com/_apis/testArea', {
reqheaders: {
'accept': 'application/json',
Expand All @@ -43,13 +43,18 @@ describe('VSOClient Units', function () {
.options('')
.reply(200, {
value: [{id: 'testLocation', maxVersion: '1', releasedVersion: '1', routeTemplate: 'testTemplate', area: 'testArea', resourceName: 'testName', resourceVersion: '1'}]
});
const res = await vsoClient.getVersioningData('1', 'testArea', 'testLocation', {'testKey': 'testValue'}, null);
});

//Act
const res: vsom.ClientVersioningData = await vsoClient.getVersioningData('1', 'testArea', 'testLocation', {'testKey': 'testValue'}, null);

//Assert
assert(res.apiVersion === '1');
assert(res.requestUrl === 'https://dev.azure.com/testTemplate');
});

it('gets versioning data where ther requested version is greater than the max version', async () => {
//Arrange
nock('https://dev.azure.com/_apis/testArea2', {
reqheaders: {
'accept': 'application/json',
Expand All @@ -58,13 +63,18 @@ describe('VSOClient Units', function () {
.options('')
.reply(200, {
value: [{id: 'testLocation', maxVersion: '2', releasedVersion: '1', routeTemplate: 'testTemplate', area: 'testArea', resourceName: 'testName', resourceVersion: '1'}]
});
const res = await vsoClient.getVersioningData('3', 'testArea2', 'testLocation', {'testKey': 'testValue'}, null);
});

//Act
const res: vsom.ClientVersioningData = await vsoClient.getVersioningData('3', 'testArea2', 'testLocation', {'testKey': 'testValue'}, null);

//Assert
assert(res.apiVersion === '2-preview.1');
assert(res.requestUrl === 'https://dev.azure.com/testTemplate');
});

it('gets versioning data where ther requested version is less than the max version', async () => {
//Arrange
nock('https://dev.azure.com/_apis/testArea3', {
reqheaders: {
'accept': 'application/json',
Expand All @@ -73,13 +83,18 @@ describe('VSOClient Units', function () {
.options('')
.reply(200, {
value: [{id: 'testLocation', maxVersion: '2', releasedVersion: '2', routeTemplate: 'testTemplate', area: 'testArea', resourceName: 'testName', resourceVersion: '1'}]
});
const res = await vsoClient.getVersioningData('1', 'testArea3', 'testLocation', {'testKey': 'testValue'}, null);
});

//Act
const res: vsom.ClientVersioningData = await vsoClient.getVersioningData('1', 'testArea3', 'testLocation', {'testKey': 'testValue'}, null);

//Assert
assert(res.apiVersion === '1');
assert(res.requestUrl === 'https://dev.azure.com/testTemplate');
});

it('gets versioning data with simple query params', async () => {
//Arrange
nock('https://dev.azure.com/_apis/testArea4', {
reqheaders: {
'accept': 'application/json',
Expand All @@ -88,14 +103,19 @@ describe('VSOClient Units', function () {
.options('')
.reply(200, {
value: [{id: 'testLocation', maxVersion: '1', releasedVersion: '1', routeTemplate: 'testTemplate', area: 'testArea4', resourceName: 'testName', resourceVersion: '1'}]
});
});

//Act
const queryParams = {status: 2};
const res = await vsoClient.getVersioningData('1', 'testArea4', 'testLocation', {'testKey': 'testValue'}, queryParams);
const res: vsom.ClientVersioningData = await vsoClient.getVersioningData('1', 'testArea4', 'testLocation', {'testKey': 'testValue'}, queryParams);

//Assert
assert(res.apiVersion === '1');
assert(res.requestUrl === 'https://dev.azure.com/testTemplate?status=2');
});

it('gets versioning data with nested query params', async () => {
//Arrange
nock('https://dev.azure.com/_apis/testArea5', {
reqheaders: {
'accept': 'application/json',
Expand All @@ -104,14 +124,19 @@ describe('VSOClient Units', function () {
.options('')
.reply(200, {
value: [{id: 'testLocation', maxVersion: '1', releasedVersion: '1', routeTemplate: 'testTemplate', area: 'testArea5', resourceName: 'testName', resourceVersion: '1'}]
});
});

//Act
const queryParams = {status: {innerstatus: 2}};
const res = await vsoClient.getVersioningData('1', 'testArea5', 'testLocation', {'testKey': 'testValue'}, queryParams);
const res: vsom.ClientVersioningData = await vsoClient.getVersioningData('1', 'testArea5', 'testLocation', {'testKey': 'testValue'}, queryParams);

//Assert
assert(res.apiVersion === '1');
assert(res.requestUrl === 'https://dev.azure.com/testTemplate?innerstatus=2');
});

it('gets versioning data after an initialization promise', async () => {
//Arrange
nock('https://newbase.com/_apis/testArea6', {
reqheaders: {
'accept': 'application/json',
Expand All @@ -120,30 +145,37 @@ describe('VSOClient Units', function () {
.options('')
.reply(200, {
value: [{id: 'testLocation', maxVersion: '1', releasedVersion: '1', routeTemplate: 'testTemplate', area: 'testArea6', resourceName: 'testName', resourceVersion: '1'}]
});
});

//Act
vsoClient._setInitializationPromise(new Promise(() => {
vsoClient.baseUrl = 'https://newbase.com';
resolve();
}));
vsoClient._setInitializationPromise(Promise.resolve());
const res = await vsoClient.getVersioningData('1', 'testArea6', 'testLocation', {'testKey': 'testValue'}, null);
const res: vsom.ClientVersioningData = await vsoClient.getVersioningData('1', 'testArea6', 'testLocation', {'testKey': 'testValue'}, null);

//Assert
assert(res.apiVersion === '1');
assert(res.requestUrl === 'https://newbase.com/testTemplate');

vsoClient = new vsom.VsoClient(baseUrl, rest);
});

it('gets the location', async () => {
nock('https://dev.azure.com/_apis/testArea7', {
//Arrange
reqheaders: {
'accept': 'application/json',
'user-agent': 'testAgent'
}})
.options('')
.reply(200, {
value: [{id: 'testLocation', maxVersion: '1', releasedVersion: '1', routeTemplate: 'testTemplate', area: 'testArea7', resourceName: 'testName', resourceVersion: '1'}]
});
const res = await vsoClient.beginGetLocation('testArea7', 'testLocation');
});

//Act
const res: ApiResourceLocation = await vsoClient.beginGetLocation('testArea7', 'testLocation');

//Assert
assert(res.id === "testLocation");
});
});

0 comments on commit 08ad406

Please sign in to comment.