Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DatabaseTest
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sindre Haugland Paulshus
DatabaseTest
Commits
237e9b71
Commit
237e9b71
authored
6 years ago
by
Sindre Haugland Paulshus
Browse files
Options
Downloads
Patches
Plain Diff
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
6 years ago
Stage: test
Stage: deploy
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
dao/create_tables.sql
+1
-0
1 addition, 0 deletions
dao/create_tables.sql
dao/persondao.js
+17
-0
17 additions, 0 deletions
dao/persondao.js
dao/persondao.test.js
+54
-4
54 additions, 4 deletions
dao/persondao.test.js
with
72 additions
and
4 deletions
dao/create_tables.sql
+
1
−
0
View file @
237e9b71
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
,
...
...
This diff is collapsed.
Click to expand it.
dao/persondao.js
+
17
−
0
View file @
237e9b71
...
@@ -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
);
}
};
};
This diff is collapsed.
Click to expand it.
dao/persondao.test.js
+
54
−
4
View file @
237e9b71
...
@@ -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
:
"
s
ecret
"
,
password
:
"
s
indre123
"
,
database
:
"
s
upertestdb
"
,
database
:
"
s
ysut2_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
();
});
});
});
});
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment