Skip to content

Commit

Permalink
refactor(test): place hooks in separate files
Browse files Browse the repository at this point in the history
- Did this as best practice since I was repeating same code in multiple files
  • Loading branch information
chidimo committed May 29, 2019
1 parent ddb2e62 commit 0403309
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 30 deletions.
2 changes: 1 addition & 1 deletion UI/js/common/user_card_address.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ const home = document.getElementById('home');
const office = document.getElementById('office');

home.textContent = address.home;
office.textContent = address.office;
office.textContent = address.office;
2 changes: 1 addition & 1 deletion UI/js/common/user_loans.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ for (const [ i, loan ] of user_loans.entries()) {
</tr>
`;
table_ref.insertRow(-1).innerHTML = data;
}
}
7 changes: 7 additions & 0 deletions test/after.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { test_logger } from '../utils/loggers';
import { clearDB } from '../utils/localDbOps';

after(async () => {
test_logger('Clearing DB');
await clearDB();
});
3 changes: 3 additions & 0 deletions test/afterEach.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import sinon from 'sinon';

afterEach(() => sinon.restore());
7 changes: 7 additions & 0 deletions test/before.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { test_logger } from '../utils/loggers';
import { createDB } from '../utils/localDbOps';

before(async () => {
test_logger('Creating DB');
await createDB();
});
18 changes: 2 additions & 16 deletions test/loans-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,14 @@ import sinonChai from 'sinon-chai';

import app from '../app';
import LoansController, { loans_model } from '../controllers/LoansController';
import { test_logger } from '../utils/loggers';
import { createDB, clearDB } from '../utils/localDbOps';

chai.use(sinonChai);
const { expect } = chai;


const server = supertest.agent(app);
const BASE_URL = '/api/v1';

describe('/loans', () => {
before(async () => {
test_logger('Creating DB in loans-spec');
await createDB();
});

after(async () => {
test_logger('Clearing DB in loans-spec');
await clearDB();
});

afterEach(() => sinon.restore());

describe('/loans: Get all loans', () => {
it('should be return a list of all loans', done => {
Expand Down Expand Up @@ -75,8 +61,8 @@ describe('/loans', () => {
res.status.should.equal(200);
res.body.data.should.be.an.instanceOf(Array);
for (const loan of res.body.data) {
assert(loan.status === 'approved');
assert(loan.repaid === true);
loan.should.have.property('status', 'approved');
loan.should.have.property('repaid', true);
}
done();
});
Expand Down
12 changes: 0 additions & 12 deletions test/users-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,12 @@

import supertest from 'supertest';
import app from '../app';
import { test_logger } from '../utils/loggers';
import { createDB, clearDB } from '../utils/localDbOps';

const server = supertest.agent(app);
const BASE_URL = '/api/v1';

describe('/users', () => {

before(async () => {
test_logger('Creating DB in users-spec');
await createDB();
});

after(async () => {
test_logger('Clearing DB in users-spec');
await clearDB();
});

describe('/auth/signup', () => {
describe('POST /auth/signup', () => {
it('should return invalid email error', done => {
Expand Down

0 comments on commit 0403309

Please sign in to comment.