Skip to content

Commit

Permalink
test(seed): improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
rijkerd committed Jan 31, 2020
1 parent d02a516 commit 89eec77
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
11 changes: 11 additions & 0 deletions test/integration/seed.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,17 @@ describe('seed', () => {
});
});

it.skip('should not seed from seeds file if throws is true', done => {
const modelName = MODEL_NAME_PREDEFINE;
const optns = { modelName, throws: true };

seedFromSeeds(optns, (error, results) => {
expect(error).to.exist;
expect(results).to.be.undefined;
done();
});
});

it('should seed predefines', done => {
seedPredefine({}, error => {
expect(error).to.not.exist;
Expand Down
54 changes: 54 additions & 0 deletions test/unit/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import {
transformSeedKeys,
applyTransformsOn,
transformToPredefineSeed,
seedFromCsv,
seedFromJson,
seedFromSeeds,
} from '../../src';

describe('process csv file', () => {
Expand Down Expand Up @@ -77,6 +80,57 @@ describe('process csv file', () => {
});
});

describe('seed from csv', () => {
it('should call done if model does not exist', () => {
const done = fake();
const option = { modelName: undefined };
seedFromCsv(option, done);
expect(done).to.be.called;
});
});

describe('seed from json', () => {
it('should call done if model does not exist', () => {
const done = fake();
const option = { modelName: undefined };
seedFromJson(option, done);
expect(done).to.be.called;
});
});

describe('seed from seeds', () => {
it('should call done if model does not exist', () => {
const done = fake();
const option = {};
seedFromSeeds(option, done);
expect(done).to.be.called;
});

it('should call done with error and result if throws is true', () => {
const error = new Error();
const Model = { modelName: 'TEST' };
const results = {};
const done = fake();
Model.seed = fake();

Model.seed({ throws: true }, done(error, results));
expect(error).to.exist;
expect(done).to.be.calledWith(error, results);
});

it('should call done with result if throws is false', () => {
const error = null;
const Model = { modelName: 'TEST' };
const results = {};
const done = fake();
Model.seed = fake();

Model.seed({ throws: false }, done(error, results));
expect(error).to.not.exist;
expect(done).to.be.calledWith(null, results);
});
});

describe('common', () => {
const { BASE_PATH, DATA_PATH, SEED_PATH } = process.env;

Expand Down

0 comments on commit 89eec77

Please sign in to comment.