From c5077de5176da1d8802fc63217b70f35fcdf257e Mon Sep 17 00:00:00 2001
From: nilstes <nils.tesdal@gmail.com>
Date: Tue, 11 Sep 2018 17:01:27 +0200
Subject: [PATCH] feilsok

---
 .gitlab-ci.yml        | 16 ++--------------
 dao/persondao.test.js | 36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+), 14 deletions(-)
 create mode 100644 dao/persondao.test.js

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 283f7e2..0a40ceb 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -7,20 +7,8 @@ services:
 # Configure test-database
 variables:
   MYSQL_DATABASE: db
-  MYSQL_ROOT_PASSWORD: password
-  
-# Create database tables
-#connect:
-#  image: mysql
-#  script:
-#  - echo "SELECT 'OK';" | mysql --user=root --password="$MYSQL_ROOT_PASSWORD" --host=mysql "$MYSQL_DATABASE" < create_tables.sql
-
-# Install node libraries
-before_script:
-  - npm install
-  - apt-get update -q && apt-get install -qqy --no-install-recommends mysql-client
-  - mysql --user=root --password="$MYSQL_ROOT_PASSWORD" --host=mysql "$MYSQL_DATABASE" < create_tables.sql
-  
+  MYSQL_ROOT_PASSWORD: secret
+    
 # Run JEST tests
 test:
   script:
diff --git a/dao/persondao.test.js b/dao/persondao.test.js
new file mode 100644
index 0000000..222b1e4
--- /dev/null
+++ b/dao/persondao.test.js
@@ -0,0 +1,36 @@
+var mysql = require("mysql");
+
+var pool = mysql.createPool({
+  connectionLimit: 2,
+  host: "mysql",
+  user: "root",
+  password: "secret",
+  database: "db",
+  debug: false
+});
+
+test("query db", () => {
+  pool.getConnection((err, connection) => {
+    console.log("Connected to database");
+    if (err) {
+      console.log("Feil ved kobling til databasen");
+      res.json({ error: "feil ved ved oppkobling" });
+    } else {
+      connection.query(
+        "select navn, alder, adresse from person",
+        (err, rows) => {
+          connection.release();
+          if (err) {
+            console.log(err);
+            res.json({ error: "error querying" });
+          } else {
+            console.log("returning rows");
+            res.json(rows);
+          }
+        }
+      );
+    }
+  });
+
+  expect(sum(1, 2)).toBe(3);
+});
\ No newline at end of file
-- 
GitLab