From 8d6b2f9adadf746864133c6786a6d1992dc757c4 Mon Sep 17 00:00:00 2001
From: Ulf Seltmann <seltmann@ub.uni-leipzig.de>
Date: Tue, 19 Dec 2017 16:28:06 +0100
Subject: [PATCH] * fixed tests * changed to ubl-internal repositories *
 changed gitlab-ci * updated dependencies

---
 .gitlab-ci.yml    |  36 +++++-----
 .npmignore        |   3 +-
 package-lock.json |  36 +++++-----
 package.json      |   4 +-
 src/test/cache.ts | 166 ++++++++++++++++++++++++++++++++++++++++++----
 5 files changed, 196 insertions(+), 49 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 5f44ce5..039bbeb 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -6,17 +6,21 @@ stages:
 - publish_image
 
 variables:
-  npm_config_registry: https://services.ub.uni-leipzig.de/npm
+  npm_config_registry: https://services.ub.uni-leipzig.de/repository/npm/
 
 npm_install:
   stage: build_app
   image: node:8-alpine
   script:
-  - npm install
-  - npm run build
+    - test -d .npm && mv .npm ${HOME}
+    - npm run build
+    - npm run ci
+    - mv ${HOME}/.npm .
   cache:
-    key: "${CI_COMMIT_SHA}"
+    key: "${CI_PROJECT_ID}"
     paths:
+    - .npm
+    - public
     - node_modules
     - dist
     - public
@@ -29,24 +33,26 @@ npm_ci:
   script:
   - npm run ci
   cache:
-    key: "${CI_COMMIT_SHA}"
+    key: "${CI_PROJECT_ID}"
     paths:
+    - .npm
     - dist
     - public
   tags:
     - docker
 
-npm_pack:
+npm_publish:
   stage: publish_app
   only:
   - master
   image: node:8-alpine
   script:
-  - npm pack
+  - 'echo "//services.ub.uni-leipzig.de/nexus/repository/npm-ubl/:_authToken=${NPM_TOKEN}" > ~/.npmrc'
+  - npm publish
   cache:
-    key: "${CI_COMMIT_SHA}"
+    key: "${CI_PROJECT_ID}"
     paths:
-    - "*.tgz"
+    - .npm
   tags:
     - docker
 
@@ -59,13 +65,13 @@ docker_build:
   - docker:dind
   script:
   - docker login --username ${DOCKER_USER} --password ${DOCKER_PASSWORD}
-  - docker build --no-cache --pull -t bdddev/dacap:latest .
-  - docker tag bdddev/dacap:latest bdddev/dacap:${CI_PIPELINE_ID}
-  - docker push bdddev/dacap:${CI_PIPELINE_ID}
-  - docker push bdddev/dacap:latest
+  - docker build --no-cache --pull -t services.ub.uni-leipzig.de:11443/bdd_dev/dacap:latest .
+  - docker tag services.ub.uni-leipzig.de:11443/bdd_dev/dacap:latest services.ub.uni-leipzig.de:11443/bdd_dev/dacap:${CI_PIPELINE_ID}
+  - docker push services.ub.uni-leipzig.de:11443/bdd_dev/dacap:${CI_PIPELINE_ID}
+  - docker push services.ub.uni-leipzig.de:11443/bdd_dev/dacap:latest
   cache:
-    key: "${CI_COMMIT_SHA}"
+    key: "${CI_PROJECT_ID}"
     paths:
-    - "*.tgz"
+    - .npm
   tags:
     - docker
diff --git a/.npmignore b/.npmignore
index be4b4e4..aff42dd 100644
--- a/.npmignore
+++ b/.npmignore
@@ -17,4 +17,5 @@
 /report.xml
 /Dockerfile
 /*.tgz
-/.gitlab-ci.yml
\ No newline at end of file
+/.gitlab-ci.yml
+/.npm
\ No newline at end of file
diff --git a/package-lock.json b/package-lock.json
index 1085686..d5ae094 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -3911,9 +3911,9 @@
       }
     },
     "nock": {
-      "version": "9.1.0",
-      "resolved": "https://services.ub.uni-leipzig.de/nexus/repository/npm/nock/-/nock-9.1.0.tgz",
-      "integrity": "sha512-u9QOLOZP0DlcKzmAzCuX5PRsIhbiRJupR7hJn1cCCT7VW3ZKUrEH/oxGEtVA8Xbu4EmzH9d/VK0x/3FxCGRrRg==",
+      "version": "9.1.4",
+      "resolved": "https://services.ub.uni-leipzig.de/nexus/repository/npm/nock/-/nock-9.1.4.tgz",
+      "integrity": "sha512-O0tkPO0VkiQ7mfCAg3QyL+6tt7srXHq0+m6BMy+SyzuKX+2Oz10ERXnqDL0nJxpVhKFx/E/K/6nT75U6RpvugQ==",
       "dev": true,
       "requires": {
         "chai": "3.5.0",
@@ -4058,15 +4058,15 @@
       "dev": true
     },
     "nyc": {
-      "version": "11.3.0",
-      "resolved": "https://services.ub.uni-leipzig.de/nexus/repository/npm/nyc/-/nyc-11.3.0.tgz",
-      "integrity": "sha512-oUu0WHt1k/JMIODvAYXX6C50Mupw2GO34P/Jdg2ty9xrLufBthHiKR2gf08aF+9S0abW1fl24R7iKRBXzibZmg==",
+      "version": "11.4.1",
+      "resolved": "https://services.ub.uni-leipzig.de/nexus/repository/npm/nyc/-/nyc-11.4.1.tgz",
+      "integrity": "sha512-5eCZpvaksFVjP2rt1r60cfXmt3MUtsQDw8bAzNqNEr4WLvUMLgiVENMf/B9bE9YAX0mGVvaGA3v9IS9ekNqB1Q==",
       "dev": true,
       "requires": {
         "archy": "1.0.0",
         "arrify": "1.0.1",
         "caching-transform": "1.0.1",
-        "convert-source-map": "1.5.0",
+        "convert-source-map": "1.5.1",
         "debug-log": "1.0.1",
         "default-require-extensions": "1.0.0",
         "find-cache-dir": "0.1.1",
@@ -4086,7 +4086,7 @@
         "resolve-from": "2.0.0",
         "rimraf": "2.6.2",
         "signal-exit": "3.0.2",
-        "spawn-wrap": "1.3.8",
+        "spawn-wrap": "1.4.2",
         "test-exclude": "4.1.1",
         "yargs": "10.0.3",
         "yargs-parser": "8.0.0"
@@ -4196,8 +4196,8 @@
           "bundled": true,
           "dev": true,
           "requires": {
-            "core-js": "2.5.1",
-            "regenerator-runtime": "0.11.0"
+            "core-js": "2.5.3",
+            "regenerator-runtime": "0.11.1"
           }
         },
         "babel-template": {
@@ -4346,12 +4346,12 @@
           "dev": true
         },
         "convert-source-map": {
-          "version": "1.5.0",
+          "version": "1.5.1",
           "bundled": true,
           "dev": true
         },
         "core-js": {
-          "version": "2.5.1",
+          "version": "2.5.3",
           "bundled": true,
           "dev": true
         },
@@ -4655,7 +4655,7 @@
           "dev": true
         },
         "is-buffer": {
-          "version": "1.1.5",
+          "version": "1.1.6",
           "bundled": true,
           "dev": true
         },
@@ -4853,7 +4853,7 @@
           "bundled": true,
           "dev": true,
           "requires": {
-            "is-buffer": "1.1.5"
+            "is-buffer": "1.1.6"
           }
         },
         "lazy-cache": {
@@ -5222,7 +5222,7 @@
                   "bundled": true,
                   "dev": true,
                   "requires": {
-                    "is-buffer": "1.1.5"
+                    "is-buffer": "1.1.6"
                   }
                 }
               }
@@ -5232,7 +5232,7 @@
               "bundled": true,
               "dev": true,
               "requires": {
-                "is-buffer": "1.1.5"
+                "is-buffer": "1.1.6"
               }
             }
           }
@@ -5268,7 +5268,7 @@
           }
         },
         "regenerator-runtime": {
-          "version": "0.11.0",
+          "version": "0.11.1",
           "bundled": true,
           "dev": true
         },
@@ -5374,7 +5374,7 @@
           "dev": true
         },
         "spawn-wrap": {
-          "version": "1.3.8",
+          "version": "1.4.2",
           "bundled": true,
           "dev": true,
           "requires": {
diff --git a/package.json b/package.json
index 5379a39..0c98cdf 100644
--- a/package.json
+++ b/package.json
@@ -75,8 +75,8 @@
     "jshint": "^2.9.5",
     "mocha": "^3.5.0",
     "mocha-jenkins-reporter": "^0.3.9",
-    "nock": "^9.1.0",
-    "nyc": "^11.3.0",
+    "nock": "^9.1.4",
+    "nyc": "^11.4.1",
     "rimraf": "^2.6.2",
     "should": "^11.2.1",
     "source-map-loader": "^0.2.1",
diff --git a/src/test/cache.ts b/src/test/cache.ts
index d7f5185..b9d688a 100644
--- a/src/test/cache.ts
+++ b/src/test/cache.ts
@@ -100,24 +100,164 @@ describe('Cache', () => {
 	});
 
 	describe('get', () => {
-		let cache;
-		beforeEach(() => {
-			nock('https://api.example.com').get('/').reply(200, {
-				"validKey": "validData"
+		describe('root element', () => {
+			let cache;
+			beforeEach(() => {
+				nock('https://api.example.com').get('/').reply(200, {
+					"validKey": "validData"
+				});
+
+				cache = new Cache(new Endpoint('https://api.example.com'), new NodeCache);
+			});
+
+			it('should return the json', (done) => {
+				cache.get('newHash', '').then((value) => {
+					should(value).eql({
+						uriPath: '',
+						contentType: 'application/json',
+						data: JSON.stringify({ "validKey": "validData" }),
+					});
+					done();
+				}).catch(done);
+			});
+			it('should return 404', (done) => {
+				cache.get('newHash', 'foo').then((value) => {
+					should(value).eql({
+						uriPath: 'foo',
+						contentType: '',
+						data: '',
+					});
+					done();
+				}).catch(done);
+			});
+		});
+		describe('root element with params', () => {
+			let cache;
+			beforeEach(() => {
+				nock('https://api.example.com').get('/?foo=bar').reply(200, {
+					"validKey": "validData"
+				});
+
+				cache = new Cache(new Endpoint('https://api.example.com'), new NodeCache);
 			});
 
-			cache = new Cache(new Endpoint('https://api.example.com'), new NodeCache);
+			it('should return the json', (done) => {
+				cache.get('newHash', '?foo=bar').then((value) => {
+					should(value).eql({
+						uriPath: '?foo=bar',
+						contentType: 'application/json',
+						data: JSON.stringify({ "validKey": "validData" }),
+					});
+					done();
+				}).catch(done);
+			});
+			it('should return 404', (done) => {
+				cache.get('newHash', 'foo').then((value) => {
+					should(value).eql({
+						uriPath: 'foo',
+						contentType: '',
+						data: '',
+					});
+					done();
+				}).catch(done);
+			});
 		});
 
-		it('should return the json',(done) => {
-			cache.get('newHash', '/').then((value) => {
-				should(value).eql({
-					uriPath: '/',
-					contentType: '',
-					data:'validData'
+		describe('relative path', () => {
+			let cache;
+			beforeEach(() => {
+				nock('https://api.example.com').get('/foo').reply(200, {
+					"validKey": "validData"
 				});
-				done();
-			}).catch(done);
+
+				cache = new Cache(new Endpoint('https://api.example.com/foo'), new NodeCache);
+			});
+
+			it('should return the json', (done) => {
+				cache.get('newHash', '').then((value) => {
+					should(value).eql({
+						uriPath: '',
+						contentType: 'application/json',
+						data: JSON.stringify({ "validKey": "validData" }),
+					});
+					done();
+				}).catch(done);
+			});
+			it('should return 404', (done) => {
+				cache.get('newHash', '?foo=bar').then((value) => {
+					should(value).eql({
+						uriPath: '?foo=bar',
+						contentType: '',
+						data: '',
+					});
+					done();
+				}).catch(done);
+			});
 		});
+
+		describe('relative path with params', () => {
+			let cache;
+			beforeEach(() => {
+				nock('https://api.example.com').get('/foo?bar=baz').reply(200, {
+					"validKey": "validData"
+				});
+
+				cache = new Cache(new Endpoint('https://api.example.com/foo'), new NodeCache);
+			});
+
+			it('should return the json', (done) => {
+				cache.get('newHash', '?bar=baz').then((value) => {
+					should(value).eql({
+						uriPath: '?bar=baz',
+						contentType: 'application/json',
+						data: JSON.stringify({ "validKey": "validData" }),
+					});
+					done();
+				}).catch(done);
+			});
+			it('should return 404', (done) => {
+				cache.get('newHash', 'bar/baz').then((value) => {
+					should(value).eql({
+						uriPath: 'bar/baz',
+						contentType: '',
+						data: '',
+					});
+					done();
+				}).catch(done);
+			});
+		});
+
+		describe('relative path with subpath', () => {
+			let cache;
+			beforeEach(() => {
+				nock('https://api.example.com').get('/foo/bar/baz').reply(200, {
+					"validKey": "validData"
+				});
+
+				cache = new Cache(new Endpoint('https://api.example.com/foo'), new NodeCache);
+			});
+
+			it('should return the json', (done) => {
+				cache.get('newHash', '/bar/baz').then((value) => {
+					should(value).eql({
+						uriPath: '/bar/baz',
+						contentType: 'application/json',
+						data: JSON.stringify({ "validKey": "validData" }),
+					});
+					done();
+				}).catch(done);
+			});
+			it('should return 404', (done) => {
+				cache.get('newHash', '/bar=baz').then((value) => {
+					should(value).eql({
+						uriPath: '/bar=baz',
+						contentType: '',
+						data: '',
+					});
+					done();
+				}).catch(done);
+			});
+		});
+
 	});
 });
\ No newline at end of file
-- 
GitLab