import * as chai from 'chai'; import * as chaiAsPromised from 'chai-as-promised'; import * as spies from 'chai-spies'; import * as sinon from 'sinon'; import * as sinonChai from 'sinon-chai'; import {CreateExcel} from '../../../lib/excel'; import { excelObjValue} from '../../data/billing_data'; chai.use(chaiAsPromised); chai.use(spies); chai.use(sinonChai); const expect: any = chai.expect; describe('CreateExcel', () => { const excelTestSuite: any = new CreateExcel(); describe('buildBillingExcel()', () => { it('should build the excel with the given value', async () => { const stub = sinon.stub(excelTestSuite, 'uploadTOSharePointList'); stub.onCall(0).returns(() => { console.log('fake function'); }); await sinon.spy(excelTestSuite, 'buildBillingExcel'); const excelParams = { excelItems: [[excelObjValue]], generateBilled: true, requestBody: null, loginName: 'test.user@test.com' }; await excelTestSuite.buildBillingExcel(excelParams); expect(excelTestSuite.buildBillingExcel).to.have.been.calledWith(excelParams); excelTestSuite.buildBillingExcel.restore(); excelTestSuite.uploadTOSharePointList.restore(); }); it('should create multiple excel sheets with different CANS', async () => { const stub = sinon.stub(excelTestSuite, 'uploadTOSharePointList'); stub.onCall(0).returns(() => { console.log('fake function'); }); sinon.spy(excelTestSuite, 'buildBillingExcel'); const newObject = { Title: 'Test Title', Created: '1/24/2017, 4:25:24 PM', Request_x0020_Type: 'Protein Sequencing Requests', RequestID: 1882, Project: 'TestName - PnChemProject', Section: 'pnchem', Request_x0020_Date: '1/24/2017', Client: 'Test Client', CAN: '1234', Lab: 'LMVR', LabPIName: 'TestTesterman', RTB_Cost: '19', SS_Cost: '0', BilledMonth: '1/1/2019' }; const excelParams = { excelItems: [[excelObjValue, excelObjValue, newObject], [excelObjValue]], generateBilled: true, requestBody: null, loginName: 'test.user@test.com' }; await excelTestSuite.buildBillingExcel(excelParams); expect(excelTestSuite.buildBillingExcel).to.have.been.calledWith(excelParams); excelTestSuite.buildBillingExcel.restore(); excelTestSuite.uploadTOSharePointList.restore(); }); it('should create an empty excel workbook', async () => { const stub = sinon.stub(excelTestSuite, 'uploadTOSharePointList'); stub.onCall(0).returns(() => { console.log('fake function'); }); await sinon.spy(excelTestSuite, 'buildBillingExcel'); const excelParams = { excelItems: [[ { listName: 'PROTEINID REQUESTS', Section: 'pnchem' } ]], generateBilled: true, requestBody: null, loginName: 'test.user@test.com' }; await excelTestSuite.buildBillingExcel(excelParams); expect(excelTestSuite.buildBillingExcel).to.have.been.calledWith(excelParams); }); }); describe('buildGenBillingSheet()', () => { afterEach(() => { excelTestSuite.buildGenBillingSheet.restore(); }); it('should build the excel with the given value', () => { sinon.spy(excelTestSuite, 'buildGenBillingSheet'); const excelParams = { excelItems: [[excelObjValue]], requestBody: null, loginName: 'test.user@test.com' }; excelTestSuite.buildGenBillingSheet(excelParams); expect(excelTestSuite.buildGenBillingSheet).to.have.been.calledWith(excelParams); }); it('should create excel sheets sorted by CANS', () => { sinon.spy(excelTestSuite, 'buildGenBillingSheet'); const newObject = { Title: 'Test Title', Created: '1/24/2017, 4:25:24 PM', Request_x0020_Type: 'Protein Sequencing Requests', RequestID: 1882, Project: 'TestName - PnChemProject', Section: 'pnchem', Request_x0020_Date: '1/24/2017', Client: 'Test Client', CAN: '1234', Lab: 'LMVR', LabPIName: 'TestTesterman', RTB_Cost: '19', SS_Cost: '0', BilledMonth: '1/1/2019' }; const excelParams = { excelItems: [[excelObjValue, excelObjValue, newObject], [excelObjValue]], requestBody: null, loginName: 'test.user@test.com' }; excelTestSuite.buildGenBillingSheet(excelParams); expect(excelTestSuite.buildGenBillingSheet).to.have.been.calledWith(excelParams); }); it('should create an empty excel workbook', () => { sinon.spy(excelTestSuite, 'buildGenBillingSheet'); const excelParams = { excelItems: [[ { listName: 'PROTEINID REQUESTS', Section: 'pnchem' } ]], requestBody: null, loginName: 'test.user@test.com' }; excelTestSuite.buildGenBillingSheet(excelParams); expect(excelTestSuite.buildGenBillingSheet).to.have.been.calledWith(excelParams); }); }); });