import * as chai from 'chai'; import * as chaiAsPromised from 'chai-as-promised'; chai.use(chaiAsPromised); import * as sinon from 'sinon'; import {Requests} from '../../lib/request' import { equal } from 'assert'; const expect = chai.expect; describe('Requests', () => { let requests, facilityId = 'facility-ci', loginName = 'testUser'; let FacilityProxyMock, facilityItemMock; beforeEach(() => { facilityItemMock = {}; FacilityProxyMock = {Proxy: {Items: sinon.stub().returns(facilityItemMock)}}; }); beforeEach(() => { requests = new Requests(facilityId, loginName); }); describe('constructor', () => { it('should initialize facilityId and loginName', async () => { expect(requests.facilityId).to.equal('facility-ci'); expect(requests.loginName).to.equal('testUser'); }); }); describe('getAll()', () => { const data = { items: [ { "Properties": [ { "choices": [], "defaultChoice": "", "internalName": "Title", "isExcluded": false, "isReadOnly": false, "isRequired": true, "isStaffOnly": false, "lsInternal": false, "isInternal": false, "label": "Request Name", "type": "Text", "value": "test-20091102-1", "guid": "fa564e0f-0c70-4ab9-b863-0177e6ddd247", "description": "", "displayFormat": null }, { "choices": [ "Submitted", "Received", "QC Completed", "Approved", "Processing", "PickUp", "Completed", "ReadyToBill", "Billed", "Cancelled" ], "defaultChoice": "Submitted", "internalName": "Status", "isExcluded": true, "isReadOnly": false, "isRequired": false, "isStaffOnly": false, "lsInternal": false, "isInternal": false, "label": "Status", "type": "Choice", "value": "Processing", "guid": "49309a1a-c6be-49b8-91e5-5211aad1098a", "description": "", "displayFormat": null }, { "choices": [], "defaultChoice": null, "internalName": "ID", "isExcluded": false, "isReadOnly": true, "isRequired": false, "isStaffOnly": false, "lsInternal": false, "isInternal": false, "label": "ID", "type": "Counter", "value": "1", "guid": "1d22ea11-1e32-424e-89ab-9fedbadb6ce1", "description": "", "displayFormat": null } ] }, { "Properties": [ { "choices": [], "defaultChoice": "", "internalName": "Title", "isExcluded": false, "isReadOnly": false, "isRequired": true, "isStaffOnly": false, "lsInternal": false, "isInternal": false, "label": "Request Name", "type": "Text", "value": "test-20091102-1", "guid": "fa564e0f-0c70-4ab9-b863-0177e6ddd247", "description": "", "displayFormat": null }, { "choices": [ "Submitted", "Received", "QC Completed", "Approved", "Processing", "PickUp", "Completed", "ReadyToBill", "Billed", "Cancelled" ], "defaultChoice": "Submitted", "internalName": "Status", "isExcluded": true, "isReadOnly": false, "isRequired": false, "isStaffOnly": false, "lsInternal": false, "isInternal": false, "label": "Status", "type": "Choice", "value": "Processing", "guid": "49309a1a-c6be-49b8-91e5-5211aad1098a", "description": "", "displayFormat": null }, { "choices": [], "defaultChoice": null, "internalName": "ID", "isExcluded": false, "isReadOnly": true, "isRequired": false, "isStaffOnly": false, "lsInternal": false, "isInternal": false, "label": "ID", "type": "Counter", "value": "2", "guid": "1d22ea11-1e32-424e-89ab-9fedbadb6ce1", "description": "", "displayFormat": null } ] }, { "Properties": [ { "choices": [], "defaultChoice": "", "internalName": "Title", "isExcluded": false, "isReadOnly": false, "isRequired": true, "isStaffOnly": false, "lsInternal": false, "isInternal": false, "label": "Request Name", "type": "Text", "value": "test-20091102-1", "guid": "fa564e0f-0c70-4ab9-b863-0177e6ddd247", "description": "", "displayFormat": null }, { "choices": [ "Submitted", "Received", "QC Completed", "Approved", "Processing", "PickUp", "Completed", "ReadyToBill", "Billed", "Cancelled" ], "defaultChoice": "Submitted", "internalName": "Status", "isExcluded": true, "isReadOnly": false, "isRequired": false, "isStaffOnly": false, "lsInternal": false, "isInternal": false, "label": "Status", "type": "Choice", "value": "Processing", "guid": "49309a1a-c6be-49b8-91e5-5211aad1098a", "description": "", "displayFormat": null }, { "choices": [], "defaultChoice": null, "internalName": "ID", "isExcluded": false, "isReadOnly": true, "isRequired": false, "isStaffOnly": false, "lsInternal": false, "isInternal": false, "label": "ID", "type": "Counter", "value": "3", "guid": "1d22ea11-1e32-424e-89ab-9fedbadb6ce1", "description": "", "displayFormat": null } ] } ] }; let response; beforeEach(() => { requests.getAll = sinon.stub().resolves(data.items); }); beforeEach(async () => { response = await requests.getAll(); }); it('should call requestList.getAll() method', async () => { expect(requests.getAll.callCount).to.equal(1); }); it('should return an object with array of data model', async () => { const item = { items: [ { "Properties": [ { "choices": [], "defaultChoice": "", "internalName": "Title", "isExcluded": false, "isReadOnly": false, "isRequired": true, "isStaffOnly": false, "lsInternal": false, "isInternal": false, "label": "Request Name", "type": "Text", "value": "test-20091102-1", "guid": "fa564e0f-0c70-4ab9-b863-0177e6ddd247", "description": "", "displayFormat": null }, { "choices": [ "Submitted", "Received", "QC Completed", "Approved", "Processing", "PickUp", "Completed", "ReadyToBill", "Billed", "Cancelled" ], "defaultChoice": "Submitted", "internalName": "Status", "isExcluded": true, "isReadOnly": false, "isRequired": false, "isStaffOnly": false, "lsInternal": false, "isInternal": false, "label": "Status", "type": "Choice", "value": "Processing", "guid": "49309a1a-c6be-49b8-91e5-5211aad1098a", "description": "", "displayFormat": null }, { "choices": [], "defaultChoice": null, "internalName": "ID", "isExcluded": false, "isReadOnly": true, "isRequired": false, "isStaffOnly": false, "lsInternal": false, "isInternal": false, "label": "ID", "type": "Counter", "value": "1", "guid": "1d22ea11-1e32-424e-89ab-9fedbadb6ce1", "description": "", "displayFormat": null } ] }, { "Properties": [ { "choices": [], "defaultChoice": "", "internalName": "Title", "isExcluded": false, "isReadOnly": false, "isRequired": true, "isStaffOnly": false, "lsInternal": false, "isInternal": false, "label": "Request Name", "type": "Text", "value": "test-20091102-1", "guid": "fa564e0f-0c70-4ab9-b863-0177e6ddd247", "description": "", "displayFormat": null }, { "choices": [ "Submitted", "Received", "QC Completed", "Approved", "Processing", "PickUp", "Completed", "ReadyToBill", "Billed", "Cancelled" ], "defaultChoice": "Submitted", "internalName": "Status", "isExcluded": true, "isReadOnly": false, "isRequired": false, "isStaffOnly": false, "lsInternal": false, "isInternal": false, "label": "Status", "type": "Choice", "value": "Processing", "guid": "49309a1a-c6be-49b8-91e5-5211aad1098a", "description": "", "displayFormat": null }, { "choices": [], "defaultChoice": null, "internalName": "ID", "isExcluded": false, "isReadOnly": true, "isRequired": false, "isStaffOnly": false, "lsInternal": false, "isInternal": false, "label": "ID", "type": "Counter", "value": "2", "guid": "1d22ea11-1e32-424e-89ab-9fedbadb6ce1", "description": "", "displayFormat": null } ] }, { "Properties": [ { "choices": [], "defaultChoice": "", "internalName": "Title", "isExcluded": false, "isReadOnly": false, "isRequired": true, "isStaffOnly": false, "lsInternal": false, "isInternal": false, "label": "Request Name", "type": "Text", "value": "test-20091102-1", "guid": "fa564e0f-0c70-4ab9-b863-0177e6ddd247", "description": "", "displayFormat": null }, { "choices": [ "Submitted", "Received", "QC Completed", "Approved", "Processing", "PickUp", "Completed", "ReadyToBill", "Billed", "Cancelled" ], "defaultChoice": "Submitted", "internalName": "Status", "isExcluded": true, "isReadOnly": false, "isRequired": false, "isStaffOnly": false, "lsInternal": false, "isInternal": false, "label": "Status", "type": "Choice", "value": "Processing", "guid": "49309a1a-c6be-49b8-91e5-5211aad1098a", "description": "", "displayFormat": null }, { "choices": [], "defaultChoice": null, "internalName": "ID", "isExcluded": false, "isReadOnly": true, "isRequired": false, "isStaffOnly": false, "lsInternal": false, "isInternal": false, "label": "ID", "type": "Counter", "value": "3", "guid": "1d22ea11-1e32-424e-89ab-9fedbadb6ce1", "description": "", "displayFormat": null } ] } ] }; expect(response).to.eql(item.items); }); }); describe('getOne()', () => { const item = { data: { "ID" : 1, "Properties": [], "relatedItems": [ { "listName": "testList", "items": [ { "ID": 1, "Properties": [ { "choices": [], "defaultChoice": "", "internalName": "Title", "isExcluded": false, "isReadOnly": false, "isRequired": true, "isStaffOnly": false, "lsInternal": false, "isInternal": false, "label": "Request Name", "type": "Text", "value": "test-20091102-1", "guid": "fa564e0f-0c70-4ab9-b863-0177e6ddd247", "description": "", "displayFormat": null }, { "choices": [ "Submitted", "Received", "QC Completed", "Approved", "Processing", "PickUp", "Completed", "ReadyToBill", "Billed", "Cancelled" ], "defaultChoice": "Submitted", "internalName": "Status", "isExcluded": true, "isReadOnly": false, "isRequired": false, "isStaffOnly": false, "lsInternal": false, "isInternal": false, "label": "Status", "type": "Choice", "value": "Processing", "guid": "49309a1a-c6be-49b8-91e5-5211aad1098a", "description": "", "displayFormat": null }, { "choices": [], "defaultChoice": null, "internalName": "ID", "isExcluded": false, "isReadOnly": true, "isRequired": false, "isStaffOnly": false, "lsInternal": false, "isInternal": false, "label": "ID", "type": "Counter", "value": "1", "guid": "1d22ea11-1e32-424e-89ab-9fedbadb6ce1", "description": "", "displayFormat": null } ] }, { "ID": 2, "Properties": [ { "choices": [], "defaultChoice": "", "internalName": "Title", "isExcluded": false, "isReadOnly": false, "isRequired": true, "isStaffOnly": false, "lsInternal": false, "isInternal": false, "label": "Request Name", "type": "Text", "value": "test-20091102-1", "guid": "fa564e0f-0c70-4ab9-b863-0177e6ddd247", "description": "", "displayFormat": null }, { "choices": [ "Submitted", "Received", "QC Completed", "Approved", "Processing", "PickUp", "Completed", "ReadyToBill", "Billed", "Cancelled" ], "defaultChoice": "Submitted", "internalName": "Status", "isExcluded": true, "isReadOnly": false, "isRequired": false, "isStaffOnly": false, "lsInternal": false, "isInternal": false, "label": "Status", "type": "Choice", "value": "Processing", "guid": "49309a1a-c6be-49b8-91e5-5211aad1098a", "description": "", "displayFormat": null }, { "choices": [], "defaultChoice": null, "internalName": "ID", "isExcluded": false, "isReadOnly": true, "isRequired": false, "isStaffOnly": false, "lsInternal": false, "isInternal": false, "label": "ID", "type": "Counter", "value": "2", "guid": "1d22ea11-1e32-424e-89ab-9fedbadb6ce1", "description": "", "displayFormat": null } ] }, { "ID": 3, "Properties": [ { "choices": [], "defaultChoice": "", "internalName": "Title", "isExcluded": false, "isReadOnly": false, "isRequired": true, "isStaffOnly": false, "lsInternal": false, "isInternal": false, "label": "Request Name", "type": "Text", "value": "test-20091102-1", "guid": "fa564e0f-0c70-4ab9-b863-0177e6ddd247", "description": "", "displayFormat": null }, { "choices": [ "Submitted", "Received", "QC Completed", "Approved", "Processing", "PickUp", "Completed", "ReadyToBill", "Billed", "Cancelled" ], "defaultChoice": "Submitted", "internalName": "Status", "isExcluded": true, "isReadOnly": false, "isRequired": false, "isStaffOnly": false, "lsInternal": false, "isInternal": false, "label": "Status", "type": "Choice", "value": "Processing", "guid": "49309a1a-c6be-49b8-91e5-5211aad1098a", "description": "", "displayFormat": null }, { "choices": [], "defaultChoice": null, "internalName": "ID", "isExcluded": false, "isReadOnly": true, "isRequired": false, "isStaffOnly": false, "lsInternal": false, "isInternal": false, "label": "ID", "type": "Counter", "value": "3", "guid": "1d22ea11-1e32-424e-89ab-9fedbadb6ce1", "description": "", "displayFormat": null } ] } ]} ]} }; let response; beforeEach(() => { requests.getOne = sinon.stub().resolves(item.data); }); beforeEach(async () => { response = await requests.getOne(1); }); it('should call request.getOne() method with expected arguments', async () => { expect(requests.getOne.firstCall.args).to.eql([1]); }); it('should return an object with array of data model', async () => { const item = { data: { "ID" : 1, "Properties": [], "relatedItems": [ { "listName": "testList", "items": [ { "ID": 1, "Properties": [ { "choices": [], "defaultChoice": "", "internalName": "Title", "isExcluded": false, "isReadOnly": false, "isRequired": true, "isStaffOnly": false, "lsInternal": false, "isInternal": false, "label": "Request Name", "type": "Text", "value": "test-20091102-1", "guid": "fa564e0f-0c70-4ab9-b863-0177e6ddd247", "description": "", "displayFormat": null }, { "choices": [ "Submitted", "Received", "QC Completed", "Approved", "Processing", "PickUp", "Completed", "ReadyToBill", "Billed", "Cancelled" ], "defaultChoice": "Submitted", "internalName": "Status", "isExcluded": true, "isReadOnly": false, "isRequired": false, "isStaffOnly": false, "lsInternal": false, "isInternal": false, "label": "Status", "type": "Choice", "value": "Processing", "guid": "49309a1a-c6be-49b8-91e5-5211aad1098a", "description": "", "displayFormat": null }, { "choices": [], "defaultChoice": null, "internalName": "ID", "isExcluded": false, "isReadOnly": true, "isRequired": false, "isStaffOnly": false, "lsInternal": false, "isInternal": false, "label": "ID", "type": "Counter", "value": "1", "guid": "1d22ea11-1e32-424e-89ab-9fedbadb6ce1", "description": "", "displayFormat": null } ] }, { "ID": 2, "Properties": [ { "choices": [], "defaultChoice": "", "internalName": "Title", "isExcluded": false, "isReadOnly": false, "isRequired": true, "isStaffOnly": false, "lsInternal": false, "isInternal": false, "label": "Request Name", "type": "Text", "value": "test-20091102-1", "guid": "fa564e0f-0c70-4ab9-b863-0177e6ddd247", "description": "", "displayFormat": null }, { "choices": [ "Submitted", "Received", "QC Completed", "Approved", "Processing", "PickUp", "Completed", "ReadyToBill", "Billed", "Cancelled" ], "defaultChoice": "Submitted", "internalName": "Status", "isExcluded": true, "isReadOnly": false, "isRequired": false, "isStaffOnly": false, "lsInternal": false, "isInternal": false, "label": "Status", "type": "Choice", "value": "Processing", "guid": "49309a1a-c6be-49b8-91e5-5211aad1098a", "description": "", "displayFormat": null }, { "choices": [], "defaultChoice": null, "internalName": "ID", "isExcluded": false, "isReadOnly": true, "isRequired": false, "isStaffOnly": false, "lsInternal": false, "isInternal": false, "label": "ID", "type": "Counter", "value": "2", "guid": "1d22ea11-1e32-424e-89ab-9fedbadb6ce1", "description": "", "displayFormat": null } ] }, { "ID": 3, "Properties": [ { "choices": [], "defaultChoice": "", "internalName": "Title", "isExcluded": false, "isReadOnly": false, "isRequired": true, "isStaffOnly": false, "lsInternal": false, "isInternal": false, "label": "Request Name", "type": "Text", "value": "test-20091102-1", "guid": "fa564e0f-0c70-4ab9-b863-0177e6ddd247", "description": "", "displayFormat": null }, { "choices": [ "Submitted", "Received", "QC Completed", "Approved", "Processing", "PickUp", "Completed", "ReadyToBill", "Billed", "Cancelled" ], "defaultChoice": "Submitted", "internalName": "Status", "isExcluded": true, "isReadOnly": false, "isRequired": false, "isStaffOnly": false, "lsInternal": false, "isInternal": false, "label": "Status", "type": "Choice", "value": "Processing", "guid": "49309a1a-c6be-49b8-91e5-5211aad1098a", "description": "", "displayFormat": null }, { "choices": [], "defaultChoice": null, "internalName": "ID", "isExcluded": false, "isReadOnly": true, "isRequired": false, "isStaffOnly": false, "lsInternal": false, "isInternal": false, "label": "ID", "type": "Counter", "value": "3", "guid": "1d22ea11-1e32-424e-89ab-9fedbadb6ce1", "description": "", "displayFormat": null } ] } ]} ]} }; expect(response).to.eql(item.data); }); }); });