Skip to content
Snippets Groups Projects
Commit 237e9b71 authored by Sindre Haugland Paulshus's avatar Sindre Haugland Paulshus
Browse files

Pushing Oppgave 1,2,3, doing for 4

parent c3bcd161
No related branches found
No related tags found
No related merge requests found
Pipeline #22583 failed
DROP TABLE person;
CREATE TABLE person ( CREATE TABLE person (
id int(11) NOT NULL AUTO_INCREMENT, id int(11) NOT NULL AUTO_INCREMENT,
navn varchar(256) NOT NULL, navn varchar(256) NOT NULL,
......
...@@ -21,4 +21,21 @@ module.exports = class PersonDao extends Dao { ...@@ -21,4 +21,21 @@ module.exports = class PersonDao extends Dao {
callback callback
); );
} }
updateOne(id, json, callback) {
var val = [json.adresse, json.alder, json.navn, id];
super.query(
"update person set adresse=?, alder=?, navn=? where id=?",
val,
callback
);
}
deleteOne(id, callback) {
super.query(
"delete from person where id=?",
[id],
callback
);
}
}; };
...@@ -4,12 +4,23 @@ const PersonDao = require("./persondao.js"); ...@@ -4,12 +4,23 @@ const PersonDao = require("./persondao.js");
const runsqlfile = require("./runsqlfile.js"); const runsqlfile = require("./runsqlfile.js");
// GitLab CI Pool // GitLab CI Pool
/*
var pool = mysql.createPool({ var pool = mysql.createPool({
connectionLimit: 1, connectionLimit: 1,
host: "mysql", host: "mysql.stud.iie.ntnu.no", //"localhost" if u wonna be on local db
user: "sindrhpa",
password: "6XgiA9XF",
database: "sindrhpa",
debug: false,
multipleStatements: true
});*/
var pool = mysql.createPool({
connectionLimit: 1,
host: "localhost", //"localhost" if u wonna be on local db
user: "root", user: "root",
password: "secret", password: "sindre123",
database: "supertestdb", database: "sysut2_ov5",
debug: false, debug: false,
multipleStatements: true multipleStatements: true
}); });
...@@ -73,3 +84,42 @@ test("get all persons from db", done => { ...@@ -73,3 +84,42 @@ test("get all persons from db", done => {
personDao.getAll(callback); personDao.getAll(callback);
}); });
//Øving5: Skrevet selv
test("update person in db", done => {
personDao.updateOne(
1,
{ navn: "Bob Bobsen", alder: 50, adresse: "Gata 2" },
callback =>{
personDao.getOne(1, (status, data) =>{
console.log(
"Test callback: status=" + status + ", data=" + JSON.stringify(data)
);
expect(data[0].navn).toBe("Bob Bobsen");
done();
})
}
);
});
test("delete user from db", done => {
var val = 0;
personDao.getAll((status, data) => {
val = data.length;
console.log(
"Test callback: status=" + status + ", data.length=" + data.length
);
personDao.deleteOne(1, callback => {
console.log(
"Test callback: status=" + callback.status
);
personDao.getAll((status, data)=> {
console.log(
"Test callback: status=" + status + ", length=" + data.length
);
expect(data.length).toBe(val - 1);
done();
});
});
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment