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
Espen Kalleberg
DatabaseTest
Commits
ffc6f3bf
Commit
ffc6f3bf
authored
5 years ago
by
Espen Kalleberg
Browse files
Options
Downloads
Patches
Plain Diff
Test
parent
006d767c
No related branches found
No related tags found
No related merge requests found
Pipeline
#49582
passed
5 years ago
Stage: test
Stage: deploy
Changes
4
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
dao/create_testdata.sql
+4
-1
4 additions, 1 deletion
dao/create_testdata.sql
dao/persondao.js
+19
-1
19 additions, 1 deletion
dao/persondao.js
dao/persondao.test.js
+41
-0
41 additions, 0 deletions
dao/persondao.test.js
server.js
+16
-0
16 additions, 0 deletions
server.js
with
80 additions
and
2 deletions
dao/create_testdata.sql
+
4
−
1
View file @
ffc6f3bf
INSERT
INTO
person
(
id
,
navn
,
alder
,
adresse
)
VALUES
INSERT
INTO
person
(
id
,
navn
,
alder
,
adresse
)
VALUES
(
1
,
'Hei Sveisen'
,
21
,
'Gata 1'
),
(
1
,
'Hei Sveisen'
,
21
,
'Gata 1'
),
(
2
,
'Hei Heisen'
,
22
,
'Gata 2'
);
(
2
,
'Hei Leisen'
,
21
,
'Gata 2'
),
(
3
,
'Hei Meisen'
,
21
,
'Gata 3'
),
(
4
,
'Hei Peisen'
,
21
,
'Gata 4'
),
(
5
,
'Hei Heisen'
,
22
,
'Gata 5'
);
This diff is collapsed.
Click to expand it.
dao/persondao.js
+
19
−
1
View file @
ffc6f3bf
...
@@ -13,6 +13,24 @@ module.exports = class PersonDao extends Dao {
...
@@ -13,6 +13,24 @@ module.exports = class PersonDao extends Dao {
);
);
}
}
updateOne
(
json
,
id
,
callback
)
{
var
val
=
[
json
.
navn
,
json
.
adresse
,
json
.
alder
,
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
);
}
createOne
(
json
,
callback
)
{
createOne
(
json
,
callback
)
{
var
val
=
[
json
.
navn
,
json
.
adresse
,
json
.
alder
];
var
val
=
[
json
.
navn
,
json
.
adresse
,
json
.
alder
];
super
.
query
(
super
.
query
(
...
@@ -21,4 +39,4 @@ module.exports = class PersonDao extends Dao {
...
@@ -21,4 +39,4 @@ module.exports = class PersonDao extends Dao {
callback
callback
);
);
}
}
}
;
}
This diff is collapsed.
Click to expand it.
dao/persondao.test.js
+
41
−
0
View file @
ffc6f3bf
...
@@ -77,3 +77,44 @@ test("get all persons from db", done => {
...
@@ -77,3 +77,44 @@ test("get all persons from db", done => {
personDao
.
getAll
(
callback
);
personDao
.
getAll
(
callback
);
});
});
test
(
"
delete one person from db
"
,
done
=>
{
function
callback
(
status
,
data
)
{
console
.
log
(
"
Test callback: status=
"
+
status
+
"
, data.length=
"
+
data
.
length
);
expect
(
data
.
affectedRows
).
toBeGreaterThanOrEqual
(
1
);
done
();
}
personDao
.
deleteOne
(
1
,
callback
);
});
test
(
"
get all persons from db after delete
"
,
done
=>
{
function
callback
(
status
,
data
)
{
console
.
log
(
"
Test callback: status=
"
+
status
+
"
, data.length=
"
+
data
.
length
);
expect
(
data
.
length
).
toBe
(
5
);
done
();
}
personDao
.
getAll
(
callback
);
});
test
(
"
update one 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
.
updateOne
(
{
navn
:
"
Billy Bob
"
,
adresse
:
"
Gata 3
"
,
alder
:
"
34
"
},
{
id
:
"
1
"
},
callback
);
});
This diff is collapsed.
Click to expand it.
server.js
+
16
−
0
View file @
ffc6f3bf
...
@@ -41,4 +41,20 @@ app.post("/person", (req, res) => {
...
@@ -41,4 +41,20 @@ app.post("/person", (req, res) => {
});
});
});
});
pp
.
delete
(
"
/person/:personId
"
,
(
req
,
res
)
=>
{
console
.
log
(
"
/person/:personId: fikk delete-request fra klient
"
);
personDao
.
deleteOne
(
req
.
params
.
personId
,
(
status
,
data
)
=>
{
res
.
status
(
status
);
res
.
json
(
data
);
});
});
app
.
put
(
"
/person/:personId
"
,
(
req
,
res
)
=>
{
console
.
log
(
"
Fikk put-request fra klienten
"
);
personDao
.
updateOne
(
req
.
body
,
req
.
params
.
personId
,
(
status
,
data
)
=>
{
res
.
status
(
status
);
res
.
json
(
data
);
});
});
var
server
=
app
.
listen
(
8080
);
var
server
=
app
.
listen
(
8080
);
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