Skip to content
Snippets Groups Projects
Commit 48f8c0d7 authored by Eyvind Nikolai Holt's avatar Eyvind Nikolai Holt
Browse files

Merge branch 'test' into 'master'

Til o3

See merge request !1
parents 006d767c 9e9d933d
No related branches found
No related tags found
1 merge request!1Til o3
Pipeline #22871 passed with stages
in 1 minute and 59 seconds
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="FLOW" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_10" default="false" project-jdk-name="10" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/Database-Test.iml" filepath="$PROJECT_DIR$/Database-Test.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
......@@ -21,4 +21,21 @@ 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(id, callback) {
super.query(
"delete from person where id=?",
[id],
callback
);
}
};
......@@ -6,10 +6,10 @@ const runsqlfile = require("./runsqlfile.js");
// GitLab CI Pool
var pool = mysql.createPool({
connectionLimit: 1,
host: "mysql",
user: "root",
password: "secret",
database: "supertestdb",
host: "mysql.stud.iie.ntnu.no",
user: "eyvindnh",
password: "baqveHFo",
database: "eyvindnh",
debug: false,
multipleStatements: true
});
......@@ -66,6 +66,41 @@ test("add person to db", done => {
);
});
test("update person in db", done => {
function callback(status, data) {
console.log(
"Test callback: status=" + status + ", data=" + JSON.stringify(data)
);
function callback2(status, data) {
console.log(
"Test callback: status=" + status + ", data=" + JSON.stringify(data)
);
expect(data.length).toBe(1);
expect(data[0].navn).toBe("Tale Leif");
done();
}
personDao.getOne(2, callback2);
}
personDao.updateOne(
{ navn: "Tale Leif", alder: 57, adresse: "Veien 5", id: 2 },
callback
);
});
test("delete person in db", done => {
function callback(status, data) {
console.log(
"Test callback: status=" + status + ", data.length=" + data.length
);
expect(data.affectedRows).toBeLessThanOrEqual(1);
done();
}
personDao.deleteOne(1, callback);
});
test("get all persons from db", done => {
function callback(status, data) {
console.log(
......
This diff is collapsed.
......@@ -9,9 +9,9 @@ const PersonDao = require("./dao/persondao.js");
var pool = mysql.createPool({
connectionLimit: 2,
host: "mysql.stud.iie.ntnu.no",
user: "nilstesd",
password: "lqqWcMzq",
database: "nilstesd",
user: "eyvindnh",
password: "baqveHFo",
database: "eyvindnh",
debug: false
});
......@@ -41,4 +41,23 @@ app.post("/person", (req, res) => {
});
});
app.put("/person/:personId", (req, res) => {
console.log("/person/:personId fikk PUT-request fra klienten");
var bodyString = JSON.stringify(req.body);
bodyString = bodyString.substring(1,bodyString.length-1);
var bodyJson = JSON.parse('{"id": ' + req.params.personId + "," + bodyString + "}");
personDao.updateOne(bodyJson, (status, data) => {
res.status(status);
res.json(data);
});
});
app.delete("/person/:personId", (req, res) => {
console.log("/person/:personId fikk PUT-request fra klienten");
personDao.deleteOne(req.params.personId, (status, data) => {
res.status(status);
res.json(data);
});
});
var server = app.listen(8080);
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