Skip to content

Commit

Permalink
test: add checkMongoexportInstalled tests
Browse files Browse the repository at this point in the history
  • Loading branch information
euberdeveloper committed Jan 5, 2021
1 parent 6585d45 commit bb0cede
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 4 deletions.
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"@types/mocha": "^8.2.0",
"@types/module-alias": "^2.0.0",
"@types/mongodb": "^3.6.3",
"@types/proxyquire": "^1.3.28",
"@types/rimraf": "^3.0.0",
"@types/shelljs": "^0.8.8",
"@types/sinon": "^9.0.10",
Expand Down
38 changes: 38 additions & 0 deletions test/checkMongoexportInstalled/checkMongoexportInstalled.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { MongoexportNotInstalledError } from '@/errors';
import { checkMongoexportInstalled } from '@/utils/checkMongoexportInstalled';

import { expect } from 'chai';
import * as sinon from 'sinon';
import proxyquire from 'proxyquire';

export default function (): void {
describe('Test: checkMongoexportInstalled auxiliary function', function () {
it(`Should pass when mongoexport is installed`, function () {
const expected = true;
const fakeChecker = sinon.fake.returns(expected);
const proxyedModule = proxyquire('@/utils/checkMongoexportInstalled', {
'command-exists': {
sync: fakeChecker
}
});
const mockedCheckMongoexportInstalled: typeof checkMongoexportInstalled =
proxyedModule.checkMongoexportInstalled;
expect(mockedCheckMongoexportInstalled).to.not.throw();
expect(fakeChecker).to.have.been.calledOnceWithExactly('mongoexport');
});

it(`Should throw a MongoexportNotInstalledError error when mongoexport is not installed`, function () {
const expected = false;
const fakeChecker = sinon.fake.returns(expected);
const proxyedModule = proxyquire('@/utils/checkMongoexportInstalled', {
'command-exists': {
sync: fakeChecker
}
});
const mockedCheckMongoexportInstalled: typeof checkMongoexportInstalled =
proxyedModule.checkMongoexportInstalled;
expect(mockedCheckMongoexportInstalled).to.throw(MongoexportNotInstalledError);
expect(fakeChecker).to.have.been.calledOnceWithExactly('mongoexport');
});
});
}
10 changes: 6 additions & 4 deletions test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ import complete from '@test/complete/complete.test';
import errors from '@test/errors/errors.test';
import getCommand from '@test/getCommand/getCommand.test';
import getMongoConnection from '@test/getMongoConnection/getMongoConnection.test';
import checkMongoexportInstalled from '@test/checkMongoexportInstalled/checkMongoexportInstalled.test';

describe('MongoBack module tests', function () {
complete();
errors();
getCommand();
getMongoConnection();
// complete();
// errors();
// getCommand();
// getMongoConnection();
checkMongoexportInstalled();
});

2 comments on commit bb0cede

@vercel
Copy link

@vercel vercel bot commented on bb0cede Jan 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on bb0cede Jan 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.