-
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 #19 from fac-17/Feature/database-tests
Feature/database tests
- Loading branch information
Showing
9 changed files
with
809 additions
and
6 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -8,4 +8,6 @@ const runDbBuild = cb => { | |
dbConnection.query(sql, cb); | ||
}; | ||
|
||
runDbBuild(); | ||
|
||
module.exports = runDbBuild; |
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 @@ | ||
|
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,19 @@ | ||
const dbConnection = require("../database/db_connection"); | ||
|
||
const getUsers = cb => { | ||
dbConnection.query("SELECT name FROM users ORDER BY id", (err, res) => { | ||
if (err) { | ||
cb(err); | ||
} else cb(null, res.rows); | ||
}); | ||
}; | ||
|
||
const getAnimals = cb => { | ||
dbConnection.query("SELECT name FROM animals ORDER BY id", (err, res) => { | ||
if (err) { | ||
cb(err); | ||
} else cb(null, res.rows); | ||
}); | ||
}; | ||
|
||
module.exports = { getUsers, getAnimals }; |
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,3 @@ | ||
module.exports = { | ||
getData: require("./getData.js") | ||
}; |
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,58 @@ | ||
const test = require("tape"); | ||
const runDbBuild = require("../model/database/build"); | ||
const queries = require("../model/queries"); | ||
|
||
test("Check table builds", t => { | ||
runDbBuild((err, res) => { | ||
t.error(err, "No error"); | ||
t.end(); | ||
}); | ||
}); | ||
|
||
test("Check getUsers function", t => { | ||
const users = [ | ||
{ name: "Gregor" }, | ||
{ name: "Andy" }, | ||
{ name: "Francesca" }, | ||
{ name: "Jack" } | ||
]; | ||
runDbBuild((err, res) => { | ||
t.error(err, "No error for DbBuild"); | ||
queries.getData.getUsers((err, data) => { | ||
t.error(err, "No error for getUsers"); | ||
t.deepEqual(users, data, "Correct names are returned"); | ||
t.end(); | ||
}); | ||
}); | ||
}); | ||
|
||
test("Check getAnimals function", t => { | ||
const animals = [ | ||
{ name: "Pig" }, | ||
{ name: "Goat" }, | ||
{ name: "Tiger" }, | ||
{ name: "Monkey" } | ||
]; | ||
|
||
runDbBuild((err, res) => { | ||
t.error(err, "No error for DbBuild"); | ||
queries.getData.getAnimals((err, data) => { | ||
t.error(err, "No error for getAnimals"); | ||
t.deepEqual(animals, data, "Correct animals are returned"); | ||
t.end(); | ||
}); | ||
}); | ||
}); | ||
|
||
test("Check return all adopted relationships", t => { | ||
const adoptions = "tbd"; | ||
|
||
runDbBuild((err, res) => { | ||
t.error(err, "No error for DbBuild"); | ||
queries.getData.getAdoptions((err, data) => { | ||
t.error(err, "No error for getAdoptions"); | ||
t.deepEqual(adoptions, data, "Correct adoptions are returned"); | ||
t.end(); | ||
}); | ||
}); | ||
}); |