<commit_before>import {
    WorkItemsService
} from './work-items.service';

import {
    WorkItemTrackingClient
} from './work-item-tracking.base';

import {
    WorkItemReference,
    WorkItem
} from "../Model/WorkItem";

import {
    expect
} from 'chai';

import 'jasmine';

import * as sinon from 'sinon';

describe("WorkItemsService", function() {

    let getCompletedWorkItemRefsDeffered: Q.Deferred < WorkItemReference[] > ;
    let getInProgressWorkItemRefsDeffered: Q.Deferred < WorkItemReference[] > ;
    let getWorkItemsDeffered: Q.Deferred < WorkItem[] > ;
    let getWorkItemRefsByWIQLDeffered: Q.Deferred < WorkItemReference[] > ;

    let workItemTrackingClient: WorkItemTrackingClient = {
        getCompletedWorkItemRefs: (): Promise < WorkItemReference[] > => {
            return null;
        },
        getInProgressWorkItemRefs: (): Promise < WorkItemReference[] > => {
            return null;
        },
        getWorkItems: (): Promise < WorkItem[] > => {
            return null;
        }
    };

    var sandbox = sinon.sandbox.create();

    let getWIs: sinon.SinonSpy;
    let witService: WorkItemsService;

    describe("In progress items", function() {

        let sampleInProgressResponseJson = {
            "queryType": "flat",
            "queryResultType": "workItem",
            "asOf": "2016-11-11T03:42:22.53Z",
            "columns": [{
                "referenceName": "System.Id",
                "name": "ID",
                "url": "https://dummy.com/DefaultCollection/_apis/wit/fields/System.Id"
            }, {
                "referenceName": "System.Title",
                "name": "Title",
                "url": "https://dummy.com/DefaultCollection/_apis/wit/fields/System.Title"
            }, {
                "referenceName": "System.State",
                "name": "State",
                "url": "https://dummy.com/DefaultCollection/_apis/wit/fields/System.State"
            }],
            "sortColumns": [{
                "field": {
                    "referenceName": "Microsoft.VSTS.Common.Priority",
                    "name": "Priority",
                    "url": "https://dummy.com/DefaultCollection/_apis/wit/fields/Microsoft.VSTS.Common.Priority"
                },
                "descending": false
            }, {
                "field": {
                    "referenceName": "System.CreatedDate",
                    "name": "Created Date",
                    "url": "https://dummy.com/DefaultCollection/_apis/wit/fields/System.CreatedDate"
                },
                "descending": true
            }],
            "workItems": [{
                "id": 21,
                "url": "https://dummy.com/DefaultCollection/_apis/wit/workItems/21"
            }, {
                "id": 20,
                "url": "https://dummy.com/DefaultCollection/_apis/wit/workItems/20"
            }, {
                "id": 19,
                "url": "https://dummy.com/DefaultCollection/_apis/wit/workItems/19"
            }]
        };

        let getInProgressWorkItemsJson = {
            "count": 3,
            "value": [{
                "id": 19,
                "rev": 2,
                "fields": {
                    "System.Id": 19,
                    "System.WorkItemType": "Product Backlog Item",
                    "System.State": "New",
                    "System.Title": "Optimise bundling",
                    "Microsoft.VSTS.Common.BacklogPriority": 1999985093
                },
                "url": "https://dummy.com/DefaultCollection/_apis/wit/workItems/19"
            }, {
                "id": 20,
                "rev": 4,
                "fields": {
                    "System.Id": 20,
                    "System.WorkItemType": "Product Backlog Item",
                    "System.State": "Committed",
                    "System.Title": "Integrate TFS queries",
                    "Microsoft.VSTS.Common.BacklogPriority": 1999955279
                },
                "url": "https://dummy.com/DefaultCollection/_apis/wit/workItems/20"
            }, {
                "id": 21,
                "rev": 3,
                "fields": {
                    "System.Id": 21,
                    "System.WorkItemType": "Product Backlog Item",
                    "System.State": "Approved",
                    "System.Title": "Visualise MC results",
                    "Microsoft.VSTS.Common.BacklogPriority": 1999977640
                },
                "url": "https://dummy.com/DefaultCollection/_apis/wit/workItems/21"
            }]
        };

        let getWisRefsClientStub: sinon.SinonSpy;

        let responseRefs = sampleInProgressResponseJson.workItems.map((it) => < WorkItemReference > {
            id: it.id,
            url: it.url
        });

        let responseWIs = getInProgressWorkItemsJson.value.map((it) => < WorkItem > {
            id: it.id,
            url: it.url,
            rev: it.rev,
            fields: it.fields,
            relations: null,
            _links: null,
            taktTime: null
        });

        beforeEach(function() {
            getInProgressWorkItemRefsDeffered = Q.defer < WorkItemReference[] > ();
            getWorkItemsDeffered = Q.defer < WorkItem[] > ();
            getWorkItemRefsByWIQLDeffered = Q.defer < WorkItemReference[] > ();

            getWIs = sandbox.stub(workItemTrackingClient, 'getWorkItems').returns(getWorkItemsDeffered.promise);
            getWisRefsClientStub = sandbox.stub(workItemTrackingClient, 'getInProgressWorkItemRefs').returns(getInProgressWorkItemRefsDeffered.promise);
            witService = new WorkItemsService(workItemTrackingClient);
        });

        afterEach(function() {
            sandbox.restore();
        });

        it("Should call wit client", function() {
            witService.getInProgressWorkItems();
            getInProgressWorkItemRefsDeffered.resolve(responseRefs);
            expect(getWisRefsClientStub.calledOnce);
            expect(getWIs.calledOnce);
        });

        it("Should return 3 items", function(done) {
            witService.getInProgressWorkItems().then(function(result) {
                expect(result).to.have.lengthOf(3);
                expect(result[0].id).to.eq(20);
                expect(result[1].id).to.eq(21);
                expect(result[2].id).to.eq(19);
            }).then(done, error => {
                fail(error);
                done();
            });
            getInProgressWorkItemRefsDeffered.resolve(responseRefs);
            getWorkItemsDeffered.resolve(responseWIs);
        });
    });

    describe("Completed work items", function() {

        let sampleCompletedJson = {
            "queryType": "flat",
            "queryResultType": "workItem",
            "asOf": "2016-11-13T10:54:43.877Z",
            "columns": [{
                "referenceName": "System.Id",
                "name": "ID",
                "url": "https://dummy.com/DefaultCollection/_apis/wit/fields/System.Id"
            }, {
                "referenceName": "System.Title",
                "name": "Title",
                "url": "https://dummy.com/DefaultCollection/_apis/wit/fields/System.Title"
            }, {
                "referenceName": "System.State",
                "name": "State",
                "url": "https://dummy.com/DefaultCollection/_apis/wit/fields/System.State"
            }],
            "sortColumns": [{
                "field": {
                    "referenceName": "Microsoft.VSTS.Common.BacklogPriority",
                    "name": "Backlog Priority",
                    "url": "https://dummy.com/DefaultCollection/_apis/wit/fields/Microsoft.VSTS.Common.BacklogPriority"
                },
                "descending": false
            }, {
                "field": {
                    "referenceName": "System.CreatedDate",
                    "name": "Created Date",
                    "url": "https://dummy.com/DefaultCollection/_apis/wit/fields/System.CreatedDate"
                },
                "descending": true
            }],
            "workItems": [{
                "id": 17,
                "url": "https://dummy.com/DefaultCollection/_apis/wit/workItems/17"
            }]
        };

        let getCompletedWorkItemsJson = {
            "count": 1,
            "value": [{
                "id": 17,
                "rev": 7,
                "fields": {
                    "System.Id": 17,
                    "System.IterationPath": "VSTS Monte Carlo\\Sprint 1",
                    "System.WorkItemType": "Product Backlog Item",
                    "System.State": "Done",
                    "System.Title": "Setup build definition",
                    "Microsoft.VSTS.Common.ClosedDate": "2016-11-13T11:17:17.933Z",
                    "Microsoft.VSTS.Common.BacklogPriority": 1999966460
                },
                "url": "https://dummy.com/DefaultCollection/_apis/wit/workItems/17"
            }]
        };

        let getCompletedWIRefs: sinon.SinonSpy;

        let responseRefs = sampleCompletedJson.workItems.map((it) => < WorkItemReference > {
            id: it.id,
            url: it.url
        });

        let responseWIs = getCompletedWorkItemsJson.value.map((it) => < WorkItem > {
            id: it.id,
            url: it.url,
            rev: it.rev,
            fields: it.fields,
            relations: null,
            _links: null,
            taktTime: null
        });

        beforeEach(function() {
            getCompletedWorkItemRefsDeffered = Q.defer < WorkItemReference[] > ();
            getWorkItemsDeffered = Q.defer < WorkItem[] > ();

            getWIs = sandbox.stub(workItemTrackingClient, 'getWorkItems').returns(getWorkItemsDeffered.promise);
            getCompletedWIRefs = sandbox.stub(workItemTrackingClient, 'getCompletedWorkItemRefs').returns(getCompletedWorkItemRefsDeffered.promise);
            witService = new WorkItemsService(workItemTrackingClient);
        });

        afterEach(function() {
            sandbox.restore();
        });

        it("Should call wit client", function() {
            witService.getCompletedWorkItems();
            getCompletedWorkItemRefsDeffered.resolve(responseRefs);
            getWorkItemsDeffered.resolve(responseWIs);
            expect(getCompletedWIRefs.calledOnce);
            expect(getWIs.calledOnce);
        });

        it("Should return one item", function(done) {
            witService.getCompletedWorkItems().then(function(result) {
                expect(result).to.have.lengthOf(1);
                expect(result[0].id).to.eq(17);
            }).then(done, fail);
            getCompletedWorkItemRefsDeffered.resolve(responseRefs);
            getWorkItemsDeffered.resolve(responseWIs);
        });


    });

    describe("", function() {

    });

    describe("Takt time calculation for work items list", function() {
        let sampleCompletedJson = {
            "queryType": "flat",
            "queryResultType": "workItem",
            "asOf": "2016-11-13T10:54:43.877Z",
            "columns": [{
                "referenceName": "System.Id",
                "name": "ID",
                "url": "https://dummy.com/DefaultCollection/_apis/wit/fields/System.Id"
            }, {
                "referenceName": "System.Title",
                "name": "Title",
                "url": "https://dummy.com/DefaultCollection/_apis/wit/fields/System.Title"
            }, {
                "referenceName": "System.State",
                "name": "State",
                "url": "https://dummy.com/DefaultCollection/_apis/wit/fields/System.State"
            }],
            "sortColumns": [{
                "field": {
                    "referenceName": "Microsoft.VSTS.Common.BacklogPriority",
                    "name": "Backlog Priority",
                    "url": "https://dummy.com/DefaultCollection/_apis/wit/fields/Microsoft.VSTS.Common.BacklogPriority"
                },
                "descending": false
            }, {
                "field": {
                    "referenceName": "System.CreatedDate",
                    "name": "Created Date",
                    "url": "https://dummy.com/DefaultCollection/_apis/wit/fields/System.CreatedDate"
                },
                "descending": true
            }],
            "workItems": [{
                "id": 47,
                "url": "https://dummy.com/DefaultCollection/_apis/wit/workItems/47"
            }, {
                "id": 88,
                "url": "https://dummy.com/DefaultCollection/_apis/wit/workItems/48"
            }, {
                "id": 49,
                "url": "https://dummy.com/DefaultCollection/_apis/wit/workItems/49"
            }, {
                "id": 50,
                "url": "https://dummy.com/DefaultCollection/_apis/wit/workItems/50"
            }]
        };

        let getCompletedWorkItemsJson = {
            "count": 4,
            "value": [{
                    "id": 47,
                    "rev": 9,
                    "fields": {
                        "System.Id": 47,
                        "System.IterationPath": "VSTS Monte Carlo\\Sprint 1",
                        "System.WorkItemType": "Product Backlog Item",
                        "System.State": "Done",
                        "System.Title": "Dummy 1",
                        "Microsoft.VSTS.Common.ClosedDate": "2016-11-15T14:17:17.933Z",
                        "Microsoft.VSTS.Common.BacklogPriority": 1999966460
                    },
                    "url": "https://dummy.com/DefaultCollection/_apis/wit/workItems/47"
                },
                {
                    "id": 48,
                    "rev": 9,
                    "fields": {
                        "System.Id": 48,
                        "System.IterationPath": "VSTS Monte Carlo\\Sprint 1",
                        "System.WorkItemType": "Product Backlog Item",
                        "System.State": "Done",
                        "System.Title": "Dummy 2",
                        "Microsoft.VSTS.Common.ClosedDate": "2016-11-13T15:17:17.933Z",
                        "Microsoft.VSTS.Common.BacklogPriority": 1999966423
                    },
                    "url": "https://dummy.com/DefaultCollection/_apis/wit/workItems/48"
                },
                {
                    "id": 49,
                    "rev": 9,
                    "fields": {
                        "System.Id": 49,
                        "System.IterationPath": "VSTS Monte Carlo\\Sprint 1",
                        "System.WorkItemType": "Product Backlog Item",
                        "System.State": "Done",
                        "System.Title": "Dummy 3",
                        "Microsoft.VSTS.Common.ClosedDate": "2016-11-10T16:12:17.933Z",
                        "Microsoft.VSTS.Common.BacklogPriority": 1999966498
                    },
                    "url": "https://dummy.com/DefaultCollection/_apis/wit/workItems/49"
                },
                {
                    "id": 50,
                    "rev": 9,
                    "fields": {
                        "System.Id": 50,
                        "System.IterationPath": "VSTS Monte Carlo\\Sprint 1",
                        "System.WorkItemType": "Product Backlog Item",
                        "System.State": "Done",
                        "System.Title": "Dummy 4",
                        "Microsoft.VSTS.Common.ClosedDate": "2016-11-13T16:12:17.933Z",
                        "Microsoft.VSTS.Common.BacklogPriority": 1999966498
                    },
                    "url": "https://dummy.com/DefaultCollection/_apis/wit/workItems/50"
                }
            ]
        };

        let getCompletedWIRefs: sinon.SinonSpy;

        let responseRefs = sampleCompletedJson.workItems.map((it) => < WorkItemReference > {
            id: it.id,
            url: it.url
        });

        let responseWIs = getCompletedWorkItemsJson.value.map((it) => < WorkItem > {
            id: it.id,
            url: it.url,
            rev: it.rev,
            fields: it.fields,
            relations: null,
            _links: null,
            taktTime: null
        });

        beforeEach(function() {
            getCompletedWorkItemRefsDeffered = Q.defer < WorkItemReference[] > ();
            getWorkItemsDeffered = Q.defer < WorkItem[] > ();

            getWIs = sandbox.stub(workItemTrackingClient, 'getWorkItems').returns(getWorkItemsDeffered.promise);
            getCompletedWIRefs = sandbox.stub(workItemTrackingClient, 'getCompletedWorkItemRefs').returns(getCompletedWorkItemRefsDeffered.promise);
            witService = new WorkItemsService(workItemTrackingClient);
        });

        afterEach(function() {
            sandbox.restore();
        });

        it("Should return four items", function(done) {
            witService.getCompletedWorkItems().then(function(result) {
                expect(result).to.have.lengthOf(4);
            }).then(done, error => {
                fail(error);
                done();
            });
            getCompletedWorkItemRefsDeffered.resolve(responseRefs);
            getWorkItemsDeffered.resolve(responseWIs);<commit_msg>Removing Q from unit tests<commit_after>import {
    WorkItemsService
} from './work-items.service';

import {
    WorkItemTrackingClient
} from './work-item-tracking.base';

import {
    WorkItemReference,
    WorkItem
} from "../Model/WorkItem";

import {
    expect
} from 'chai';

import 'jasmine';

import * as sinon from 'sinon';


class Deferred<T> {

  promise: Promise<T>;
  resolve: (value?: T | PromiseLike<T>) => void;
  reject:  (reason?: any) => void;

  constructor() {
    this.promise = new Promise<T>((resolve, reject) => {
      this.resolve = resolve;
      this.reject  = reject;
    });
  }
}

describe("WorkItemsService", function() {

    let getCompletedWorkItemRefsDeffered: Deferred < WorkItemReference[] > ;
    let getInProgressWorkItemRefsDeffered: Deferred  < WorkItemReference[] > ;
    let getWorkItemsDeffered: Deferred < WorkItem[] > ;
    let getWorkItemRefsByWIQLDeffered: Deferred  < WorkItemReference[] > ;

    let workItemTrackingClient: WorkItemTrackingClient = {
        getCompletedWorkItemRefs: (): Promise < WorkItemReference[] > => {
            return null;
        },
        getInProgressWorkItemRefs: (): Promise < WorkItemReference[] > => {
            return null;
        },
        getWorkItems: (): Promise < WorkItem[] > => {
            return null;
        }
    };

    var sandbox = sinon.sandbox.create();

    let getWIs: sinon.SinonSpy;
    let witService: WorkItemsService;

    describe("In progress items", function() {

        let sampleInProgressResponseJson = {
            "queryType": "flat",
            "queryResultType": "workItem",
            "asOf": "2016-11-11T03:42:22.53Z",
            "columns": [{
                "referenceName": "System.Id",
                "name": "ID",
                "url": "https://dummy.com/DefaultCollection/_apis/wit/fields/System.Id"
            }, {
                "referenceName": "System.Title",
                "name": "Title",
                "url": "https://dummy.com/DefaultCollection/_apis/wit/fields/System.Title"
            }, {
                "referenceName": "System.State",
                "name": "State",
                "url": "https://dummy.com/DefaultCollection/_apis/wit/fields/System.State"
            }],
            "sortColumns": [{
                "field": {
                    "referenceName": "Microsoft.VSTS.Common.Priority",
                    "name": "Priority",
                    "url": "https://dummy.com/DefaultCollection/_apis/wit/fields/Microsoft.VSTS.Common.Priority"
                },
                "descending": false
            }, {
                "field": {
                    "referenceName": "System.CreatedDate",
                    "name": "Created Date",
                    "url": "https://dummy.com/DefaultCollection/_apis/wit/fields/System.CreatedDate"
                },
                "descending": true
            }],
            "workItems": [{
                "id": 21,
                "url": "https://dummy.com/DefaultCollection/_apis/wit/workItems/21"
            }, {
                "id": 20,
                "url": "https://dummy.com/DefaultCollection/_apis/wit/workItems/20"
            }, {
                "id": 19,
                "url": "https://dummy.com/DefaultCollection/_apis/wit/workItems/19"
            }]
        };

        let getInProgressWorkItemsJson = {
            "count": 3,
            "value": [{
                "id": 19,
                "rev": 2,
                "fields": {
                    "System.Id": 19,
                    "System.WorkItemType": "Product Backlog Item",
                    "System.State": "New",
                    "System.Title": "Optimise bundling",
                    "Microsoft.VSTS.Common.BacklogPriority": 1999985093
                },
                "url": "https://dummy.com/DefaultCollection/_apis/wit/workItems/19"
            }, {
                "id": 20,
                "rev": 4,
                "fields": {
                    "System.Id": 20,
                    "System.WorkItemType": "Product Backlog Item",
                    "System.State": "Committed",
                    "System.Title": "Integrate TFS queries",
                    "Microsoft.VSTS.Common.BacklogPriority": 1999955279
                },
                "url": "https://dummy.com/DefaultCollection/_apis/wit/workItems/20"
            }, {
                "id": 21,
                "rev": 3,
                "fields": {
                    "System.Id": 21,
                    "System.WorkItemType": "Product Backlog Item",
                    "System.State": "Approved",
                    "System.Title": "Visualise MC results",
                    "Microsoft.VSTS.Common.BacklogPriority": 1999977640
                },
                "url": "https://dummy.com/DefaultCollection/_apis/wit/workItems/21"
            }]
        };

        let getWisRefsClientStub: sinon.SinonSpy;

        let responseRefs = sampleInProgressResponseJson.workItems.map((it) => < WorkItemReference > {
            id: it.id,
            url: it.url
        });

        let responseWIs = getInProgressWorkItemsJson.value.map((it) => < WorkItem > {
            id: it.id,
            url: it.url,
            rev: it.rev,
            fields: it.fields,
            relations: null,
            _links: null,
            taktTime: null
        });

        beforeEach(function() {
            getInProgressWorkItemRefsDeffered = new Deferred<WorkItemReference[]>();
            getWorkItemsDeffered = new Deferred < WorkItem[] > ();
            getWorkItemRefsByWIQLDeffered = new Deferred< WorkItemReference[] > ();

            getWIs = sandbox.stub(workItemTrackingClient, 'getWorkItems').returns(getWorkItemsDeffered.promise);
            getWisRefsClientStub = sandbox.stub(workItemTrackingClient, 'getInProgressWorkItemRefs').returns(getInProgressWorkItemRefsDeffered.promise);
            witService = new WorkItemsService(workItemTrackingClient);
        });

        afterEach(function() {
            sandbox.restore();
        });

        it("Should call wit client", function() {
            witService.getInProgressWorkItems();
            getInProgressWorkItemRefsDeffered.resolve(responseRefs);
            expect(getWisRefsClientStub.calledOnce);
            expect(getWIs.calledOnce);
        });

        it("Should return 3 items", function(done) {
            witService.getInProgressWorkItems().then(function(result) {
                expect(result).to.have.lengthOf(3);
                expect(result[0].id).to.eq(20);
                expect(result[1].id).to.eq(21);
                expect(result[2].id).to.eq(19);
            }).then(done, error => {
                fail(error);
                done();
            });
            getInProgressWorkItemRefsDeffered.resolve(responseRefs);
            getWorkItemsDeffered.resolve(responseWIs);
        });
    });

    describe("Completed work items", function() {

        let sampleCompletedJson = {
            "queryType": "flat",
            "queryResultType": "workItem",
            "asOf": "2016-11-13T10:54:43.877Z",
            "columns": [{
                "referenceName": "System.Id",
                "name": "ID",
                "url": "https://dummy.com/DefaultCollection/_apis/wit/fields/System.Id"
            }, {
                "referenceName": "System.Title",
                "name": "Title",
                "url": "https://dummy.com/DefaultCollection/_apis/wit/fields/System.Title"
            }, {
                "referenceName": "System.State",
                "name": "State",
                "url": "https://dummy.com/DefaultCollection/_apis/wit/fields/System.State"
            }],
            "sortColumns": [{
                "field": {
                    "referenceName": "Microsoft.VSTS.Common.BacklogPriority",
                    "name": "Backlog Priority",
                    "url": "https://dummy.com/DefaultCollection/_apis/wit/fields/Microsoft.VSTS.Common.BacklogPriority"
                },
                "descending": false
            }, {
                "field": {
                    "referenceName": "System.CreatedDate",
                    "name": "Created Date",
                    "url": "https://dummy.com/DefaultCollection/_apis/wit/fields/System.CreatedDate"
                },
                "descending": true
            }],
            "workItems": [{
                "id": 17,
                "url": "https://dummy.com/DefaultCollection/_apis/wit/workItems/17"
            }]
        };

        let getCompletedWorkItemsJson = {
            "count": 1,
            "value": [{
                "id": 17,
                "rev": 7,
                "fields": {
                    "System.Id": 17,
                    "System.IterationPath": "VSTS Monte Carlo\\Sprint 1",
                    "System.WorkItemType": "Product Backlog Item",
                    "System.State": "Done",
                    "System.Title": "Setup build definition",
                    "Microsoft.VSTS.Common.ClosedDate": "2016-11-13T11:17:17.933Z",
                    "Microsoft.VSTS.Common.BacklogPriority": 1999966460
                },
                "url": "https://dummy.com/DefaultCollection/_apis/wit/workItems/17"
            }]
        };

        let getCompletedWIRefs: sinon.SinonSpy;

        let responseRefs = sampleCompletedJson.workItems.map((it) => < WorkItemReference > {
            id: it.id,
            url: it.url
        });

        let responseWIs = getCompletedWorkItemsJson.value.map((it) => < WorkItem > {
            id: it.id,
            url: it.url,
            rev: it.rev,
            fields: it.fields,
            relations: null,
            _links: null,
            taktTime: null
        });

        beforeEach(function() {
            getCompletedWorkItemRefsDeffered = new Deferred< WorkItemReference[] > ();
            getWorkItemsDeffered = new Deferred < WorkItem[] > ();

            getWIs = sandbox.stub(workItemTrackingClient, 'getWorkItems').returns(getWorkItemsDeffered.promise);
            getCompletedWIRefs = sandbox.stub(workItemTrackingClient, 'getCompletedWorkItemRefs').returns(getCompletedWorkItemRefsDeffered.promise);
            witService = new WorkItemsService(workItemTrackingClient);
        });

        afterEach(function() {
            sandbox.restore();
        });

        it("Should call wit client", function() {
            witService.getCompletedWorkItems();
            getCompletedWorkItemRefsDeffered.resolve(responseRefs);
            getWorkItemsDeffered.resolve(responseWIs);
            expect(getCompletedWIRefs.calledOnce);
            expect(getWIs.calledOnce);
        });

        it("Should return one item", function(done) {
            witService.getCompletedWorkItems().then(function(result) {
                expect(result).to.have.lengthOf(1);
                expect(result[0].id).to.eq(17);
            }).then(done, fail);
            getCompletedWorkItemRefsDeffered.resolve(responseRefs);
            getWorkItemsDeffered.resolve(responseWIs);
        });


    });

    describe("Takt time calculation for work items list", function() {
        let sampleCompletedJson = {
            "queryType": "flat",
            "queryResultType": "workItem",
            "asOf": "2016-11-13T10:54:43.877Z",
            "columns": [{
                "referenceName": "System.Id",
                "name": "ID",
                "url": "https://dummy.com/DefaultCollection/_apis/wit/fields/System.Id"
            }, {
                "referenceName": "System.Title",
                "name": "Title",
                "url": "https://dummy.com/DefaultCollection/_apis/wit/fields/System.Title"
            }, {
                "referenceName": "System.State",
                "name": "State",
                "url": "https://dummy.com/DefaultCollection/_apis/wit/fields/System.State"
            }],
            "sortColumns": [{
                "field": {
                    "referenceName": "Microsoft.VSTS.Common.BacklogPriority",
                    "name": "Backlog Priority",
                    "url": "https://dummy.com/DefaultCollection/_apis/wit/fields/Microsoft.VSTS.Common.BacklogPriority"
                },
                "descending": false
            }, {
                "field": {
                    "referenceName": "System.CreatedDate",
                    "name": "Created Date",
                    "url": "https://dummy.com/DefaultCollection/_apis/wit/fields/System.CreatedDate"
                },
                "descending": true
            }],
            "workItems": [{
                "id": 47,
                "url": "https://dummy.com/DefaultCollection/_apis/wit/workItems/47"
            }, {
                "id": 88,
                "url": "https://dummy.com/DefaultCollection/_apis/wit/workItems/48"
            }, {
                "id": 49,
                "url": "https://dummy.com/DefaultCollection/_apis/wit/workItems/49"
            }, {
                "id": 50,
                "url": "https://dummy.com/DefaultCollection/_apis/wit/workItems/50"
            }]
        };

        let getCompletedWorkItemsJson = {
            "count": 4,
            "value": [{
                    "id": 47,
                    "rev": 9,
                    "fields": {
                        "System.Id": 47,
                        "System.IterationPath": "VSTS Monte Carlo\\Sprint 1",
                        "System.WorkItemType": "Product Backlog Item",
                        "System.State": "Done",
                        "System.Title": "Dummy 1",
                        "Microsoft.VSTS.Common.ClosedDate": "2016-11-15T14:17:17.933Z",
                        "Microsoft.VSTS.Common.BacklogPriority": 1999966460
                    },
                    "url": "https://dummy.com/DefaultCollection/_apis/wit/workItems/47"
                },
                {
                    "id": 48,
                    "rev": 9,
                    "fields": {
                        "System.Id": 48,
                        "System.IterationPath": "VSTS Monte Carlo\\Sprint 1",
                        "System.WorkItemType": "Product Backlog Item",
                        "System.State": "Done",
                        "System.Title": "Dummy 2",
                        "Microsoft.VSTS.Common.ClosedDate": "2016-11-13T15:17:17.933Z",
                        "Microsoft.VSTS.Common.BacklogPriority": 1999966423
                    },
                    "url": "https://dummy.com/DefaultCollection/_apis/wit/workItems/48"
                },
                {
                    "id": 49,
                    "rev": 9,
                    "fields": {
                        "System.Id": 49,
                        "System.IterationPath": "VSTS Monte Carlo\\Sprint 1",
                        "System.WorkItemType": "Product Backlog Item",
                        "System.State": "Done",
                        "System.Title": "Dummy 3",
                        "Microsoft.VSTS.Common.ClosedDate": "2016-11-10T16:12:17.933Z",
                        "Microsoft.VSTS.Common.BacklogPriority": 1999966498
                    },
                    "url": "https://dummy.com/DefaultCollection/_apis/wit/workItems/49"
                },
                {
                    "id": 50,
                    "rev": 9,
                    "fields": {
                        "System.Id": 50,
                        "System.IterationPath": "VSTS Monte Carlo\\Sprint 1",
                        "System.WorkItemType": "Product Backlog Item",
                        "System.State": "Done",
                        "System.Title": "Dummy 4",
                        "Microsoft.VSTS.Common.ClosedDate": "2016-11-13T16:12:17.933Z",
                        "Microsoft.VSTS.Common.BacklogPriority": 1999966498
                    },
                    "url": "https://dummy.com/DefaultCollection/_apis/wit/workItems/50"
                }
            ]
        };

        let getCompletedWIRefs: sinon.SinonSpy;

        let responseRefs = sampleCompletedJson.workItems.map((it) => < WorkItemReference > {
            id: it.id,
            url: it.url
        });

        let responseWIs = getCompletedWorkItemsJson.value.map((it) => < WorkItem > {
            id: it.id,
            url: it.url,
            rev: it.rev,
            fields: it.fields,
            relations: null,
            _links: null,
            taktTime: null
        });

        beforeEach(function() {
            getCompletedWorkItemRefsDeffered = new Deferred < WorkItemReference[] > ();
            getWorkItemsDeffered = new Deferred < WorkItem[] > ();

            getWIs = sandbox.stub(workItemTrackingClient, 'getWorkItems').returns(getWorkItemsDeffered.promise);
            getCompletedWIRefs = sandbox.stub(workItemTrackingClient, 'getCompletedWorkItemRefs').returns(getCompletedWorkItemRefsDeffered.promise);
            witService = new WorkItemsService(workItemTrackingClient);
        });

        afterEach(function() {
            sandbox.restore();
        });

        it("Should return four items", function(done) {
            witService.getCompletedWorkItems().then(function(result) {
                expect(result).to.have.lengthOf(4);
            }).then(done, error => {
                fail(error);
                done();
            });
            getCompletedWorkItemRefsDeffered.resolve(responseRefs);
            getWorkItemsDeffered.resolve(responseWIs);
{'fraction_non_alphanumeric': 0.13015571482025157, 'fraction_numerical': 0.019054197967935987, 'mean_word_length': 1.4804740486899408, 'pattern_counts': {'":': 358, '<': 47, '<?xml version=': 0, '>': 72, 'https://': 62, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2483531', 'n_tokens_mistral': 10107, 'n_tokens_neox': 9084, 'n_words': 1393}