Skip to content
Snippets Groups Projects
Commit 937717fe authored by Jonas Kristoffersen's avatar Jonas Kristoffersen
Browse files

Endret persondao

parent 006d767c
No related branches found
No related tags found
No related merge requests found
Pipeline #22945 failed
......@@ -21,4 +21,22 @@ module.exports = class PersonDao extends Dao {
callback
);
}
updateOne(json, callback) {
var val = [json.navn, json.adresse, json.alder, json.id];
super.query(
"update person set navn = ?, adresse = ?, alder = ? where id=?",
val,
callback
);
}
deleteOne(json, callback) {
var val = [json.id];
super.query(
"delete from person where id =?",
val,
callback
);
}
};
......@@ -5,14 +5,24 @@ const runsqlfile = require("./runsqlfile.js");
// GitLab CI Pool
var pool = mysql.createPool({
connectionLimit: 1,
host: "mysql",
user: "root",
password: "secret",
database: "supertestdb",
debug: false,
multipleStatements: true
connectionLimit: 2,
host: "mysql",
user: "root",
password: "secret",
database: "supertestdb",
debug: false,
multipleStatements: true
});
/*
var pool = mysql.createPool({
connectionLimit: 2,
host: "mysql.stud.iie.ntnu.no",
user: "nilstesd",
password: "lqqWcMzq",
database: "nilstesd",
debug: false
});
*/
let personDao = new PersonDao(pool);
......@@ -77,3 +87,38 @@ test("get all persons from db", done => {
personDao.getAll(callback);
});
test("Update one person in db", done => {
function callback(status, data) {
console.log(
"Test callback: status=" + status + ", data=" + JSON.stringify(data)
);
expect(data.length).toBe(0);
done();
}
personDao.updateOne({ navn: "Oppdatert Nilsen", alder: 99, adresse: "Gata 3", id:0 }, callback);
});
test("get all persons from db", done => {
function callback(status, data) {
console.log(
"Test callback: status=" + status + ", data.length=" + data.length
);
expect(data.length).toBeGreaterThanOrEqual(2);
done();
}
personDao.getAll(callback);
});
test("delete person from db", done => {
function callback(status, data) {
console.log(
"Test callback: status=" + status + ", data=" + JSON.stringify(data)
);
expect(data.affectedRows).toBeGreaterThanOrEqual(1);
done();
}
personDao.deleteOne(0, callback);
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment