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
Aleksander Johansen
DatabaseTest
Commits
b667f3c3
Commit
b667f3c3
authored
6 years ago
by
Aleksander Johansen
Browse files
Options
Downloads
Patches
Plain Diff
Dont read pls
parent
5471b913
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#22801
passed
6 years ago
Stage: test
Stage: deploy
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
dao/create_tables.sql
+2
-2
2 additions, 2 deletions
dao/create_tables.sql
dao/create_testdata.sql
+1
-1
1 addition, 1 deletion
dao/create_testdata.sql
dao/persondao.js
+33
-5
33 additions, 5 deletions
dao/persondao.js
dao/persondao.test.js
+43
-7
43 additions, 7 deletions
dao/persondao.test.js
with
79 additions
and
15 deletions
dao/create_tables.sql
+
2
−
2
View file @
b667f3c3
DROP
TABLE
IF
EXISTS
person
;
DROP
TABLE
IF
EXISTS
person
Drogas
;
CREATE
TABLE
person
(
CREATE
TABLE
person
Drogas
(
id
int
(
11
)
NOT
NULL
AUTO_INCREMENT
,
navn
varchar
(
256
)
NOT
NULL
,
alder
int
(
3
)
DEFAULT
NULL
,
...
...
This diff is collapsed.
Click to expand it.
dao/create_testdata.sql
+
1
−
1
View file @
b667f3c3
INSERT
INTO
person
(
id
,
navn
,
alder
,
adresse
)
VALUES
INSERT
INTO
person
Drogas
(
id
,
navn
,
alder
,
adresse
)
VALUES
(
1
,
'Hei Sveisen'
,
21
,
'Gata 1'
),
(
2
,
'Hei Heisen'
,
22
,
'Gata 2'
);
This diff is collapsed.
Click to expand it.
dao/persondao.js
+
33
−
5
View file @
b667f3c3
...
...
@@ -2,12 +2,11 @@ const Dao = require("./dao.js");
module
.
exports
=
class
PersonDao
extends
Dao
{
getAll
(
callback
)
{
super
.
query
(
"
select navn, alder, adresse from person
"
,
[],
callback
);
super
.
query
(
"
select navn, alder, adresse from person
Drogas
"
,
[],
callback
);
}
getOne
(
id
,
callback
)
{
super
.
query
(
"
select navn, alder, adresse from person where id=?
"
,
super
.
query
(
"
select navn, alder, adresse from personDrogas where id=?
"
,
[
id
],
callback
);
...
...
@@ -15,10 +14,39 @@ module.exports = class PersonDao extends Dao {
createOne
(
json
,
callback
)
{
var
val
=
[
json
.
navn
,
json
.
adresse
,
json
.
alder
];
super
.
query
(
"
insert into person (navn,adresse,alder) values (?,?,?)
"
,
super
.
query
(
"
insert into personDrogas (navn,adresse,alder) values (?,?,?)
"
,
val
,
callback
);
}
deleteOne
(
id
,
callback
){
super
.
query
(
"
DELETE FROM personDrogas WHERE id=?
"
,
[
id
],
callback
);
}
updateOne
(
json
,
id
,
callback
){
let
navn
=
json
.
navn
;
let
adresse
=
json
.
adresse
;
let
alder
=
json
.
alder
;
if
(
json
.
navn
.
trim
()
===
""
){
navn
=
super
.
query
(
"
SELECT navn FROM personDrogas WHERE id=?
"
,
[
id
],
callback
);
}
if
(
json
.
adresse
.
trim
()
===
""
){
adresse
=
super
.
query
(
"
SELECT adresse FROM personDrogas WHERE id=?
"
,
[
id
],
callback
);
}
if
(
json
.
alder
==
null
){
alder
=
super
.
query
(
"
SELECT alder FROM personDrogas WHERE id=?
"
,
[
id
],
callback
);
}
let
val
=
[
navn
,
adresse
,
alder
,
id
];
super
.
query
(
"
UPDATE personDrogas SET navn=?, adresse=?, alder=? WHERE id=?
"
,
val
,
callback
);
}
};
This diff is collapsed.
Click to expand it.
dao/persondao.test.js
+
43
−
7
View file @
b667f3c3
...
...
@@ -5,17 +5,18 @@ 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
:
1
0
,
host
:
"
mysql
.stud.iie.ntnu.no
"
,
user
:
"
nilstesd
"
,
password
:
"
lqqWcMzq
"
,
database
:
"
nilstesd
"
,
debug
:
false
,
multipleStatements
:
true
});
let
personDao
=
new
PersonDao
(
pool
);
beforeAll
(
done
=>
{
runsqlfile
(
"
dao/create_tables.sql
"
,
pool
,
()
=>
{
runsqlfile
(
"
dao/create_testdata.sql
"
,
pool
,
done
);
...
...
@@ -77,3 +78,38 @@ test("get all persons from db", done => {
personDao
.
getAll
(
callback
);
});
test
(
"
Deleting person from database
"
,
done
=>
{
function
callback
(
status
,
data
)
{
console
.
log
(
"
Test callback: status=
"
+
status
+
"
, data=
"
+
JSON
.
stringify
(
data
));
expect
(
data
.
affectedRows
).
toBe
(
1
);
length
=
data
.
length
;
done
();
}
personDao
.
deleteOne
(
2
,
callback
);
});
test
(
"
Update person from database
"
,
done
=>
{
let
oldName
;
let
oldAge
;
let
oldAdress
;
personDao
.
getOne
(
1
,
(
status
,
data
)
=>
{
oldName
=
data
.
navn
;
oldAge
=
data
.
alder
;
oldAdress
=
data
.
adresse
;
});
personDao
.
updateOne
({
navn
:
"
Nissen
"
,
alder
:
100
,
adresse
:
"
Steder i verden
"
},
1
,
()
=>
{});
personDao
.
getOne
(
"
1
"
,
(
satus
,
data3
)
=>
{
if
(
data3
.
error
)
data3
=
{
navn
:
""
,
alder
:
2
,
adresse
:
"
asd
"
};
expect
(
oldName
).
not
.
toEqual
(
data3
.
navn
);
expect
(
oldAge
).
not
.
toEqual
(
data3
.
alder
);
expect
(
oldAdress
).
not
.
toEqual
(
data3
.
adresse
);
});
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