-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from FAC-11/database-tests
Add database test and initial istanbul setup
- Loading branch information
Showing
4 changed files
with
107 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
const tape = require('tape'); | ||
const shot = require('shot'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const buildDataBase = require('../src/model/db_build'); | ||
const dbConnection = require('../src/model/db_connection'); | ||
const app = require('../src/app'); | ||
|
||
// Select all firstnames from users | ||
tape("Select all firstnames from users", t => { | ||
buildDataBase(); | ||
const expected = [ | ||
{ firstname: 'Abdullah'}, | ||
{ firstname: 'Max'}, | ||
{ firstname: 'Jen'}, | ||
{ firstname: 'Rebeca'} | ||
]; | ||
|
||
dbConnection.query('SELECT firstname FROM users;', (err, res) => { | ||
if (err) { | ||
t.error(err, 'This is an error'); | ||
} else { | ||
const actual = res.rows; | ||
t.deepEquals(actual, expected, 'db query should get firstnames'); | ||
t.end(); | ||
} | ||
}) | ||
}) | ||
|
||
// test ideas database | ||
tape("get idea titles from ideas database", t => { | ||
buildDataBase(); | ||
const expected = [ | ||
{ ideatitle: 'Movie recommendation app' }, | ||
{ ideatitle: 'travel giffy app' }, | ||
{ ideatitle: 'holiday inspiration app' }, | ||
{ ideatitle: 'mario cv app' } | ||
]; | ||
|
||
dbConnection.query('SELECT ideatitle FROM ideas;', (err, res) => { | ||
if (err) { | ||
t.error(err, 'This is an error'); | ||
} else { | ||
const actual = res.rows; | ||
t.deepEquals(actual, expected, 'db query should get titles'); | ||
t.end(); | ||
} | ||
}) | ||
}) | ||
|
||
tape("check if post adds a new user to user table", t => { | ||
buildDataBase(); | ||
const insertUserSql = "INSERT INTO users (firstname, email) VALUES ($1, $2)"; | ||
const expected = [ | ||
{ firstname: 'Amelie', email: '[email protected]'} | ||
]; | ||
|
||
dbConnection.query(insertUserSql, [expected[0].firstname, expected[0].email], (err, res) => { | ||
if (err) { | ||
t.error(err, 'This is an error'); | ||
} else { | ||
dbConnection.query("SELECT firstname, email FROM users WHERE firstname='Amelie';", | ||
(err, res) => { | ||
if (err) { | ||
t.error('This is an error'); | ||
} else { | ||
const actual = res.rows; | ||
t.deepEquals(actual, expected, 'firstname should be Amelie'); | ||
t.end(); | ||
} | ||
}) | ||
} | ||
}) | ||
}) | ||
|
||
|
||
|
||
|
||
// inserting a new idea | ||
// tape("check if a post adds a new idea to ideatable", t => { | ||
// buildDataBase(); | ||
// const insertNewIdeaSql = "INSERT INTO ideas (userid, dataadded, ideatitle, ideadesc) VALUES ($1, $2, $3, $4)"; | ||
// const expected = [ | ||
// { userid: 5, dataadded: 2017-08-17, } | ||
// ]; | ||
// | ||
// dbConnection.query('SELECT ideatitle FROM ideas;', (err, res) => { | ||
// if (err) { | ||
// t.error(err, 'This is an error'); | ||
// } else { | ||
// const actual = res.rows; | ||
// t.deepEquals(actual, expected, 'db query should get titles'); | ||
// t.end(); | ||
// } | ||
// }) | ||
// }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters