UNPKG

@riturajgc/upload-manager-service

Version:

Upload manager service for bitnudge

38 lines (34 loc) 1.94 kB
const { expect } = require('chai'); const sinon = require('sinon'); const { Storage } = require('./../../index.js'); const App = new Storage(1); App.setMongoose({ dbURL: 'mongodb://localhost/bitnudge-upload-document-test-string' }); describe.only('Adapter', () => { describe('fetchDocument', () => { it('case-1: should return data if all the required input paramter is correct', async () => { expect(App.adapter.statusChange).to.be.exist; }); it('case-2: should return data if all the required input paramter is correct', async () => { const uploadManagerData = sinon.stub(App.adapter.type.model, 'update').resolves({ n:1 }); const result = await App.adapter.statusChange({fileId: "5b4c424d669a91104ad6eb7e", status: "5b4c424d669a91104ad6eb7e"}); uploadManagerData.restore(); expect(result.status).to.be.true; expect(uploadManagerData.calledOnce).to.be.true; }); it('case-3: should return false if all the required input paramter are not given', async () => { const result = await App.adapter.statusChange({fileId: "5b4c424d669a91104ad6eb7e"}); expect(result.status).to.be.false; expect(result.message).to.contain("Please provide all the fields"); }); it('case-4: should return false if any error happens', async () => { let uploadManagerData = sinon.stub(App.adapter.type.model,'update').rejects("check"); const result = await App.adapter.statusChange({fileId: "5b4c424d669a91104ad6eb7e", status: "5b4c424d669a91104ad6eb7e"}); uploadManagerData.restore(); expect(result.status).to.be.false; expect(uploadManagerData.calledOnce).to.be.true; expect(result.message).equal("There is some problem, please try after some time"); }); }) });