Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions __test__/routes/expenses/insertReminder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const chai = require('chai')
const sinon = require('sinon');
const spies = require('chai-spies');

const db = require('../../../db');
const { Reminder } = require('../../../db');
const insertReminder = require('../../../routes/expenses/insertReminder');

chai.use(spies);
Expand All @@ -25,7 +25,7 @@ describe('insertReminder', () => {

it('calls create with the right parameters', async () => {
const callback = chai.spy(() => Promise.resolve(true));
const stub = sinon.stub(db.reminder, 'create').callsFake(callback);
const stub = sinon.stub(Reminder, 'create').callsFake(callback);

await insertReminder(
{ body: { user: 'foo', det: 'bar', amt: 1, dat: 'today' }},
Expand All @@ -41,7 +41,7 @@ describe('insertReminder', () => {
it('response is still sent if errors are thrown', async () => {
const error = new Error();
const callback = chai.spy(() => { throw error; });
const stub = sinon.stub(db.reminder, 'create').callsFake(callback);
const stub = sinon.stub(Reminder, 'create').callsFake(callback);

await insertReminder(
{ body: { user: 'foo', det: 'bar', amt: 1, dat: 'today' }},
Expand Down
6 changes: 3 additions & 3 deletions __test__/routes/expenses/investmentOverview.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const chai = require('chai')
const sinon = require('sinon');
const spies = require('chai-spies');

const db = require('../../../db');
const { Investment } = require('../../../db');
const investmentOverview = require('../../../routes/expenses/investmentOverview');

chai.use(spies);
Expand All @@ -26,7 +26,7 @@ describe('investmentOverview', () => {
it('calls create with the right parameters', async () => {
const result = 'bar';
const callback = chai.spy(() => result);
const stub = sinon.stub(db.investment, 'findAll').callsFake(callback);
const stub = sinon.stub(Investment, 'findAll').callsFake(callback);

await investmentOverview(
{ body: { user: 'foo' }},
Expand All @@ -43,7 +43,7 @@ describe('investmentOverview', () => {
it('response is still sent if errors are thrown', async () => {
const error = new Error();
const callback = chai.spy(() => { throw error; });
const stub = sinon.stub(db.investment, 'findAll').callsFake(callback);
const stub = sinon.stub(Investment, 'findAll').callsFake(callback);

await investmentOverview(
{ body: { user: 'foo' }},
Expand Down
6 changes: 3 additions & 3 deletions __test__/routes/expenses/investments.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const chai = require('chai')
const sinon = require('sinon');
const spies = require('chai-spies');

const db = require('../../../db');
const { Investment } = require('../../../db');
const investments = require('../../../routes/expenses/investments');

chai.use(spies);
Expand All @@ -26,7 +26,7 @@ describe('investments', () => {
it('calls create with the right parameters', async () => {
const result = ['bar'];
const callback = chai.spy(() => result);
const stub = sinon.stub(db.investment, 'findAll').callsFake(callback);
const stub = sinon.stub(Investment, 'findAll').callsFake(callback);

await investments(
{ body: { user: 'foo' }},
Expand All @@ -42,7 +42,7 @@ describe('investments', () => {
it('response is still sent if errors are thrown', async () => {
const error = new Error();
const callback = chai.spy(() => { throw error; });
const stub = sinon.stub(db.investment, 'findAll').callsFake(callback);
const stub = sinon.stub(Investment, 'findAll').callsFake(callback);

await investments(
{ body: { user: 'foo' }},
Expand Down
6 changes: 3 additions & 3 deletions __test__/routes/expenses/reminders.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const chai = require('chai')
const sinon = require('sinon');
const spies = require('chai-spies');

const db = require('../../../db');
const { Reminder } = require('../../../db');
const reminders = require('../../../routes/expenses/reminders');

chai.use(spies);
Expand All @@ -26,7 +26,7 @@ describe('reminders', () => {
it('calls create with the right parameters', async () => {
const result = ['bar'];
const callback = chai.spy(() => result);
const stub = sinon.stub(db.reminder, 'findAll').callsFake(callback);
const stub = sinon.stub(Reminder, 'findAll').callsFake(callback);

await reminders(
{ body: { user: 'foo' }},
Expand All @@ -42,7 +42,7 @@ describe('reminders', () => {
it('response is still sent if errors are thrown', async () => {
const error = new Error();
const callback = chai.spy(() => { throw error; });
const stub = sinon.stub(db.reminder, 'findAll').callsFake(callback);
const stub = sinon.stub(Reminder, 'findAll').callsFake(callback);

await reminders(
{ body: { user: 'foo' }},
Expand Down
6 changes: 3 additions & 3 deletions __test__/routes/expenses/spendingOverview.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const chai = require('chai')
const sinon = require('sinon');
const spies = require('chai-spies');

const db = require('../../../db');
const { Spendings } = require('../../../db');
const spendingOverview = require('../../../routes/expenses/spendingOverview');

chai.use(spies);
Expand All @@ -26,7 +26,7 @@ describe('spendingOverview', () => {
it('calls create with the right parameters', async () => {
const result = ['bar'];
const callback = chai.spy(() => result);
const stub = sinon.stub(db.spendings, 'findAll').callsFake(callback);
const stub = sinon.stub(Spendings, 'findAll').callsFake(callback);

await spendingOverview(
{ body: { user: 'foo' }},
Expand All @@ -42,7 +42,7 @@ describe('spendingOverview', () => {
it('response is still sent if errors are thrown', async () => {
const error = new Error();
const callback = chai.spy(() => { throw error; });
const stub = sinon.stub(db.spendings, 'findAll').callsFake(callback);
const stub = sinon.stub(Spendings, 'findAll').callsFake(callback);

await spendingOverview(
{ body: { user: 'foo' }},
Expand Down
6 changes: 3 additions & 3 deletions __test__/routes/expenses/spendings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const chai = require('chai')
const sinon = require('sinon');
const spies = require('chai-spies');

const db = require('../../../db');
const { Spendings } = require('../../../db');
const spendings = require('../../../routes/expenses/spendings');

chai.use(spies);
Expand All @@ -26,7 +26,7 @@ describe('spendings', () => {
it('calls create with the right parameters', async () => {
const result = ['bar'];
const callback = chai.spy(() => result);
const stub = sinon.stub(db.spendings, 'findAll').callsFake(callback);
const stub = sinon.stub(Spendings, 'findAll').callsFake(callback);

await spendings(
{ body: { user: 'foo' }},
Expand All @@ -42,7 +42,7 @@ describe('spendings', () => {
it('response is still sent if errors are thrown', async () => {
const error = new Error();
const callback = chai.spy(() => { throw error; });
const stub = sinon.stub(db.spendings, 'findAll').callsFake(callback);
const stub = sinon.stub(Spendings, 'findAll').callsFake(callback);

await spendings(
{ body: { user: 'foo' }},
Expand Down
10 changes: 5 additions & 5 deletions __test__/routes/expenses/transaction.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const chai = require('chai')
const sinon = require('sinon');
const spies = require('chai-spies');

const db = require('../../../db');
const { Spendings, Investment } = require('../../../db');
const transaction = require('../../../routes/expenses/transaction');

chai.use(spies);
Expand All @@ -26,8 +26,8 @@ describe('transaction', () => {
it('queries the right place ont the db (spending)', async () => {
const spy_spendings = chai.spy();
const spy_investment = chai.spy();
const stub_spendings = sinon.stub(db.spendings, 'create').callsFake(spy_spendings);
const stub_investment = sinon.stub(db.investment, 'create').callsFake(spy_investment);
const stub_spendings = sinon.stub(Spendings, 'create').callsFake(spy_spendings);
const stub_investment = sinon.stub(Investment, 'create').callsFake(spy_investment);

await transaction(
{ body: { type: 'Spending' }},
Expand All @@ -45,8 +45,8 @@ describe('transaction', () => {
it('queries the right place ont the db (Investment)', async () => {
const spy_spendings = chai.spy();
const spy_investment = chai.spy();
const stub_spendings = sinon.stub(db.spendings, 'create').callsFake(spy_spendings);
const stub_investment = sinon.stub(db.investment, 'create').callsFake(spy_investment);
const stub_spendings = sinon.stub(Spendings, 'create').callsFake(spy_spendings);
const stub_investment = sinon.stub(Investment, 'create').callsFake(spy_investment);

await transaction(
{ body: { type: 'Investment' }},
Expand Down
56 changes: 28 additions & 28 deletions db.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const Sequelize = require('sequelize');
const Sequelize = require("sequelize");

require('dotenv').config({ path: `${process.cwd()}/.env.example` });
require("dotenv").config({ path: `${process.cwd()}/.env.example` });

/**
* @description database tables using Sequelize
Expand All @@ -11,111 +11,111 @@ const db = new Sequelize({
database: process.env.DB_DATABASE,
password: process.env.DB_PASSWORD,
port: process.env.PORT,
dialect: 'mysql',
dialect: "mysql"
});

/**
* @description table name: credit , elements:mode, detail, amount
*/
const credit = db.define('credit', {
const Credit = db.define("credit", {
id: {
type: Sequelize.DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
autoIncrement: true
},
mode: Sequelize.DataTypes.STRING,
detail: Sequelize.DataTypes.BOOLEAN,
amount: Sequelize.DataTypes.INTEGER,
amount: Sequelize.DataTypes.INTEGER
});

/**
* @description table name: user , elements:username, email, pass, name, mob, budget
*/
const user = db.define('user', {
const User = db.define("user", {
id: {
type: Sequelize.DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
autoIncrement: true
},
username: Sequelize.DataTypes.STRING,
email: Sequelize.DataTypes.STRING,
password: Sequelize.DataTypes.STRING,
name: Sequelize.DataTypes.STRING,
mobile: Sequelize.DataTypes.STRING,
Budget: Sequelize.DataTypes.INTEGER,
Budget: Sequelize.DataTypes.INTEGER
});

/**
* @description table name: spendings , elements:user, detail, amount, Mode
*/
const spendings = db.define('spendings', {
const Spendings = db.define("spendings", {
id: {
type: Sequelize.DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
autoIncrement: true
},
user: Sequelize.DataTypes.STRING,
detail: Sequelize.DataTypes.STRING,
amount: Sequelize.DataTypes.INTEGER,
Mode: Sequelize.DataTypes.STRING,
Mode: Sequelize.DataTypes.STRING
});

/**
* @description table name: investment , elements:user, detail, amount, Mode
*/
const investment = db.define('investment', {
const Investment = db.define("investment", {
id: {
type: Sequelize.DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
autoIncrement: true
},
user: Sequelize.DataTypes.STRING,
detail: Sequelize.DataTypes.STRING,
amount: Sequelize.DataTypes.INTEGER,
Mode: Sequelize.DataTypes.STRING,
Mode: Sequelize.DataTypes.STRING
});

/**
* @description table name: reminder , elements:user, detail, amount, date
*/
const reminder = db.define('reminders', {
const Reminder = db.define("reminders", {
id: {
type: Sequelize.DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
autoIncrement: true
},
user: Sequelize.DataTypes.STRING,
detail: Sequelize.DataTypes.STRING,
amount: Sequelize.DataTypes.INTEGER,
date: Sequelize.DataTypes.STRING,
date: Sequelize.DataTypes.STRING
});

/**
* @description table name: transaction , elements:user, detail, amount, date, type
*/
const transaction = db.define('transaction', {
const Transaction = db.define("transaction", {
id: {
type: Sequelize.DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
autoIncrement: true
},
user: Sequelize.DataTypes.STRING,
detail: Sequelize.DataTypes.STRING,
amount: Sequelize.DataTypes.INTEGER,
date: Sequelize.DataTypes.STRING,
type: Sequelize.DataTypes.STRING,
Mode: Sequelize.DataTypes.STRING,
Mode: Sequelize.DataTypes.STRING
});

db.sync().then(function() {
console.log('Database is ready');
console.log("Database is ready");
});

module.exports = {
user,
spendings,
credit,
reminder,
investment,
transaction,
User,
Spendings,
Credit,
Reminder,
Investment,
Transaction
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"mysql2": "^1.4.2",
"passport": "^0.4.0",
"passport-local": "^1.0.0",
"passport-google-oauth": "^2.0.0",
"sequelize": "^5.15.1",
"socket.io": "^2.0.4"
},
Expand All @@ -62,7 +63,6 @@
"husky": "^4.2.5",
"lint-staged": "^10.1.4",
"mocha": "^6.2.1",
"passport-google-oauth": "^2.0.0",
"prettier": "^1.16.4",
"sinon": "^7.5.0"
}
Expand Down
15 changes: 8 additions & 7 deletions routes/expenses/insertReminder.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
// looks good so far so good
const { reminder } = require('../../db');
const { Reminder } = require("../../db");

// this looks good
const insertReminder = async (req, res) => {
try {
await reminder.create({
user: req.body.user,
detail: req.body.det,
amount: req.body.amt,
date: req.body.dat,
const { user, det, amt, dat } = req.body;
await Reminder.create({
user,
detail: det,
amount: amt,
date: dat
});
res.send({ status: true });
} catch (err) {
console.log('err');
console.log("err");
res.send(err);
}
};
Expand Down
Loading