-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d0455c0
commit 1f9391a
Showing
5 changed files
with
147 additions
and
85 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
const fs = require('fs'); | ||
const db_connection = require('./db_connection'); | ||
const fs = require("fs"); | ||
const db_connection = require("./db_connection"); | ||
|
||
const sql = fs.readFileSync(`${__dirname}/db_build.sql`).toString(); | ||
|
||
const runDbBuild = cb => { | ||
db_connection.query(sql, (err, res) => { | ||
if (err) return err; | ||
console.log(res); | ||
}); | ||
} | ||
db_connection.query(sql, (err, res) => { | ||
if (err) { | ||
cb(err, null); | ||
} else { | ||
cb(null, res); | ||
} | ||
}); | ||
}; | ||
|
||
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 |
---|---|---|
@@ -1,44 +1,44 @@ | ||
{ | ||
"name": "semn", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"dependencies": { | ||
"body-parser": "^1.18.3", | ||
"codecov": "^3.0.4", | ||
"dot-env": "^0.0.1", | ||
"env2": "^2.2.2", | ||
"eslint": "^5.4.0", | ||
"handlebars": "^4.0.11", | ||
"compression": "^1.7.3", | ||
"express": "^4.16.3", | ||
"express-handlebars": "^3.0.0", | ||
"helmet": "^3.13.0", | ||
"pg": "^7.4.3" | ||
}, | ||
"devDependencies": { | ||
"nodemon": "^1.18.3", | ||
"nyc": "^12.0.2", | ||
"supertest": "^3.1.0", | ||
"tap-spec": "^5.0.0", | ||
"tape": "^4.9.1", | ||
"eslint": "^5.4.0" | ||
}, | ||
"scripts": { | ||
"db": "NODE_ENV=test node database/db_build.js", | ||
"dev": "nodemon src/app.js", | ||
"start": "node src/app.js", | ||
"test": "NODE_ENV=test nyc tape ./tests/*.js | tap-spec", | ||
"coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/sunuwars/SEMN.git" | ||
}, | ||
"author": "Sangita, Emily, Nathalie and Martin", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/sunuwars/SEMN/issues" | ||
}, | ||
"homepage": "https://github.com/sunuwars/SEMN#readme" | ||
"name": "semn", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"dependencies": { | ||
"body-parser": "^1.18.3", | ||
"codecov": "^3.0.4", | ||
"dot-env": "^0.0.1", | ||
"env2": "^2.2.2", | ||
"eslint": "^5.4.0", | ||
"handlebars": "^4.0.11", | ||
"compression": "^1.7.3", | ||
"express": "^4.16.3", | ||
"express-handlebars": "^3.0.0", | ||
"helmet": "^3.13.0", | ||
"pg": "^7.4.3" | ||
}, | ||
"devDependencies": { | ||
"nodemon": "^1.18.3", | ||
"nyc": "^12.0.2", | ||
"supertest": "^3.1.0", | ||
"tap-spec": "^5.0.0", | ||
"tape": "^4.9.1", | ||
"eslint": "^5.4.0" | ||
}, | ||
"scripts": { | ||
"db": "NODE_ENV=test node database/db_build.js", | ||
"dev": "nodemon src/app.js", | ||
"start": "node src/app.js", | ||
"test": "NODE_ENV=test nyc tape ./test/*.js | tap-spec", | ||
"coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/sunuwars/SEMN.git" | ||
}, | ||
"author": "Sangita, Emily, Nathalie and Martin", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/sunuwars/SEMN/issues" | ||
}, | ||
"homepage": "https://github.com/sunuwars/SEMN#readme" | ||
} |
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 |
---|---|---|
@@ -1,38 +1,46 @@ | ||
const db = require('./../../database/dbConnection'); | ||
const db = require("../../../database/db_connection"); | ||
|
||
const dbQuery = { | ||
// log in | ||
getFacster: function() { | ||
let query = 'SELECT * FROM users WHERE "username" = $1'; | ||
db.query(query, (err, res) => { | ||
if (err) { | ||
cb("Error!", null); | ||
} | ||
cb(null, res); | ||
}); | ||
}, | ||
// log in | ||
getFacster: (username, cb) => { | ||
let query = `SELECT * FROM users WHERE username = '${username}'`; | ||
db.query(query, (err, res) => { | ||
if (err) { | ||
cb("Error!", null); | ||
} else if (res.rowCount === 0) { | ||
cb(true, null); | ||
} else { | ||
cb(null, res); | ||
} | ||
}); | ||
}, | ||
|
||
// sign in | ||
postFacster: function() { | ||
let query = 'INSERT INTO users (username, first_name, last_name, bio, cohort, picture, github, password) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)'; | ||
db.query(query, [username, first_name, last_name, bio, cohort, picture, github, password] (err, res) => { | ||
if (err) { | ||
cb("Error!", null); | ||
} | ||
cb(null, res); | ||
}); | ||
}, | ||
// sign in | ||
postFacster: (user, cb) => { | ||
let query = `INSERT INTO users (username, first_name, last_name, bio, cohort, picture, github, password) VALUES ('${ | ||
user.username | ||
}', '${user.first_name}', '${user.last_name}', '${user.bio}', '${ | ||
user.cohort | ||
}', '${user.picture}', '${user.github}', '${user.password}')`; | ||
db.query(query, (err, res) => { | ||
if (err) { | ||
cb("Error!", null); | ||
} else if (res.rowCount === 1) { | ||
cb(null, res); | ||
} | ||
}); | ||
}, | ||
|
||
checkAuth: function() { | ||
let query = 'SELECT password FROM users WHERE "username" = $1'; | ||
db.query(query, (err, res) => { | ||
if (err) { | ||
cb("Error!", null); | ||
} | ||
cb(null, res); | ||
}); | ||
} | ||
|
||
} | ||
checkAuth: (user, cb) => { | ||
let query = `SELECT password FROM users WHERE username = '${user}'`; | ||
db.query(query, (err, res) => { | ||
if (err) { | ||
cb("Error!", null); | ||
} else { | ||
cb(null, res.rows[0].password); | ||
} | ||
}); | ||
} | ||
}; | ||
|
||
module.exports = dbQuery; |
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 |
---|---|---|
@@ -1,3 +1,54 @@ | ||
const test = require(tape); | ||
const runDbBuild = require('./database/db_build.js'); | ||
const queries = require('./src/model/queries/') | ||
const test = require("tape"); | ||
const runDbBuild = require("../database/db_build"); | ||
const queries = require("../src/model/queries/queries"); | ||
|
||
test("Tape is working", t => { | ||
t.equal(Math.sqrt(9), 3, "Square root of 9 is 3"); | ||
t.end(); | ||
}); | ||
|
||
test("getFacster can find and return Emily", t => { | ||
queries.getFacster("apple", (err, res) => { | ||
const actual = res.rows[0].first_name; | ||
t.deepEquals(actual, "Emily", "Emily returned on query"); | ||
t.end(); | ||
}); | ||
}); | ||
|
||
test("Steve is not a user - returns false", t => { | ||
queries.getFacster("Steve", (err, res) => { | ||
const actual = err; | ||
t.equal(actual, true, "No result returns error"); | ||
t.end(); | ||
}); | ||
}); | ||
|
||
test("postFacster can add a user", t => { | ||
const user = { | ||
username: "pear", | ||
first_name: "Lies", | ||
last_name: "Fakeson", | ||
bio: "Not real", | ||
cohort: "1", | ||
picture: "dummy.png", | ||
github: "dummy", | ||
password: "$2a10hmsqmbvAqIt5QBM0.EQ7h.PnMOQ4c6yqGCB.o.AhQWfzjbLvp0JJS" | ||
}; | ||
queries.postFacster(user, (err, res) => { | ||
const actual = res.rowCount; | ||
t.equal(actual, 1, "Inserted new row"); | ||
t.end(); | ||
}); | ||
}); | ||
|
||
test("Auth query returns password", t => { | ||
queries.checkAuth("apple", (err, res) => { | ||
const actual = res; | ||
t.equal( | ||
actual, | ||
"$2a10hmsqmbvAqIt5QBM0.EQ7h.PnMOQ4c6yqGCB.o.AhQWfzjbLvp0JJS", | ||
"Password Returned" | ||
); | ||
t.end(); | ||
}); | ||
}); |