From 29e643e66396fd8fd73b58980124f7d8436f949d Mon Sep 17 00:00:00 2001 From: Mikayla Dobson <93477693+innocuous-symmetry@users.noreply.github.com> Date: Fri, 9 Dec 2022 18:10:26 -0600 Subject: [PATCH] configuring backend tests --- server/coverage/clover.xml | 12 + server/coverage/coverage-final.json | 2 + server/coverage/lcov-report/base.css | 224 ++++++ .../coverage/lcov-report/block-navigation.js | 87 +++ server/coverage/lcov-report/favicon.png | Bin 0 -> 445 bytes server/coverage/lcov-report/index.html | 116 ++++ server/coverage/lcov-report/now.js.html | 97 +++ server/coverage/lcov-report/now.ts.html | 88 +++ server/coverage/lcov-report/prettify.css | 1 + server/coverage/lcov-report/prettify.js | 2 + .../lcov-report/server/appRoot.ts.html | 88 +++ .../server/controllers/CollectionCtl.ts.html | 220 ++++++ .../server/controllers/CourseCtl.ts.html | 190 ++++++ .../server/controllers/CuisineCtl.ts.html | 190 ++++++ .../server/controllers/GroceryListCtl.ts.html | 250 +++++++ .../server/controllers/IngredientCtl.ts.html | 220 ++++++ .../server/controllers/RecipeCtl.ts.html | 244 +++++++ .../server/controllers/UserCtl.ts.html | 370 ++++++++++ .../lcov-report/server/controllers/index.html | 221 ++++++ .../server/controllers/index.ts.html | 115 ++++ .../coverage/lcov-report/server/db/index.html | 116 ++++ .../lcov-report/server/db/index.ts.html | 100 +++ server/coverage/lcov-report/server/index.html | 116 ++++ .../server/models/collection.ts.html | 547 +++++++++++++++ .../lcov-report/server/models/course.ts.html | 214 ++++++ .../lcov-report/server/models/cuisine.ts.html | 214 ++++++ .../server/models/groceryList.ts.html | 307 +++++++++ .../lcov-report/server/models/index.html | 206 ++++++ .../server/models/ingredient.ts.html | 265 ++++++++ .../lcov-report/server/models/recipe.ts.html | 361 ++++++++++ .../lcov-report/server/models/user.ts.html | 640 ++++++++++++++++++ .../lcov-report/server/routes/cuisine.ts.html | 202 ++++++ .../lcov-report/server/routes/index.html | 116 ++++ .../lcov-report/server/util/index.html | 116 ++++ .../lcov-report/server/util/now.ts.html | 88 +++ .../lcov-report/sort-arrow-sprite.png | Bin 0 -> 138 bytes server/coverage/lcov-report/sorter.js | 196 ++++++ server/coverage/lcov-report/util/index.html | 116 ++++ server/coverage/lcov-report/util/now.ts.html | 88 +++ server/coverage/lcov.info | 12 + server/index.ts | 7 +- server/jest.config.js | 6 + server/jest/index.ts | 5 + server/jest/tests/now.test.ts | 13 + server/jest/tests/routes/collection.test.ts | 0 server/jest/tests/routes/comment.test.ts | 0 server/jest/tests/routes/course.test.ts | 0 server/jest/tests/routes/cuisine.test.ts | 48 ++ server/jest/tests/routes/friend.test.ts | 0 server/jest/tests/routes/groceryList.test.ts | 0 server/jest/tests/routes/ingredient.test.ts | 0 server/jest/tests/routes/recipe.test.ts | 0 server/jest/tests/routes/subscription.test.ts | 0 server/jest/tests/routes/users.test.ts | 44 ++ server/package.json | 8 +- 55 files changed, 6884 insertions(+), 4 deletions(-) create mode 100644 server/coverage/clover.xml create mode 100644 server/coverage/coverage-final.json create mode 100644 server/coverage/lcov-report/base.css create mode 100644 server/coverage/lcov-report/block-navigation.js create mode 100644 server/coverage/lcov-report/favicon.png create mode 100644 server/coverage/lcov-report/index.html create mode 100644 server/coverage/lcov-report/now.js.html create mode 100644 server/coverage/lcov-report/now.ts.html create mode 100644 server/coverage/lcov-report/prettify.css create mode 100644 server/coverage/lcov-report/prettify.js create mode 100644 server/coverage/lcov-report/server/appRoot.ts.html create mode 100644 server/coverage/lcov-report/server/controllers/CollectionCtl.ts.html create mode 100644 server/coverage/lcov-report/server/controllers/CourseCtl.ts.html create mode 100644 server/coverage/lcov-report/server/controllers/CuisineCtl.ts.html create mode 100644 server/coverage/lcov-report/server/controllers/GroceryListCtl.ts.html create mode 100644 server/coverage/lcov-report/server/controllers/IngredientCtl.ts.html create mode 100644 server/coverage/lcov-report/server/controllers/RecipeCtl.ts.html create mode 100644 server/coverage/lcov-report/server/controllers/UserCtl.ts.html create mode 100644 server/coverage/lcov-report/server/controllers/index.html create mode 100644 server/coverage/lcov-report/server/controllers/index.ts.html create mode 100644 server/coverage/lcov-report/server/db/index.html create mode 100644 server/coverage/lcov-report/server/db/index.ts.html create mode 100644 server/coverage/lcov-report/server/index.html create mode 100644 server/coverage/lcov-report/server/models/collection.ts.html create mode 100644 server/coverage/lcov-report/server/models/course.ts.html create mode 100644 server/coverage/lcov-report/server/models/cuisine.ts.html create mode 100644 server/coverage/lcov-report/server/models/groceryList.ts.html create mode 100644 server/coverage/lcov-report/server/models/index.html create mode 100644 server/coverage/lcov-report/server/models/ingredient.ts.html create mode 100644 server/coverage/lcov-report/server/models/recipe.ts.html create mode 100644 server/coverage/lcov-report/server/models/user.ts.html create mode 100644 server/coverage/lcov-report/server/routes/cuisine.ts.html create mode 100644 server/coverage/lcov-report/server/routes/index.html create mode 100644 server/coverage/lcov-report/server/util/index.html create mode 100644 server/coverage/lcov-report/server/util/now.ts.html create mode 100644 server/coverage/lcov-report/sort-arrow-sprite.png create mode 100644 server/coverage/lcov-report/sorter.js create mode 100644 server/coverage/lcov-report/util/index.html create mode 100644 server/coverage/lcov-report/util/now.ts.html create mode 100644 server/coverage/lcov.info create mode 100644 server/jest.config.js create mode 100644 server/jest/index.ts create mode 100644 server/jest/tests/now.test.ts create mode 100644 server/jest/tests/routes/collection.test.ts create mode 100644 server/jest/tests/routes/comment.test.ts create mode 100644 server/jest/tests/routes/course.test.ts create mode 100644 server/jest/tests/routes/cuisine.test.ts create mode 100644 server/jest/tests/routes/friend.test.ts create mode 100644 server/jest/tests/routes/groceryList.test.ts create mode 100644 server/jest/tests/routes/ingredient.test.ts create mode 100644 server/jest/tests/routes/recipe.test.ts create mode 100644 server/jest/tests/routes/subscription.test.ts create mode 100644 server/jest/tests/routes/users.test.ts diff --git a/server/coverage/clover.xml b/server/coverage/clover.xml new file mode 100644 index 0000000..d9cd11e --- /dev/null +++ b/server/coverage/clover.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/server/coverage/coverage-final.json b/server/coverage/coverage-final.json new file mode 100644 index 0000000..23251f0 --- /dev/null +++ b/server/coverage/coverage-final.json @@ -0,0 +1,2 @@ +{"/Users/mikayladobson/Developer/PORTFOLIO/recipe-manager/server/dist/util/now.js": {"path":"/Users/mikayladobson/Developer/PORTFOLIO/recipe-manager/server/dist/util/now.js","statementMap":{"0":{"start":{"line":2,"column":0},"end":{"line":2,"column":62}},"1":{"start":{"line":3,"column":12},"end":{"line":3,"column":107}},"2":{"start":{"line":4,"column":0},"end":{"line":4,"column":22}}},"fnMap":{},"branchMap":{},"s":{"0":1,"1":1,"2":1},"f":{},"b":{},"inputSourceMap":null,"_coverageSchema":"1a1c01bbd47fc00a2c39e90264f33305004495a9","hash":"d3077020336b64e83c273307d04f9e3686d7e20c"} +} diff --git a/server/coverage/lcov-report/base.css b/server/coverage/lcov-report/base.css new file mode 100644 index 0000000..f418035 --- /dev/null +++ b/server/coverage/lcov-report/base.css @@ -0,0 +1,224 @@ +body, html { + margin:0; padding: 0; + height: 100%; +} +body { + font-family: Helvetica Neue, Helvetica, Arial; + font-size: 14px; + color:#333; +} +.small { font-size: 12px; } +*, *:after, *:before { + -webkit-box-sizing:border-box; + -moz-box-sizing:border-box; + box-sizing:border-box; + } +h1 { font-size: 20px; margin: 0;} +h2 { font-size: 14px; } +pre { + font: 12px/1.4 Consolas, "Liberation Mono", Menlo, Courier, monospace; + margin: 0; + padding: 0; + -moz-tab-size: 2; + -o-tab-size: 2; + tab-size: 2; +} +a { color:#0074D9; text-decoration:none; } +a:hover { text-decoration:underline; } +.strong { font-weight: bold; } +.space-top1 { padding: 10px 0 0 0; } +.pad2y { padding: 20px 0; } +.pad1y { padding: 10px 0; } +.pad2x { padding: 0 20px; } +.pad2 { padding: 20px; } +.pad1 { padding: 10px; } +.space-left2 { padding-left:55px; } +.space-right2 { padding-right:20px; } +.center { text-align:center; } +.clearfix { display:block; } +.clearfix:after { + content:''; + display:block; + height:0; + clear:both; + visibility:hidden; + } +.fl { float: left; } +@media only screen and (max-width:640px) { + .col3 { width:100%; max-width:100%; } + .hide-mobile { display:none!important; } +} + +.quiet { + color: #7f7f7f; + color: rgba(0,0,0,0.5); +} +.quiet a { opacity: 0.7; } + +.fraction { + font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; + font-size: 10px; + color: #555; + background: #E8E8E8; + padding: 4px 5px; + border-radius: 3px; + vertical-align: middle; +} + +div.path a:link, div.path a:visited { color: #333; } +table.coverage { + border-collapse: collapse; + margin: 10px 0 0 0; + padding: 0; +} + +table.coverage td { + margin: 0; + padding: 0; + vertical-align: top; +} +table.coverage td.line-count { + text-align: right; + padding: 0 5px 0 20px; +} +table.coverage td.line-coverage { + text-align: right; + padding-right: 10px; + min-width:20px; +} + +table.coverage td span.cline-any { + display: inline-block; + padding: 0 5px; + width: 100%; +} +.missing-if-branch { + display: inline-block; + margin-right: 5px; + border-radius: 3px; + position: relative; + padding: 0 4px; + background: #333; + color: yellow; +} + +.skip-if-branch { + display: none; + margin-right: 10px; + position: relative; + padding: 0 4px; + background: #ccc; + color: white; +} +.missing-if-branch .typ, .skip-if-branch .typ { + color: inherit !important; +} +.coverage-summary { + border-collapse: collapse; + width: 100%; +} +.coverage-summary tr { border-bottom: 1px solid #bbb; } +.keyline-all { border: 1px solid #ddd; } +.coverage-summary td, .coverage-summary th { padding: 10px; } +.coverage-summary tbody { border: 1px solid #bbb; } +.coverage-summary td { border-right: 1px solid #bbb; } +.coverage-summary td:last-child { border-right: none; } +.coverage-summary th { + text-align: left; + font-weight: normal; + white-space: nowrap; +} +.coverage-summary th.file { border-right: none !important; } +.coverage-summary th.pct { } +.coverage-summary th.pic, +.coverage-summary th.abs, +.coverage-summary td.pct, +.coverage-summary td.abs { text-align: right; } +.coverage-summary td.file { white-space: nowrap; } +.coverage-summary td.pic { min-width: 120px !important; } +.coverage-summary tfoot td { } + +.coverage-summary .sorter { + height: 10px; + width: 7px; + display: inline-block; + margin-left: 0.5em; + background: url(sort-arrow-sprite.png) no-repeat scroll 0 0 transparent; +} +.coverage-summary .sorted .sorter { + background-position: 0 -20px; +} +.coverage-summary .sorted-desc .sorter { + background-position: 0 -10px; +} +.status-line { height: 10px; } +/* yellow */ +.cbranch-no { background: yellow !important; color: #111; } +/* dark red */ +.red.solid, .status-line.low, .low .cover-fill { background:#C21F39 } +.low .chart { border:1px solid #C21F39 } +.highlighted, +.highlighted .cstat-no, .highlighted .fstat-no, .highlighted .cbranch-no{ + background: #C21F39 !important; +} +/* medium red */ +.cstat-no, .fstat-no, .cbranch-no, .cbranch-no { background:#F6C6CE } +/* light red */ +.low, .cline-no { background:#FCE1E5 } +/* light green */ +.high, .cline-yes { background:rgb(230,245,208) } +/* medium green */ +.cstat-yes { background:rgb(161,215,106) } +/* dark green */ +.status-line.high, .high .cover-fill { background:rgb(77,146,33) } +.high .chart { border:1px solid rgb(77,146,33) } +/* dark yellow (gold) */ +.status-line.medium, .medium .cover-fill { background: #f9cd0b; } +.medium .chart { border:1px solid #f9cd0b; } +/* light yellow */ +.medium { background: #fff4c2; } + +.cstat-skip { background: #ddd; color: #111; } +.fstat-skip { background: #ddd; color: #111 !important; } +.cbranch-skip { background: #ddd !important; color: #111; } + +span.cline-neutral { background: #eaeaea; } + +.coverage-summary td.empty { + opacity: .5; + padding-top: 4px; + padding-bottom: 4px; + line-height: 1; + color: #888; +} + +.cover-fill, .cover-empty { + display:inline-block; + height: 12px; +} +.chart { + line-height: 0; +} +.cover-empty { + background: white; +} +.cover-full { + border-right: none !important; +} +pre.prettyprint { + border: none !important; + padding: 0 !important; + margin: 0 !important; +} +.com { color: #999 !important; } +.ignore-none { color: #999; font-weight: normal; } + +.wrapper { + min-height: 100%; + height: auto !important; + height: 100%; + margin: 0 auto -48px; +} +.footer, .push { + height: 48px; +} diff --git a/server/coverage/lcov-report/block-navigation.js b/server/coverage/lcov-report/block-navigation.js new file mode 100644 index 0000000..cc12130 --- /dev/null +++ b/server/coverage/lcov-report/block-navigation.js @@ -0,0 +1,87 @@ +/* eslint-disable */ +var jumpToCode = (function init() { + // Classes of code we would like to highlight in the file view + var missingCoverageClasses = ['.cbranch-no', '.cstat-no', '.fstat-no']; + + // Elements to highlight in the file listing view + var fileListingElements = ['td.pct.low']; + + // We don't want to select elements that are direct descendants of another match + var notSelector = ':not(' + missingCoverageClasses.join('):not(') + ') > '; // becomes `:not(a):not(b) > ` + + // Selecter that finds elements on the page to which we can jump + var selector = + fileListingElements.join(', ') + + ', ' + + notSelector + + missingCoverageClasses.join(', ' + notSelector); // becomes `:not(a):not(b) > a, :not(a):not(b) > b` + + // The NodeList of matching elements + var missingCoverageElements = document.querySelectorAll(selector); + + var currentIndex; + + function toggleClass(index) { + missingCoverageElements + .item(currentIndex) + .classList.remove('highlighted'); + missingCoverageElements.item(index).classList.add('highlighted'); + } + + function makeCurrent(index) { + toggleClass(index); + currentIndex = index; + missingCoverageElements.item(index).scrollIntoView({ + behavior: 'smooth', + block: 'center', + inline: 'center' + }); + } + + function goToPrevious() { + var nextIndex = 0; + if (typeof currentIndex !== 'number' || currentIndex === 0) { + nextIndex = missingCoverageElements.length - 1; + } else if (missingCoverageElements.length > 1) { + nextIndex = currentIndex - 1; + } + + makeCurrent(nextIndex); + } + + function goToNext() { + var nextIndex = 0; + + if ( + typeof currentIndex === 'number' && + currentIndex < missingCoverageElements.length - 1 + ) { + nextIndex = currentIndex + 1; + } + + makeCurrent(nextIndex); + } + + return function jump(event) { + if ( + document.getElementById('fileSearch') === document.activeElement && + document.activeElement != null + ) { + // if we're currently focused on the search input, we don't want to navigate + return; + } + + switch (event.which) { + case 78: // n + case 74: // j + goToNext(); + break; + case 66: // b + case 75: // k + case 80: // p + goToPrevious(); + break; + } + }; +})(); +window.addEventListener('keydown', jumpToCode); diff --git a/server/coverage/lcov-report/favicon.png b/server/coverage/lcov-report/favicon.png new file mode 100644 index 0000000000000000000000000000000000000000..c1525b811a167671e9de1fa78aab9f5c0b61cef7 GIT binary patch literal 445 zcmV;u0Yd(XP))rP{nL}Ln%S7`m{0DjX9TLF* zFCb$4Oi7vyLOydb!7n&^ItCzb-%BoB`=x@N2jll2Nj`kauio%aw_@fe&*}LqlFT43 z8doAAe))z_%=P%v^@JHp3Hjhj^6*Kr_h|g_Gr?ZAa&y>wxHE99Gk>A)2MplWz2xdG zy8VD2J|Uf#EAw*bo5O*PO_}X2Tob{%bUoO2G~T`@%S6qPyc}VkhV}UifBuRk>%5v( z)x7B{I~z*k<7dv#5tC+m{km(D087J4O%+<<;K|qwefb6@GSX45wCK}Sn*> + + + + Code coverage report for All files + + + + + + + + + +
+
+

All files

+
+ +
+ 100% + Statements + 3/3 +
+ + +
+ 100% + Branches + 0/0 +
+ + +
+ 100% + Functions + 0/0 +
+ + +
+ 100% + Lines + 3/3 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileStatementsBranchesFunctionsLines
now.js +
+
100%3/3100%0/0100%0/0100%3/3
+
+
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/now.js.html b/server/coverage/lcov-report/now.js.html new file mode 100644 index 0000000..4aaf1d1 --- /dev/null +++ b/server/coverage/lcov-report/now.js.html @@ -0,0 +1,97 @@ + + + + + + Code coverage report for now.js + + + + + + + + + +
+
+

All files now.js

+
+ +
+ 100% + Statements + 3/3 +
+ + +
+ 100% + Branches + 0/0 +
+ + +
+ 100% + Functions + 0/0 +
+ + +
+ 100% + Lines + 3/3 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+

+
1 +2 +3 +4 +5  +1x +1x +1x + 
"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+const now = new Intl.DateTimeFormat('en-US', { dateStyle: 'medium', timeStyle: 'long' }).format(Date.now());
+exports.default = now;
+//# sourceMappingURL=now.js.map
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/now.ts.html b/server/coverage/lcov-report/now.ts.html new file mode 100644 index 0000000..e841f10 --- /dev/null +++ b/server/coverage/lcov-report/now.ts.html @@ -0,0 +1,88 @@ + + + + + + Code coverage report for now.ts + + + + + + + + + +
+
+

All files now.ts

+
+ +
+ 100% + Statements + 2/2 +
+ + +
+ 100% + Branches + 0/0 +
+ + +
+ 100% + Functions + 0/0 +
+ + +
+ 100% + Lines + 2/2 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+

+
1 +21x +1x
const now = new Intl.DateTimeFormat('en-US', { dateStyle: 'medium', timeStyle: 'long' }).format(Date.now())
+export default now;
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/prettify.css b/server/coverage/lcov-report/prettify.css new file mode 100644 index 0000000..b317a7c --- /dev/null +++ b/server/coverage/lcov-report/prettify.css @@ -0,0 +1 @@ +.pln{color:#000}@media screen{.str{color:#080}.kwd{color:#008}.com{color:#800}.typ{color:#606}.lit{color:#066}.pun,.opn,.clo{color:#660}.tag{color:#008}.atn{color:#606}.atv{color:#080}.dec,.var{color:#606}.fun{color:red}}@media print,projection{.str{color:#060}.kwd{color:#006;font-weight:bold}.com{color:#600;font-style:italic}.typ{color:#404;font-weight:bold}.lit{color:#044}.pun,.opn,.clo{color:#440}.tag{color:#006;font-weight:bold}.atn{color:#404}.atv{color:#060}}pre.prettyprint{padding:2px;border:1px solid #888}ol.linenums{margin-top:0;margin-bottom:0}li.L0,li.L1,li.L2,li.L3,li.L5,li.L6,li.L7,li.L8{list-style-type:none}li.L1,li.L3,li.L5,li.L7,li.L9{background:#eee} diff --git a/server/coverage/lcov-report/prettify.js b/server/coverage/lcov-report/prettify.js new file mode 100644 index 0000000..b322523 --- /dev/null +++ b/server/coverage/lcov-report/prettify.js @@ -0,0 +1,2 @@ +/* eslint-disable */ +window.PR_SHOULD_USE_CONTINUATION=true;(function(){var h=["break,continue,do,else,for,if,return,while"];var u=[h,"auto,case,char,const,default,double,enum,extern,float,goto,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"];var p=[u,"catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"];var l=[p,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,dynamic_cast,explicit,export,friend,inline,late_check,mutable,namespace,nullptr,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"];var x=[p,"abstract,boolean,byte,extends,final,finally,implements,import,instanceof,null,native,package,strictfp,super,synchronized,throws,transient"];var R=[x,"as,base,by,checked,decimal,delegate,descending,dynamic,event,fixed,foreach,from,group,implicit,in,interface,internal,into,is,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var"];var r="all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,true,try,unless,until,when,while,yes";var w=[p,"debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"];var s="caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END";var I=[h,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"];var f=[h,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"];var H=[h,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"];var A=[l,R,w,s+I,f,H];var e=/^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)/;var C="str";var z="kwd";var j="com";var O="typ";var G="lit";var L="pun";var F="pln";var m="tag";var E="dec";var J="src";var P="atn";var n="atv";var N="nocode";var M="(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&&=|&=|\\(|\\*|\\*=|\\+=|\\,|\\-=|\\->|\\/|\\/=|:|::|\\;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|\\?|\\@|\\[|\\^|\\^=|\\^\\^|\\^\\^=|\\{|\\||\\|=|\\|\\||\\|\\|=|\\~|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\\s*";function k(Z){var ad=0;var S=false;var ac=false;for(var V=0,U=Z.length;V122)){if(!(al<65||ag>90)){af.push([Math.max(65,ag)|32,Math.min(al,90)|32])}if(!(al<97||ag>122)){af.push([Math.max(97,ag)&~32,Math.min(al,122)&~32])}}}}af.sort(function(av,au){return(av[0]-au[0])||(au[1]-av[1])});var ai=[];var ap=[NaN,NaN];for(var ar=0;arat[0]){if(at[1]+1>at[0]){an.push("-")}an.push(T(at[1]))}}an.push("]");return an.join("")}function W(al){var aj=al.source.match(new RegExp("(?:\\[(?:[^\\x5C\\x5D]|\\\\[\\s\\S])*\\]|\\\\u[A-Fa-f0-9]{4}|\\\\x[A-Fa-f0-9]{2}|\\\\[0-9]+|\\\\[^ux0-9]|\\(\\?[:!=]|[\\(\\)\\^]|[^\\x5B\\x5C\\(\\)\\^]+)","g"));var ah=aj.length;var an=[];for(var ak=0,am=0;ak=2&&ai==="["){aj[ak]=X(ag)}else{if(ai!=="\\"){aj[ak]=ag.replace(/[a-zA-Z]/g,function(ao){var ap=ao.charCodeAt(0);return"["+String.fromCharCode(ap&~32,ap|32)+"]"})}}}}return aj.join("")}var aa=[];for(var V=0,U=Z.length;V=0;){S[ac.charAt(ae)]=Y}}var af=Y[1];var aa=""+af;if(!ag.hasOwnProperty(aa)){ah.push(af);ag[aa]=null}}ah.push(/[\0-\uffff]/);V=k(ah)})();var X=T.length;var W=function(ah){var Z=ah.sourceCode,Y=ah.basePos;var ad=[Y,F];var af=0;var an=Z.match(V)||[];var aj={};for(var ae=0,aq=an.length;ae=5&&"lang-"===ap.substring(0,5);if(am&&!(ai&&typeof ai[1]==="string")){am=false;ap=J}if(!am){aj[ag]=ap}}var ab=af;af+=ag.length;if(!am){ad.push(Y+ab,ap)}else{var al=ai[1];var ak=ag.indexOf(al);var ac=ak+al.length;if(ai[2]){ac=ag.length-ai[2].length;ak=ac-al.length}var ar=ap.substring(5);B(Y+ab,ag.substring(0,ak),W,ad);B(Y+ab+ak,al,q(ar,al),ad);B(Y+ab+ac,ag.substring(ac),W,ad)}}ah.decorations=ad};return W}function i(T){var W=[],S=[];if(T.tripleQuotedStrings){W.push([C,/^(?:\'\'\'(?:[^\'\\]|\\[\s\S]|\'{1,2}(?=[^\']))*(?:\'\'\'|$)|\"\"\"(?:[^\"\\]|\\[\s\S]|\"{1,2}(?=[^\"]))*(?:\"\"\"|$)|\'(?:[^\\\']|\\[\s\S])*(?:\'|$)|\"(?:[^\\\"]|\\[\s\S])*(?:\"|$))/,null,"'\""])}else{if(T.multiLineStrings){W.push([C,/^(?:\'(?:[^\\\']|\\[\s\S])*(?:\'|$)|\"(?:[^\\\"]|\\[\s\S])*(?:\"|$)|\`(?:[^\\\`]|\\[\s\S])*(?:\`|$))/,null,"'\"`"])}else{W.push([C,/^(?:\'(?:[^\\\'\r\n]|\\.)*(?:\'|$)|\"(?:[^\\\"\r\n]|\\.)*(?:\"|$))/,null,"\"'"])}}if(T.verbatimStrings){S.push([C,/^@\"(?:[^\"]|\"\")*(?:\"|$)/,null])}var Y=T.hashComments;if(Y){if(T.cStyleComments){if(Y>1){W.push([j,/^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/,null,"#"])}else{W.push([j,/^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\r\n]*)/,null,"#"])}S.push([C,/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/,null])}else{W.push([j,/^#[^\r\n]*/,null,"#"])}}if(T.cStyleComments){S.push([j,/^\/\/[^\r\n]*/,null]);S.push([j,/^\/\*[\s\S]*?(?:\*\/|$)/,null])}if(T.regexLiterals){var X=("/(?=[^/*])(?:[^/\\x5B\\x5C]|\\x5C[\\s\\S]|\\x5B(?:[^\\x5C\\x5D]|\\x5C[\\s\\S])*(?:\\x5D|$))+/");S.push(["lang-regex",new RegExp("^"+M+"("+X+")")])}var V=T.types;if(V){S.push([O,V])}var U=(""+T.keywords).replace(/^ | $/g,"");if(U.length){S.push([z,new RegExp("^(?:"+U.replace(/[\s,]+/g,"|")+")\\b"),null])}W.push([F,/^\s+/,null," \r\n\t\xA0"]);S.push([G,/^@[a-z_$][a-z_$@0-9]*/i,null],[O,/^(?:[@_]?[A-Z]+[a-z][A-Za-z_$@0-9]*|\w+_t\b)/,null],[F,/^[a-z_$][a-z_$@0-9]*/i,null],[G,new RegExp("^(?:0x[a-f0-9]+|(?:\\d(?:_\\d+)*\\d*(?:\\.\\d*)?|\\.\\d\\+)(?:e[+\\-]?\\d+)?)[a-z]*","i"),null,"0123456789"],[F,/^\\[\s\S]?/,null],[L,/^.[^\s\w\.$@\'\"\`\/\#\\]*/,null]);return g(W,S)}var K=i({keywords:A,hashComments:true,cStyleComments:true,multiLineStrings:true,regexLiterals:true});function Q(V,ag){var U=/(?:^|\s)nocode(?:\s|$)/;var ab=/\r\n?|\n/;var ac=V.ownerDocument;var S;if(V.currentStyle){S=V.currentStyle.whiteSpace}else{if(window.getComputedStyle){S=ac.defaultView.getComputedStyle(V,null).getPropertyValue("white-space")}}var Z=S&&"pre"===S.substring(0,3);var af=ac.createElement("LI");while(V.firstChild){af.appendChild(V.firstChild)}var W=[af];function ae(al){switch(al.nodeType){case 1:if(U.test(al.className)){break}if("BR"===al.nodeName){ad(al);if(al.parentNode){al.parentNode.removeChild(al)}}else{for(var an=al.firstChild;an;an=an.nextSibling){ae(an)}}break;case 3:case 4:if(Z){var am=al.nodeValue;var aj=am.match(ab);if(aj){var ai=am.substring(0,aj.index);al.nodeValue=ai;var ah=am.substring(aj.index+aj[0].length);if(ah){var ak=al.parentNode;ak.insertBefore(ac.createTextNode(ah),al.nextSibling)}ad(al);if(!ai){al.parentNode.removeChild(al)}}}break}}function ad(ak){while(!ak.nextSibling){ak=ak.parentNode;if(!ak){return}}function ai(al,ar){var aq=ar?al.cloneNode(false):al;var ao=al.parentNode;if(ao){var ap=ai(ao,1);var an=al.nextSibling;ap.appendChild(aq);for(var am=an;am;am=an){an=am.nextSibling;ap.appendChild(am)}}return aq}var ah=ai(ak.nextSibling,0);for(var aj;(aj=ah.parentNode)&&aj.nodeType===1;){ah=aj}W.push(ah)}for(var Y=0;Y=S){ah+=2}if(V>=ap){Z+=2}}}var t={};function c(U,V){for(var S=V.length;--S>=0;){var T=V[S];if(!t.hasOwnProperty(T)){t[T]=U}else{if(window.console){console.warn("cannot override language handler %s",T)}}}}function q(T,S){if(!(T&&t.hasOwnProperty(T))){T=/^\s*]*(?:>|$)/],[j,/^<\!--[\s\S]*?(?:-\->|$)/],["lang-",/^<\?([\s\S]+?)(?:\?>|$)/],["lang-",/^<%([\s\S]+?)(?:%>|$)/],[L,/^(?:<[%?]|[%?]>)/],["lang-",/^]*>([\s\S]+?)<\/xmp\b[^>]*>/i],["lang-js",/^]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\s\S]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i]]),["default-markup","htm","html","mxml","xhtml","xml","xsl"]);c(g([[F,/^[\s]+/,null," \t\r\n"],[n,/^(?:\"[^\"]*\"?|\'[^\']*\'?)/,null,"\"'"]],[[m,/^^<\/?[a-z](?:[\w.:-]*\w)?|\/?>$/i],[P,/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^>\'\"\s]*(?:[^>\'\"\s\/]|\/(?=\s)))/],[L,/^[=<>\/]+/],["lang-js",/^on\w+\s*=\s*\"([^\"]+)\"/i],["lang-js",/^on\w+\s*=\s*\'([^\']+)\'/i],["lang-js",/^on\w+\s*=\s*([^\"\'>\s]+)/i],["lang-css",/^style\s*=\s*\"([^\"]+)\"/i],["lang-css",/^style\s*=\s*\'([^\']+)\'/i],["lang-css",/^style\s*=\s*([^\"\'>\s]+)/i]]),["in.tag"]);c(g([],[[n,/^[\s\S]+/]]),["uq.val"]);c(i({keywords:l,hashComments:true,cStyleComments:true,types:e}),["c","cc","cpp","cxx","cyc","m"]);c(i({keywords:"null,true,false"}),["json"]);c(i({keywords:R,hashComments:true,cStyleComments:true,verbatimStrings:true,types:e}),["cs"]);c(i({keywords:x,cStyleComments:true}),["java"]);c(i({keywords:H,hashComments:true,multiLineStrings:true}),["bsh","csh","sh"]);c(i({keywords:I,hashComments:true,multiLineStrings:true,tripleQuotedStrings:true}),["cv","py"]);c(i({keywords:s,hashComments:true,multiLineStrings:true,regexLiterals:true}),["perl","pl","pm"]);c(i({keywords:f,hashComments:true,multiLineStrings:true,regexLiterals:true}),["rb"]);c(i({keywords:w,cStyleComments:true,regexLiterals:true}),["js"]);c(i({keywords:r,hashComments:3,cStyleComments:true,multilineStrings:true,tripleQuotedStrings:true,regexLiterals:true}),["coffee"]);c(g([],[[C,/^[\s\S]+/]]),["regex"]);function d(V){var U=V.langExtension;try{var S=a(V.sourceNode);var T=S.sourceCode;V.sourceCode=T;V.spans=S.spans;V.basePos=0;q(U,T)(V);D(V)}catch(W){if("console" in window){console.log(W&&W.stack?W.stack:W)}}}function y(W,V,U){var S=document.createElement("PRE");S.innerHTML=W;if(U){Q(S,U)}var T={langExtension:V,numberLines:U,sourceNode:S};d(T);return S.innerHTML}function b(ad){function Y(af){return document.getElementsByTagName(af)}var ac=[Y("pre"),Y("code"),Y("xmp")];var T=[];for(var aa=0;aa=0){var ah=ai.match(ab);var am;if(!ah&&(am=o(aj))&&"CODE"===am.tagName){ah=am.className.match(ab)}if(ah){ah=ah[1]}var al=false;for(var ak=aj.parentNode;ak;ak=ak.parentNode){if((ak.tagName==="pre"||ak.tagName==="code"||ak.tagName==="xmp")&&ak.className&&ak.className.indexOf("prettyprint")>=0){al=true;break}}if(!al){var af=aj.className.match(/\blinenums\b(?::(\d+))?/);af=af?af[1]&&af[1].length?+af[1]:true:false;if(af){Q(aj,af)}S={langExtension:ah,sourceNode:aj,numberLines:af};d(S)}}}if(X]*(?:>|$)/],[PR.PR_COMMENT,/^<\!--[\s\S]*?(?:-\->|$)/],[PR.PR_PUNCTUATION,/^(?:<[%?]|[%?]>)/],["lang-",/^<\?([\s\S]+?)(?:\?>|$)/],["lang-",/^<%([\s\S]+?)(?:%>|$)/],["lang-",/^]*>([\s\S]+?)<\/xmp\b[^>]*>/i],["lang-handlebars",/^]*type\s*=\s*['"]?text\/x-handlebars-template['"]?\b[^>]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-js",/^]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\s\S]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i],[PR.PR_DECLARATION,/^{{[#^>/]?\s*[\w.][^}]*}}/],[PR.PR_DECLARATION,/^{{&?\s*[\w.][^}]*}}/],[PR.PR_DECLARATION,/^{{{>?\s*[\w.][^}]*}}}/],[PR.PR_COMMENT,/^{{![^}]*}}/]]),["handlebars","hbs"]);PR.registerLangHandler(PR.createSimpleLexer([[PR.PR_PLAIN,/^[ \t\r\n\f]+/,null," \t\r\n\f"]],[[PR.PR_STRING,/^\"(?:[^\n\r\f\\\"]|\\(?:\r\n?|\n|\f)|\\[\s\S])*\"/,null],[PR.PR_STRING,/^\'(?:[^\n\r\f\\\']|\\(?:\r\n?|\n|\f)|\\[\s\S])*\'/,null],["lang-css-str",/^url\(([^\)\"\']*)\)/i],[PR.PR_KEYWORD,/^(?:url|rgb|\!important|@import|@page|@media|@charset|inherit)(?=[^\-\w]|$)/i,null],["lang-css-kw",/^(-?(?:[_a-z]|(?:\\[0-9a-f]+ ?))(?:[_a-z0-9\-]|\\(?:\\[0-9a-f]+ ?))*)\s*:/i],[PR.PR_COMMENT,/^\/\*[^*]*\*+(?:[^\/*][^*]*\*+)*\//],[PR.PR_COMMENT,/^(?:)/],[PR.PR_LITERAL,/^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i],[PR.PR_LITERAL,/^#(?:[0-9a-f]{3}){1,2}/i],[PR.PR_PLAIN,/^-?(?:[_a-z]|(?:\\[\da-f]+ ?))(?:[_a-z\d\-]|\\(?:\\[\da-f]+ ?))*/i],[PR.PR_PUNCTUATION,/^[^\s\w\'\"]+/]]),["css"]);PR.registerLangHandler(PR.createSimpleLexer([],[[PR.PR_KEYWORD,/^-?(?:[_a-z]|(?:\\[\da-f]+ ?))(?:[_a-z\d\-]|\\(?:\\[\da-f]+ ?))*/i]]),["css-kw"]);PR.registerLangHandler(PR.createSimpleLexer([],[[PR.PR_STRING,/^[^\)\"\']+/]]),["css-str"]); diff --git a/server/coverage/lcov-report/server/appRoot.ts.html b/server/coverage/lcov-report/server/appRoot.ts.html new file mode 100644 index 0000000..9efd69e --- /dev/null +++ b/server/coverage/lcov-report/server/appRoot.ts.html @@ -0,0 +1,88 @@ + + + + + + Code coverage report for server/appRoot.ts + + + + + + + + + +
+
+

All files / server appRoot.ts

+
+ +
+ 100% + Statements + 2/2 +
+ + +
+ 100% + Branches + 0/0 +
+ + +
+ 100% + Functions + 0/0 +
+ + +
+ 100% + Lines + 2/2 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+

+
1 +21x +1x
import path from 'path';
+export const appRoot = path.resolve(__dirname);
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/server/controllers/CollectionCtl.ts.html b/server/coverage/lcov-report/server/controllers/CollectionCtl.ts.html new file mode 100644 index 0000000..e85de89 --- /dev/null +++ b/server/coverage/lcov-report/server/controllers/CollectionCtl.ts.html @@ -0,0 +1,220 @@ + + + + + + Code coverage report for server/controllers/CollectionCtl.ts + + + + + + + + + +
+
+

All files / server/controllers CollectionCtl.ts

+
+ +
+ 14.28% + Statements + 4/28 +
+ + +
+ 0% + Branches + 0/7 +
+ + +
+ 0% + Functions + 0/6 +
+ + +
+ 17.39% + Lines + 4/23 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+

+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +461x +  +1x +1x +  +1x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + 
import createError from "http-errors";
+import { ICollection } from "../schemas";
+import { Collection } from "../models/collection";
+const CollectionInstance = new Collection();
+ 
+export default class CollectionCtl {
+    async getOne(id: number | string) {
+        const result = await CollectionInstance.getOne(id);
+        Iif (!result) throw createError('404', 'Collection not found');
+        return result;
+    }
+ 
+    async getAll() {
+        const result = await CollectionInstance.getAll();
+        Iif (!result) throw createError('404', 'No collections found');
+        return result;
+    }
+ 
+    async getUserDefault(id: number | string) {
+        const result = await CollectionInstance.getUserDefault(id);
+        Iif (!result) throw createError('404', "No default collection found. Contact an admin, this isn't supposed to happen");
+        return result;
+    }
+    
+    async post(data: ICollection) {
+        const result = await CollectionInstance.post(data);
+        Iif (!result) throw createError('400', 'Bad request');
+        return result;
+    }
+ 
+    async getSubscriptions(userid: number | string) {
+        const result = await CollectionInstance.getSubscriptions(userid);
+        Iif (!result) throw createError('404', 'No subscriptions found');
+        return result;
+    }
+ 
+    async postSubscription(collectionid: number | string, userid: number | string) {
+        const { ok, code, data } = await CollectionInstance.postSubscription(collectionid, userid);
+        
+        if (ok) {
+            return data;
+        } else {
+            throw createError(code, data as string);
+        }
+    }
+}
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/server/controllers/CourseCtl.ts.html b/server/coverage/lcov-report/server/controllers/CourseCtl.ts.html new file mode 100644 index 0000000..532437c --- /dev/null +++ b/server/coverage/lcov-report/server/controllers/CourseCtl.ts.html @@ -0,0 +1,190 @@ + + + + + + Code coverage report for server/controllers/CourseCtl.ts + + + + + + + + + +
+
+

All files / server/controllers CourseCtl.ts

+
+ +
+ 18.18% + Statements + 4/22 +
+ + +
+ 0% + Branches + 0/3 +
+ + +
+ 0% + Functions + 0/3 +
+ + +
+ 21.05% + Lines + 4/19 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+

+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +361x +  +1x +1x +  +1x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + 
import createError from 'http-errors';
+import { ICourse } from '../schemas';
+import Course from '../models/course';
+const CourseInstance = new Course();
+ 
+export default class CourseCtl {
+    async getAll() {
+        try {
+            const result = await CourseInstance.getAll();
+            Iif (!result) throw createError('404', 'No cuisines found');
+            return result;
+        } catch (e: any) {
+            throw new Error(e);
+        }
+    }
+ 
+    async getOne(id: string) {
+        try {
+            const result = await CourseInstance.getOne(id);
+            Iif (!result) throw createError('404', 'No cuisine found with id ' + id);
+            return result;
+        } catch (e: any) {
+            throw new Error(e);
+        }
+    }
+ 
+    async post(data: ICourse) {
+        try {
+            const result = await CourseInstance.post(data);
+            Iif (!result) throw createError('400', 'Bad request');
+            return result;
+        } catch (e: any) {
+            throw new Error(e);
+        }
+    }
+}
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/server/controllers/CuisineCtl.ts.html b/server/coverage/lcov-report/server/controllers/CuisineCtl.ts.html new file mode 100644 index 0000000..7ad8a38 --- /dev/null +++ b/server/coverage/lcov-report/server/controllers/CuisineCtl.ts.html @@ -0,0 +1,190 @@ + + + + + + Code coverage report for server/controllers/CuisineCtl.ts + + + + + + + + + +
+
+

All files / server/controllers CuisineCtl.ts

+
+ +
+ 18.18% + Statements + 4/22 +
+ + +
+ 0% + Branches + 0/3 +
+ + +
+ 0% + Functions + 0/3 +
+ + +
+ 21.05% + Lines + 4/19 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+

+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +361x +  +1x +1x +  +1x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + 
import createError from "http-errors";
+import { ICuisine } from "../schemas";
+import Cuisine from "../models/cuisine";
+const CuisineInstance = new Cuisine();
+ 
+export default class CuisineCtl {
+    async getAll() {
+        try {
+            const result = await CuisineInstance.getAll();
+            Iif (!result) throw createError('404', 'No cuisines found');
+            return result;
+        } catch (e: any) {
+            throw new Error(e);
+        }
+    }
+ 
+    async getOne(id: string) {
+        try {
+            const result = await CuisineInstance.getOne(id);
+            Iif (!result) throw createError('404', 'No cuisine found with id ' + id);
+            return result;
+        } catch (e: any) {
+            throw new Error(e);
+        }
+    }
+ 
+    async post(data: ICuisine) {
+        try {
+            const result = await CuisineInstance.post(data);
+            Iif (!result) throw createError('400', 'Bad request');
+            return result;
+        } catch (e: any) {
+            throw new Error(e);
+        }
+    }
+}
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/server/controllers/GroceryListCtl.ts.html b/server/coverage/lcov-report/server/controllers/GroceryListCtl.ts.html new file mode 100644 index 0000000..0425e13 --- /dev/null +++ b/server/coverage/lcov-report/server/controllers/GroceryListCtl.ts.html @@ -0,0 +1,250 @@ + + + + + + Code coverage report for server/controllers/GroceryListCtl.ts + + + + + + + + + +
+
+

All files / server/controllers GroceryListCtl.ts

+
+ +
+ 11.76% + Statements + 4/34 +
+ + +
+ 0% + Branches + 0/5 +
+ + +
+ 0% + Functions + 0/5 +
+ + +
+ 13.79% + Lines + 4/29 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+

+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +561x +  +1x +1x +  +1x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + 
import createError from "http-errors";
+import { IGroceryList } from "../schemas";
+import { GroceryList } from "../models/groceryList";
+const GroceryInstance = new GroceryList();
+ 
+export default class GroceryListCtl {
+    async getAll() {
+        try {
+            const result = await GroceryInstance.getAll();
+            Iif (!result) throw createError('404', 'No results found');
+            return result;
+        } catch (e: any) {
+            throw new Error(e);
+        }
+    }
+ 
+    async getOne(id: string) {
+        try {
+            const result = await GroceryInstance.getOne(id);
+            Iif (!result) throw createError('404', 'No results found');
+            return result;
+        } catch (e: any) {
+            throw new Error(e);
+        }
+    }
+ 
+    async getByUserID(userid: string) {
+        try {
+            const result = await GroceryInstance.getByUserID(userid);
+            Iif (!result) throw createError('404', 'No results found');
+            return result;
+        } catch (e: any) {
+            throw new Error(e);
+        }
+    }
+ 
+    async post(data: IGroceryList) {
+        try {
+            const result = await GroceryInstance.post(data);
+            Iif (!result) throw createError('400', 'Bad request');
+            return result;
+        } catch (e: any) {
+            throw new Error(e);
+        }
+    }
+ 
+    async put(id: string, data: IGroceryList) {
+        try {
+            const result = await GroceryInstance.put(id, data);
+            Iif (!result) throw createError('400', 'Bad request');
+            return result;
+        } catch (e: any) {
+            throw new Error(e);
+        }
+    }
+}
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/server/controllers/IngredientCtl.ts.html b/server/coverage/lcov-report/server/controllers/IngredientCtl.ts.html new file mode 100644 index 0000000..1482c11 --- /dev/null +++ b/server/coverage/lcov-report/server/controllers/IngredientCtl.ts.html @@ -0,0 +1,220 @@ + + + + + + Code coverage report for server/controllers/IngredientCtl.ts + + + + + + + + + +
+
+

All files / server/controllers IngredientCtl.ts

+
+ +
+ 14.28% + Statements + 4/28 +
+ + +
+ 0% + Branches + 0/4 +
+ + +
+ 0% + Functions + 0/4 +
+ + +
+ 16.66% + Lines + 4/24 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+

+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +461x +  +1x +1x +  +1x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + 
import createError from "http-errors";
+import { IIngredient } from "../schemas";
+import { Ingredient } from "../models/ingredient";
+const IngredientInstance = new Ingredient();
+ 
+export default class IngredientCtl {
+    async getAll() {
+        try {
+            const result = await IngredientInstance.getAll();
+            Iif (!result) throw createError('404', 'No ingredients found');
+            return result;
+        } catch (e: any) {
+            throw new Error(e);
+        }
+    }
+ 
+    async getOne(id: string) {
+        try {
+            const result = await IngredientInstance.getOne(id);
+            Iif (!result) throw createError('404', 'No ingredient found with id ' + id);
+            return result;
+        } catch (e: any) {
+            throw new Error(e);
+        }
+    }
+ 
+    async post(data: IIngredient) {
+        try {
+            const result = await IngredientInstance.post(data);
+            Iif (!result) throw createError('400', 'Bad request');
+            return result;
+        } catch (e: any) {
+            throw new Error(e);
+        }
+    }
+ 
+    async put(id: string, data: IIngredient) {
+        try {
+            const result = await IngredientInstance.put(id, data);
+            Iif (!result) throw createError('400', 'Bad request');
+            return result;
+        } catch (e: any) {
+            throw new Error(e);
+        }
+    }
+}
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/server/controllers/RecipeCtl.ts.html b/server/coverage/lcov-report/server/controllers/RecipeCtl.ts.html new file mode 100644 index 0000000..b81bc42 --- /dev/null +++ b/server/coverage/lcov-report/server/controllers/RecipeCtl.ts.html @@ -0,0 +1,244 @@ + + + + + + Code coverage report for server/controllers/RecipeCtl.ts + + + + + + + + + +
+
+

All files / server/controllers RecipeCtl.ts

+
+ +
+ 13.33% + Statements + 4/30 +
+ + +
+ 0% + Branches + 0/4 +
+ + +
+ 0% + Functions + 0/5 +
+ + +
+ 15.38% + Lines + 4/26 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+

+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +541x +  +1x +1x +  +1x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + 
import createError from "http-errors";
+import { IRecipe } from "../schemas";
+import { Recipe } from "../models/recipe";
+const RecipeInstance = new Recipe();
+ 
+export default class RecipeCtl {
+    async getOne(id: string) {
+        try {
+            const result = await RecipeInstance.getOneByID(id);
+            Iif (!result) throw createError('404', "Recipe not found");
+            return result;
+        } catch (error: any) {
+            throw new Error(error);
+        }
+    }
+ 
+    async getAllAuthored(id: string) {
+        try {
+            const result = await RecipeInstance.getAllAuthored(id);
+            Iif (!result) throw createError('404', "No recipes found");
+            return result;
+        } catch (e: any) {
+            throw new Error(e);
+        }
+    }
+ 
+    async getAllAccessible(id: string) {
+        try {
+            
+        } catch (e: any) {
+            throw new Error(e);
+        }
+    }
+ 
+    async updateOne(id: string, data: IRecipe) {
+        try {
+            const result = await RecipeInstance.updateOneByID(id, data);
+            Iif (!result) throw createError('400', "Bad request");
+            return result;
+        } catch (error: any) {
+            throw new Error(error);
+        }
+    }
+ 
+    async post(userid: string, data: IRecipe) {
+        try {
+            const result = await RecipeInstance.post(userid, data);
+            Iif (!result) throw createError('400', "Bad request");
+            return result;
+        } catch (error: any) {
+            throw new Error(error);
+        }
+    }
+}
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/server/controllers/UserCtl.ts.html b/server/coverage/lcov-report/server/controllers/UserCtl.ts.html new file mode 100644 index 0000000..507c601 --- /dev/null +++ b/server/coverage/lcov-report/server/controllers/UserCtl.ts.html @@ -0,0 +1,370 @@ + + + + + + Code coverage report for server/controllers/UserCtl.ts + + + + + + + + + +
+
+

All files / server/controllers UserCtl.ts

+
+ +
+ 7.14% + Statements + 4/56 +
+ + +
+ 0% + Branches + 0/8 +
+ + +
+ 0% + Functions + 0/9 +
+ + +
+ 8.33% + Lines + 4/48 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+

+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 +89 +90 +91 +92 +93 +94 +95 +961x +  +1x +1x +  +1x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + 
import createError from 'http-errors';
+import { IUser } from '../schemas';
+import { User } from "../models/user";
+const UserInstance = new User();
+ 
+export default class UserCtl {
+    async getAll() {
+        try {
+            const users = await UserInstance.getAllUsers();
+            Iif (!users) throw createError(404, "No users found");
+            return users;
+        } catch (error: any) {
+            throw new Error(error);
+        }
+    }
+ 
+    async post(data: IUser) {
+        try {
+            const response = await UserInstance.post(data);
+            // if (!response) throw createError(400, "Bad request");
+            return response;
+        } catch (error: any) {
+            throw new Error(error);
+        }
+    }
+ 
+    async getOne(id: number | string) {
+        try {
+            const user = await UserInstance.getOneByID(id);
+            Iif (!user) throw createError(404, "User not found");
+            return user;
+        } catch (error: any) {
+            throw new Error(error);
+        }
+    }
+ 
+    async updateOne(id: number | string, data: IUser) {
+        try {
+            const result = await UserInstance.updateOneByID(id, data);
+            Iif (!result) throw createError(400, "Bad request");
+            return result;
+        } catch (error: any) {
+            throw new Error(error);
+        }
+    }
+ 
+    async getFriends(id: number | string) {
+        try {
+            const result = await UserInstance.getFriends(id);
+            Iif (!result) return createError(404, "You have no friends");
+            return result;
+        } catch (e: any) {
+            throw new Error(e);
+        }
+    }
+ 
+    async getFriendshipByID(id: number | string, userid: number | string) {
+        try {
+            const { ok, code, result } = await UserInstance.getFriendshipByID(id, userid);
+            Iif (ok) return result;
+            throw createError(code, result);
+        } catch (e: any) {
+            throw new Error(e);
+        }
+    }
+ 
+    async getPendingFriendRequests(senderid: string | number) {
+        try {
+            const { ok, code, result } = await UserInstance.getPendingFriendRequests(senderid);
+            Iif (ok) return result;
+            throw createError(code, result);
+        } catch (e: any) {
+            throw new Error(e);
+        }
+    }
+ 
+    async addFriendship(userid: number | string, targetid: number | string) {
+        try {
+            const result = await UserInstance.addFriendship(userid, targetid);
+            Iif (!result) throw createError(400, "something went wrong");
+            return result;
+        } catch (e: any) {
+            throw new Error(e);
+        }
+    }
+ 
+    async updateFriendship(id: number | string, userid: number | string, data: { active: boolean, pending: boolean, dateterminated?: string }) {
+        try {
+            const { ok, code, result } = await UserInstance.updateFriendship(id, userid, data);
+            Iif (ok) return result;
+            throw createError(code, result);
+        } catch (e: any) {
+            throw new Error(e);
+        }
+    }
+}
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/server/controllers/index.html b/server/coverage/lcov-report/server/controllers/index.html new file mode 100644 index 0000000..25e430e --- /dev/null +++ b/server/coverage/lcov-report/server/controllers/index.html @@ -0,0 +1,221 @@ + + + + + + Code coverage report for server/controllers + + + + + + + + + +
+
+

All files server/controllers

+
+ +
+ 17.94% + Statements + 42/234 +
+ + +
+ 0% + Branches + 0/34 +
+ + +
+ 0% + Functions + 0/35 +
+ + +
+ 18.36% + Lines + 36/196 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileStatementsBranchesFunctionsLines
CollectionCtl.ts +
+
14.28%4/280%0/70%0/617.39%4/23
CourseCtl.ts +
+
18.18%4/220%0/30%0/321.05%4/19
CuisineCtl.ts +
+
18.18%4/220%0/30%0/321.05%4/19
GroceryListCtl.ts +
+
11.76%4/340%0/50%0/513.79%4/29
IngredientCtl.ts +
+
14.28%4/280%0/40%0/416.66%4/24
RecipeCtl.ts +
+
13.33%4/300%0/40%0/515.38%4/26
UserCtl.ts +
+
7.14%4/560%0/80%0/98.33%4/48
index.ts +
+
100%14/14100%0/0100%0/0100%8/8
+
+
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/server/controllers/index.ts.html b/server/coverage/lcov-report/server/controllers/index.ts.html new file mode 100644 index 0000000..e09d2d0 --- /dev/null +++ b/server/coverage/lcov-report/server/controllers/index.ts.html @@ -0,0 +1,115 @@ + + + + + + Code coverage report for server/controllers/index.ts + + + + + + + + + +
+
+

All files / server/controllers index.ts

+
+ +
+ 100% + Statements + 14/14 +
+ + +
+ 100% + Branches + 0/0 +
+ + +
+ 100% + Functions + 0/0 +
+ + +
+ 100% + Lines + 8/8 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+

+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +111x +1x +1x +1x +1x +1x +1x +  +  +1x + 
import CollectionCtl from "./CollectionCtl";
+import CuisineCtl from "./CuisineCtl";
+import GroceryListCtl from "./GroceryListCtl";
+import IngredientCtl from "./IngredientCtl";
+import RecipeCtl from "./RecipeCtl";
+import UserCtl from "./UserCtl";
+import CourseCtl from "./CourseCtl";
+ 
+export {
+    CollectionCtl, CuisineCtl, CourseCtl, GroceryListCtl, IngredientCtl, RecipeCtl, UserCtl
+}
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/server/db/index.html b/server/coverage/lcov-report/server/db/index.html new file mode 100644 index 0000000..a9a125d --- /dev/null +++ b/server/coverage/lcov-report/server/db/index.html @@ -0,0 +1,116 @@ + + + + + + Code coverage report for server/db + + + + + + + + + +
+
+

All files server/db

+
+ +
+ 100% + Statements + 5/5 +
+ + +
+ 100% + Branches + 0/0 +
+ + +
+ 100% + Functions + 0/0 +
+ + +
+ 100% + Lines + 5/5 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileStatementsBranchesFunctionsLines
index.ts +
+
100%5/5100%0/0100%0/0100%5/5
+
+
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/server/db/index.ts.html b/server/coverage/lcov-report/server/db/index.ts.html new file mode 100644 index 0000000..c62ae98 --- /dev/null +++ b/server/coverage/lcov-report/server/db/index.ts.html @@ -0,0 +1,100 @@ + + + + + + Code coverage report for server/db/index.ts + + + + + + + + + +
+
+

All files / server/db index.ts

+
+ +
+ 100% + Statements + 5/5 +
+ + +
+ 100% + Branches + 0/0 +
+ + +
+ 100% + Functions + 0/0 +
+ + +
+ 100% + Lines + 5/5 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+

+
1 +2 +3 +4 +5 +61x +1x +1x +  +1x +1x
import { Pool } from 'pg';
+import dotenv from 'dotenv';
+dotenv.config();
+ 
+const pool = new Pool({ connectionString: process.env.CONSTRING });
+export default pool;
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/server/index.html b/server/coverage/lcov-report/server/index.html new file mode 100644 index 0000000..85af95d --- /dev/null +++ b/server/coverage/lcov-report/server/index.html @@ -0,0 +1,116 @@ + + + + + + Code coverage report for server + + + + + + + + + +
+
+

All files server

+
+ +
+ 100% + Statements + 2/2 +
+ + +
+ 100% + Branches + 0/0 +
+ + +
+ 100% + Functions + 0/0 +
+ + +
+ 100% + Lines + 2/2 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileStatementsBranchesFunctionsLines
appRoot.ts +
+
100%2/2100%0/0100%0/0100%2/2
+
+
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/server/models/collection.ts.html b/server/coverage/lcov-report/server/models/collection.ts.html new file mode 100644 index 0000000..dcc586a --- /dev/null +++ b/server/coverage/lcov-report/server/models/collection.ts.html @@ -0,0 +1,547 @@ + + + + + + Code coverage report for server/models/collection.ts + + + + + + + + + +
+
+

All files / server/models collection.ts

+
+ +
+ 10.14% + Statements + 7/69 +
+ + +
+ 0% + Branches + 0/21 +
+ + +
+ 0% + Functions + 0/6 +
+ + +
+ 10.93% + Lines + 7/64 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+

+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 +89 +90 +91 +92 +93 +94 +95 +96 +97 +98 +99 +100 +101 +102 +103 +104 +105 +106 +107 +108 +109 +110 +111 +112 +113 +114 +115 +116 +117 +118 +119 +120 +121 +122 +123 +124 +125 +126 +127 +128 +129 +130 +131 +132 +133 +134 +135 +136 +137 +138 +139 +140 +141 +142 +143 +144 +145 +146 +147 +148 +149 +150 +151 +152 +153 +154 +155  +1x +1x +1x +1x +1x +1x +1x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + 
import { ICollection, IUser } from "../schemas";
+import { User } from "./user";
+import { appRoot } from "../appRoot";
+import now from "../util/now";
+import pool from "../db";
+import fs from 'fs';
+const UserInstance = new User();
+export class Collection {
+    async getOne(id: number | string) {
+        try {
+            const statement = `SELECT * FROM recipin.collection WHERE id = $1`;
+            const values = [id];
+            const result = await pool.query(statement, values);
+            Iif (result.rows.length) return result.rows[0];
+            return null;
+        } catch (e: any) {
+            throw new Error(e);
+        }
+    }
+ 
+    async getUserDefault(id: number | string) {
+        try {
+            const statement = `
+                SELECT * FROM recipin.collection
+                WHERE ownerid = $1
+                AND ismaincollection = true;
+            `
+            const result = await pool.query(statement, [id]);
+            Iif (result.rows.length) return result.rows[0];
+            return null;
+        } catch (e: any) {
+            throw new Error(e);
+        }
+    }
+ 
+    async getAll() {
+        // requires clearance
+        try {
+            const statement = `SELECT * FROM recipin.collection`;
+            const result = await pool.query(statement);
+            Iif (result.rows.length) return result.rows;
+            return null;
+        } catch (e: any) {
+            throw new Error(e);
+        }
+    }
+ 
+    async post(data: ICollection) {
+        console.log('new default collection');
+        const { name, active, ismaincollection, ownerid } = data;
+        try {
+            const statement = `
+                INSERT INTO recipin.collection
+                    (name, active, ismaincollection, ownerid, datecreated, datemodified)
+                VALUES ($1, $2, $3, $4, $5, $6)
+                RETURNING *;
+            `
+            const values = [name, (active || true), (ismaincollection || false), ownerid, now, now];
+            const result = await pool.query(statement, values);
+            Iif (result.rows.length) return result.rows;
+            return null;
+        } catch (e: any) {
+            throw new Error(e);
+        }
+    }
+ 
+    async getSubscriptions(userid: number | string) {
+        try {
+            const sql = fs.readFileSync(appRoot + '/db/sql/get/getsubscriptions.sql').toString();
+            console.log(sql);
+            const result = await pool.query(sql, [userid]);
+            Iif (result.rows.length) return result.rows;
+            return null;
+        } catch (e: any) {
+            throw new Error(e);
+        }
+    }
+ 
+    async postSubscription(collectionid: number | string, userid: number | string): Promise<{ ok: boolean, code: number, data: number | string | any[] }> {
+        try {
+            // ensure user exists
+            const user: IUser | null = await UserInstance.getOneByID(userid);
+            Iif (!user) {
+                return {
+                    ok: false,
+                    code: 404,
+                    data: "User not found"
+                }
+            }
+ 
+            // ensure collection exists
+            const target: ICollection | null = await this.getOne(collectionid);
+            Iif (!target) {
+                return {
+                    ok: false,
+                    code: 404,
+                    data: "Collection not found"
+                }
+            }
+ 
+            // ensure a user cannot subscribe to their own collection
+            let typedUserID: number = (userid == typeof 'string') ? parseInt(userid) : userid as number;
+            Iif (target.ownerid == typedUserID) {
+                return {
+                    ok: false,
+                    code: 403,
+                    data: "User cannot subscribe to their own collection"
+                }
+            }
+ 
+            // ensure a duplicate subscription does not exist
+            const allSubscriptions = `
+                SELECT * FROM recipin.cmp_usersubscriptions
+                WHERE collectionid = $1;
+            `
+            const subscriptionResult = await pool.query(allSubscriptions, [collectionid]);
+            Iif (subscriptionResult.rows?.length) {
+                for (let row of subscriptionResult.rows) {
+                    Iif (row.usermemberid == typedUserID) {
+                        return {
+                            ok: false,
+                            code: 403,
+                            data: "This user is already subscribed"
+                        }
+                    } 
+                }
+            }
+ 
+            // finally, execute insertion
+            const statement = `
+                INSERT INTO recipin.cmp_usersubscriptions
+                    (collectionid, usermemberid, active)
+                VALUES ($1, $2, true)
+                RETURNING *;
+            `
+ 
+            const result = await pool.query(statement, [collectionid, userid]);
+            Iif (result.rows.length) {
+                return {
+                    ok: true,
+                    code: 201,
+                    data: result.rows
+                }
+            }
+ 
+            return {
+                ok: false,
+                code: 400,
+                data: "Bad request. No data returned."
+            }
+        } catch (e: any) {
+            throw new Error(e);
+        }
+    }
+}
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/server/models/course.ts.html b/server/coverage/lcov-report/server/models/course.ts.html new file mode 100644 index 0000000..013b28e --- /dev/null +++ b/server/coverage/lcov-report/server/models/course.ts.html @@ -0,0 +1,214 @@ + + + + + + Code coverage report for server/models/course.ts + + + + + + + + + +
+
+

All files / server/models course.ts

+
+ +
+ 11.11% + Statements + 3/27 +
+ + +
+ 0% + Branches + 0/3 +
+ + +
+ 0% + Functions + 0/3 +
+ + +
+ 12.5% + Lines + 3/24 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+

+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +441x +1x +  +  +1x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + 
import now from "../util/now";
+import pool from "../db";
+import { ICourse } from "../schemas";
+ 
+export default class Course {
+    async getOne(id: string) {
+        try {
+            const statement = `SELECT * FROM recipin.course WHERE id = $1`;
+            const values = [id];
+            const result = await pool.query(statement, values);
+            Iif (result.rows) return result.rows[0];
+            return null;
+        } catch (error: any) {
+            throw new Error(error);
+        }
+    }
+ 
+    async getAll() {
+        try {
+            const statement = `SELECT * FROM recipin.course`;
+            const result = await pool.query(statement);
+            Iif (result.rows.length) return result.rows;
+            return null;
+        } catch (e: any) {
+            throw new Error(e);
+        }
+    }
+ 
+    async post(data: ICourse) {
+        try {
+            const { name } = data;
+            const statement = `
+            INSERT INTO recipin.course
+                (name, datecreated, datemodified, active)
+            VALUES ($1, $2, $3, $4) RETURNING *`;
+            const values = [name, now, now, true];
+            const result = await pool.query(statement, values);
+            Iif (result.rows.length) return result.rows[0];
+            return null;
+        } catch (e: any) {
+            throw new Error(e);
+        }
+    }
+}
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/server/models/cuisine.ts.html b/server/coverage/lcov-report/server/models/cuisine.ts.html new file mode 100644 index 0000000..b9e2d03 --- /dev/null +++ b/server/coverage/lcov-report/server/models/cuisine.ts.html @@ -0,0 +1,214 @@ + + + + + + Code coverage report for server/models/cuisine.ts + + + + + + + + + +
+
+

All files / server/models cuisine.ts

+
+ +
+ 11.11% + Statements + 3/27 +
+ + +
+ 0% + Branches + 0/3 +
+ + +
+ 0% + Functions + 0/3 +
+ + +
+ 12.5% + Lines + 3/24 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+

+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +441x +1x +  +  +1x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + 
import pool from "../db";
+import now from "../util/now";
+import { ICuisine } from "../schemas";
+ 
+export default class Cuisine {
+    async getOne(id: string) {
+        try {
+            const statement = `SELECT * FROM recipin.cuisine WHERE id = $1`;
+            const values = [id];
+            const result = await pool.query(statement, values);
+            Iif (result.rows) return result.rows[0];
+            return null;
+        } catch (error: any) {
+            throw new Error(error);
+        }
+    }
+ 
+    async getAll() {
+        try {
+            const statement = `SELECT * FROM recipin.cuisine`;
+            const result = await pool.query(statement);
+            Iif (result.rows.length) return result.rows;
+            return null;
+        } catch (e: any) {
+            throw new Error(e);
+        }
+    }
+ 
+    async post(data: ICuisine) {
+        try {
+            const { name } = data;
+            const statement = `
+            INSERT INTO recipin.cuisine
+                (name, datecreated, datemodified, active)
+            VALUES ($1, $2, $3, $4) RETURNING *`;
+            const values = [name, now, now, true];
+            const result = await pool.query(statement, values);
+            Iif (result.rows.length) return result.rows[0];
+            return null;
+        } catch (e: any) {
+            throw new Error(e);
+        }
+    }
+}
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/server/models/groceryList.ts.html b/server/coverage/lcov-report/server/models/groceryList.ts.html new file mode 100644 index 0000000..7847c5d --- /dev/null +++ b/server/coverage/lcov-report/server/models/groceryList.ts.html @@ -0,0 +1,307 @@ + + + + + + Code coverage report for server/models/groceryList.ts + + + + + + + + + +
+
+

All files / server/models groceryList.ts

+
+ +
+ 5.12% + Statements + 2/39 +
+ + +
+ 0% + Branches + 0/5 +
+ + +
+ 0% + Functions + 0/5 +
+ + +
+ 5.88% + Lines + 2/34 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+

+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75  +1x +  +1x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + 
import { IGroceryList } from "../schemas";
+import pool from "../db";
+ 
+export class GroceryList {
+    async getAll() {
+        try {
+            const statement = 'SELECT * FROM recipin.grocerylist';
+            const result = await pool.query(statement);
+            Iif (result.rows.length) return result.rows;
+            return null;
+        } catch (e: any) {
+            throw new Error(e);
+        }
+    }
+ 
+    async getOne(id: string) {
+        try {
+            const statement = `SELECT * FROM recipin.grocerylist WHERE id = $1`
+            const result = await pool.query(statement, [id]);
+            Iif (result.rows.length) return result.rows[0];
+            return null;
+        } catch (e: any) {
+            throw new Error(e);
+        }
+    }
+ 
+    async getByUserID(userid: string) {
+        try {
+            const statement = `SELECT * FROM recipin.grocerylist WHERE ownerid = $1`
+            const result = await pool.query(statement, [userid]);
+            Iif (result.rows.length) return result.rows;
+            return null;
+        } catch (e: any) {
+            throw new Error(e);
+        }
+    }
+ 
+    async post(data: IGroceryList) {
+        try {
+            // assumes that any new list will be active on creation
+            const statement = `
+                INSERT INTO recipin.grocerylist
+                    (name, active, ownerid)
+                VALUES ($1, true, $2)
+                RETURNING *;
+            `
+            const values = [data.name, data.ownerid];
+            const result = await pool.query(statement, values);
+            Iif (result.rows.length) return result.rows[0];
+            return null;
+        } catch (e: any) {
+            throw new Error(e);
+        }
+    }
+ 
+    async put(id: string, data: IGroceryList) {
+        try {
+            const statement = `
+                UPDATE recipin.grocerylist
+                SET name = $1,
+                    active = $2,
+                    ownerid = $3
+                WHERE id = $4
+                RETURNING *
+            `
+            const values = [data.name, data.active, data.ownerid, id];
+ 
+            const result = await pool.query(statement, values);
+            Iif (result.rows.length) return result.rows[0];
+            return null;
+        } catch (e: any) {
+            throw new Error(e);
+        }
+    }
+}
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/server/models/index.html b/server/coverage/lcov-report/server/models/index.html new file mode 100644 index 0000000..fd80715 --- /dev/null +++ b/server/coverage/lcov-report/server/models/index.html @@ -0,0 +1,206 @@ + + + + + + Code coverage report for server/models + + + + + + + + + +
+
+

All files server/models

+
+ +
+ 8.4% + Statements + 28/333 +
+ + +
+ 0% + Branches + 0/63 +
+ + +
+ 0% + Functions + 0/37 +
+ + +
+ 9.39% + Lines + 28/298 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileStatementsBranchesFunctionsLines
collection.ts +
+
10.14%7/690%0/210%0/610.93%7/64
course.ts +
+
11.11%3/270%0/30%0/312.5%3/24
cuisine.ts +
+
11.11%3/270%0/30%0/312.5%3/24
groceryList.ts +
+
5.12%2/390%0/50%0/55.88%2/34
ingredient.ts +
+
9.09%3/330%0/60%0/410.34%3/29
recipe.ts +
+
11.36%5/440%0/50%0/612.82%5/39
user.ts +
+
5.31%5/940%0/200%0/105.95%5/84
+
+
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/server/models/ingredient.ts.html b/server/coverage/lcov-report/server/models/ingredient.ts.html new file mode 100644 index 0000000..417f04a --- /dev/null +++ b/server/coverage/lcov-report/server/models/ingredient.ts.html @@ -0,0 +1,265 @@ + + + + + + Code coverage report for server/models/ingredient.ts + + + + + + + + + +
+
+

All files / server/models ingredient.ts

+
+ +
+ 9.09% + Statements + 3/33 +
+ + +
+ 0% + Branches + 0/6 +
+ + +
+ 0% + Functions + 0/4 +
+ + +
+ 10.34% + Lines + 3/29 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+

+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61  +1x +1x +  +1x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + 
import { IIngredient } from "../schemas";
+import pool from "../db";
+import now from "../util/now";
+ 
+export class Ingredient {
+    async getAll() {
+        try {
+            const statement = `SELECT * FROM recipin.ingredient`;
+            const result = await pool.query(statement);
+            Iif (result.rows.length) return result.rows;
+            return null;
+        } catch (e: any) {
+            throw new Error(e);
+        }
+    }
+ 
+    async getOne(id: string) {
+        try {
+            const statement = `SELECT * FROM recipin.ingredient WHERE id = $1`;
+            const result = await pool.query(statement, [id]);
+            Iif (result.rows.length) return result.rows[0];
+            return null;
+        } catch (e: any) {
+            throw new Error(e);
+        }
+    }
+ 
+    async post(data: IIngredient) {
+        try {
+            const statement = `
+            INSERT INTO recipin.ingredient
+                (name, description, datecreated)
+            VALUES ($1, $2, $3) RETURNING *`;
+            const values = [data.name, data.description, data.datecreated || now];
+            const result = await pool.query(statement, values);
+            Iif (result.rows.length) return result.rows[0];
+            return null;
+        } catch (e: any) {
+            throw new Error(e);
+        }
+    }
+ 
+    async put(id: string, data: IIngredient) {
+        try {
+            const statement = `
+            UPDATE recipin.ingredient
+            SET name = $1,
+                description = $2
+            WHERE id = $3
+            RETURNING *
+            `
+    
+            const values = [data.name, data.description, id];
+            const result = await pool.query(statement, values);
+            Iif (result.rows.length) return result.rows[0];
+            return null;
+        } catch (e: any) {
+            throw new Error(e);
+        }
+    }
+}
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/server/models/recipe.ts.html b/server/coverage/lcov-report/server/models/recipe.ts.html new file mode 100644 index 0000000..3ae8426 --- /dev/null +++ b/server/coverage/lcov-report/server/models/recipe.ts.html @@ -0,0 +1,361 @@ + + + + + + Code coverage report for server/models/recipe.ts + + + + + + + + + +
+
+

All files / server/models recipe.ts

+
+ +
+ 11.36% + Statements + 5/44 +
+ + +
+ 0% + Branches + 0/5 +
+ + +
+ 0% + Functions + 0/6 +
+ + +
+ 12.82% + Lines + 5/39 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+

+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 +89 +90 +91 +92 +93  +1x +1x +1x +1x +  +1x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + 
import { IRecipe } from "../schemas";
+import pool from "../db";
+import { CollectionCtl } from "../controllers";
+import now from "../util/now";
+const CollectionInstance = new CollectionCtl();
+ 
+export class Recipe {
+    async getOneByID(id: string) {
+        try {
+            const statement = `SELECT * FROM recipin.recipe WHERE id = $1`;
+            const values = [id];
+            const result = await pool.query(statement, values);
+            Iif (result.rows) return result.rows[0];
+            return null;
+        } catch (error: any) {
+            throw new Error(error);
+        }
+    }
+ 
+    async getAllAuthored(id: string) {
+        try {
+            const statement = `SELECT * FROM recipin.recipe WHERE authoruserid = $1`;
+            const result = await pool.query(statement, [id]);
+            Iif (result.rows.length) return result.rows;
+            return null;
+        } catch (e: any) {
+            throw new Error(e);
+        }
+    }
+ 
+    async getAllAccessible(id: string) {
+ 
+    }
+ 
+    async fetchRecipesByCollection(collectionid: string) {
+        try {
+            
+        } catch (e: any) {
+            throw new Error(e);
+        }
+    }
+ 
+    async updateOneByID(id: string, data: IRecipe) {
+        const { name, description, preptime } = data;
+        try {
+            const statement = `
+                UPDATE recipin.recipe
+                SET name = $1,
+                    description = $2,
+                    preptime = $3
+                WHERE id = $4
+                RETURNING *;
+            `
+ 
+            const result = await pool.query(statement, [name, description, preptime, id]);
+            Iif (result.rows) return result.rows[0];
+            return null;
+        } catch (error: any) {
+            throw new Error(error);
+        }
+    }
+ 
+    async post(userid: string, data: IRecipe) {
+        const { name, description, preptime } = data;
+ 
+        try {
+            // create recipe itself
+            const statement = `
+                INSERT INTO recipin.recipe
+                    (name, description, preptime, authoruserid, datecreated, datemodified)
+                VALUES ($1, $2, $3, $4, $5, $6)
+                RETURNING *;
+            `
+            const values = [name, description, preptime, userid, now, now];
+            const result = await pool.query(statement, values);
+            Iif (!result.rows.length) return null;
+ 
+            // associate recipe with default collection once created
+            const collection = await CollectionInstance.getUserDefault(userid);
+            const associateToCollection = `
+                INSERT INTO recipin.cmp_recipecollection
+                (recipeid, collectionid)
+                VALUES ($1, $2) RETURNING *
+            `
+            const associateResult = await pool.query(associateToCollection, [result.rows[0].id, collection.id]);
+            Iif (!associateResult.rows.length) return null;
+            
+            return { recipe: result.rows[0], collection: associateResult.rows[0] }
+        } catch (error: any) {
+            throw new Error(error);
+        }
+    }
+}
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/server/models/user.ts.html b/server/coverage/lcov-report/server/models/user.ts.html new file mode 100644 index 0000000..d4a4992 --- /dev/null +++ b/server/coverage/lcov-report/server/models/user.ts.html @@ -0,0 +1,640 @@ + + + + + + Code coverage report for server/models/user.ts + + + + + + + + + +
+
+

All files / server/models user.ts

+
+ +
+ 5.31% + Statements + 5/94 +
+ + +
+ 0% + Branches + 0/20 +
+ + +
+ 0% + Functions + 0/10 +
+ + +
+ 5.95% + Lines + 5/84 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+

+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 +89 +90 +91 +92 +93 +94 +95 +96 +97 +98 +99 +100 +101 +102 +103 +104 +105 +106 +107 +108 +109 +110 +111 +112 +113 +114 +115 +116 +117 +118 +119 +120 +121 +122 +123 +124 +125 +126 +127 +128 +129 +130 +131 +132 +133 +134 +135 +136 +137 +138 +139 +140 +141 +142 +143 +144 +145 +146 +147 +148 +149 +150 +151 +152 +153 +154 +155 +156 +157 +158 +159 +160 +161 +162 +163 +164 +165 +166 +167 +168 +169 +170 +171 +172 +173 +174 +175 +176 +177 +178 +179 +180 +181 +182 +183 +184 +185 +186  +1x +1x +1x +1x +  +1x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + 
import { IUser } from "../schemas";
+import fs from "fs";
+import pool from '../db';
+import now from "../util/now";
+import { appRoot } from "../appRoot";
+ 
+export class User {
+    async getAllUsers() {
+        // behind auth
+        try {
+            const statement = `SELECT * FROM recipin.appusers`;
+            const result = await pool.query(statement);
+            Iif (result.rows.length) return result.rows;
+            return null;
+        } catch (error: any) {
+            throw new Error(error);
+        }
+    }
+ 
+    async getOneByID(id: number | string) {
+        try {
+            const statement = `SELECT * FROM recipin.appusers WHERE id = $1`;
+            const values = [id];
+            const result = await pool.query(statement, values);
+            Iif (result.rows.length) return result.rows[0];
+            return null;
+        } catch (error: any) {
+            throw new Error(error);
+        }
+    }
+ 
+    async getOneByEmail(email: number | string) {
+        try {
+            const statement = `SELECT * FROM recipin.appusers WHERE email = $1`;
+            const result = await pool.query(statement, [email]);
+            Iif (result.rows.length) return result.rows[0];
+            return null;
+        } catch (e: any) {
+            throw new Error(e);
+            
+        }
+    }
+ 
+    async updateOneByID(id: number | string, data: IUser) {
+        try {
+            const statement = `
+                UPDATE recipin.appusers
+                SET firstname = $1,
+                    lastname = $2,
+                    handle = $3,
+                    email = $4,
+                    password = $5,
+                    active = $6,
+                    datemodified = $7
+                WHERE id = $8
+                RETURNING *;
+            `
+            const values = [
+                data.firstname, data.lastname, data.handle,
+                data.email, data.password, data.active,
+                data.datemodified, id
+            ]
+ 
+            const result = await pool.query(statement, values);
+            Iif (result.rows.length) return result.rows[0];
+            return null;
+        } catch (error: any) {
+            throw new Error(error);
+        }
+    }
+ 
+ 
+    async post(data: IUser) {
+        const { firstname, lastname, handle, email, password, active, isadmin } = data;
+ 
+        try {
+            const statement = `
+                INSERT INTO recipin.appusers (
+                    firstname, lastname, handle, email, password, 
+                    active, isadmin, datecreated, datemodified) 
+                VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
+                RETURNING *;
+            `;
+            const params = [firstname, lastname, handle, email, password, active, isadmin, now, now];
+            const result = await pool.query(statement, params);
+            Iif (result.rows.length) return result.rows[0] as IUser;
+            return null;
+        } catch (error: any) {
+            throw new Error(error);
+        }
+    }
+ 
+    async getFriends(id: number | string) {
+        try {
+            // const sql = fs.readFileSync(appRoot + '/db/sql/derived/friendships.sql').toString();
+            const sql = `
+                SELECT * FROM recipin.cmp_userfriendships
+                WHERE senderid = $1;
+            `
+            const result = await pool.query(sql, [id]);
+            Iif (result.rows.length) return result.rows;
+            return null;
+        } catch (e: any) {
+            throw new Error(e);
+        }
+    }
+ 
+    async getFriendshipByID(id: number | string, userid: number | string) {
+        try {
+            const statement = `SELECT * FROM recipin.cmp_userfriendships WHERE id = $1`;
+            const result = await pool.query(statement, [id]);
+ 
+            Iif (result.rows.length) {
+                const row = result.rows[0];
+                Iif (row.senderid == userid || row.targetid == userid) {
+                    const sql = fs.readFileSync(appRoot + '/db/sql/get/friendshipbyid.sql').toString();
+                    const formattedResult = await pool.query(sql, [id]);
+                    Iif (formattedResult.rows.length) return { ok: true, code: 200, result: formattedResult.rows }
+                    return { ok: false, code: 400, result: "Something went wrong" }
+                }
+                return { ok: true, code: 403, result: "Not authorized to access this resource" }
+            }
+            
+            return { ok: false, code: 404, result: "No friendship found with that ID" }
+        } catch (e: any) {
+            throw new Error(e);
+        }
+    }
+ 
+    async getPendingFriendRequests(senderid: number | string) {
+        try {
+            const statement = `SELECT * FROM recipin.cmp_userfriendships WHERE pending = true AND senderid = $1`
+            const result = await pool.query(statement, [senderid]);
+ 
+            Iif (result.rows.length) return { ok: true, code: 200, result: result.rows }
+            return { ok: true, code: 200, result: "No pending friend requests found" }
+        } catch (e: any) {
+            throw new Error(e);
+        }
+    }
+ 
+    async addFriendship(userid: number | string, targetid: number | string) {
+        try {
+            const statement = `
+                INSERT INTO recipin.cmp_userfriendships
+                (datecreated, active, pending, senderid, targetid)
+                VALUES ($1, false, true, $2, $3)
+                RETURNING *;
+            `
+            const values = [now, userid, targetid];
+            const result = await pool.query(statement, values);
+            Iif (result.rows.length) {
+                return result.rows[0];
+            }
+            return null;
+        } catch (e: any) {
+            throw new Error(e);
+        }
+    }
+ 
+    async updateFriendship(id: number | string, userid: number | string, data: { active: boolean, pending: boolean, dateterminated?: string }) {
+        try {
+            const query = `SELECT * FROM recipin.cmp_userfriendships WHERE id = $1`;
+            const friendship = await pool.query(query, [id]);
+            Iif (!friendship.rows.length) return { ok: false, code: 404, result: "Friendship with this code not found" };
+            Iif (!(friendship.rows[0].active) && friendship.rows[0].senderid == userid) {
+                return { ok: false, code: 403, result: "Please wait for friend request to be accepted" }
+            }
+ 
+            const statement = `
+                UPDATE recipin.cmp_userfriendships
+                SET active = $1,
+                    pending = $2,
+                    dateterminated = $3
+                WHERE id = $4
+                RETURNING *;
+            `
+            const values = [data.active, data.pending, (data.dateterminated || null), id];
+            const result = await pool.query(statement, values);
+            Iif (result.rows.length) return { ok: true, code: 200, result: result.rows[0] }
+            return { ok: false, code: 400, result: "Bad request" }
+        } catch (e: any) {
+            throw new Error(e);
+        }
+    }
+}
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/server/routes/cuisine.ts.html b/server/coverage/lcov-report/server/routes/cuisine.ts.html new file mode 100644 index 0000000..5b11413 --- /dev/null +++ b/server/coverage/lcov-report/server/routes/cuisine.ts.html @@ -0,0 +1,202 @@ + + + + + + Code coverage report for server/routes/cuisine.ts + + + + + + + + + +
+
+

All files / server/routes cuisine.ts

+
+ +
+ 29.16% + Statements + 7/24 +
+ + +
+ 100% + Branches + 0/0 +
+ + +
+ 25% + Functions + 1/4 +
+ + +
+ 26.08% + Lines + 6/23 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+

+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +401x +1x +1x +  +1x +  +1x +1x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + 
import { Express, Router } from 'express';
+import { CuisineCtl } from '../controllers';
+const CuisineInstance = new CuisineCtl();
+ 
+const router = Router();
+ 
+export const cuisineRouter = (app: Express) => {
+    app.use('/cuisine', router);
+ 
+    router.get('/', async (req, res, next) => {
+        try {
+            const result = await CuisineInstance.getAll();
+            res.status(200).send(result);
+        } catch(e) {
+            next(e);
+        }
+    })
+ 
+    router.get('/:id', async (req, res, next) => {
+        const { id } = req.params;
+ 
+        try {
+            const result = await CuisineInstance.getOne(id);
+            res.status(200).send(result);
+        } catch(e) {
+            next(e);
+        }
+    })
+ 
+    router.post('/', async (req, res, next) => {
+        const data = req.body;
+ 
+        try {
+            const result = await CuisineInstance.post(data);
+            res.status(201).send(result);
+        } catch(e) {
+            next(e);
+        }
+    })
+}
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/server/routes/index.html b/server/coverage/lcov-report/server/routes/index.html new file mode 100644 index 0000000..fced389 --- /dev/null +++ b/server/coverage/lcov-report/server/routes/index.html @@ -0,0 +1,116 @@ + + + + + + Code coverage report for server/routes + + + + + + + + + +
+
+

All files server/routes

+
+ +
+ 29.16% + Statements + 7/24 +
+ + +
+ 100% + Branches + 0/0 +
+ + +
+ 25% + Functions + 1/4 +
+ + +
+ 26.08% + Lines + 6/23 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileStatementsBranchesFunctionsLines
cuisine.ts +
+
29.16%7/24100%0/025%1/426.08%6/23
+
+
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/server/util/index.html b/server/coverage/lcov-report/server/util/index.html new file mode 100644 index 0000000..0400c23 --- /dev/null +++ b/server/coverage/lcov-report/server/util/index.html @@ -0,0 +1,116 @@ + + + + + + Code coverage report for server/util + + + + + + + + + +
+
+

All files server/util

+
+ +
+ 100% + Statements + 2/2 +
+ + +
+ 100% + Branches + 0/0 +
+ + +
+ 100% + Functions + 0/0 +
+ + +
+ 100% + Lines + 2/2 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileStatementsBranchesFunctionsLines
now.ts +
+
100%2/2100%0/0100%0/0100%2/2
+
+
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/server/util/now.ts.html b/server/coverage/lcov-report/server/util/now.ts.html new file mode 100644 index 0000000..0d7d7f1 --- /dev/null +++ b/server/coverage/lcov-report/server/util/now.ts.html @@ -0,0 +1,88 @@ + + + + + + Code coverage report for server/util/now.ts + + + + + + + + + +
+
+

All files / server/util now.ts

+
+ +
+ 100% + Statements + 2/2 +
+ + +
+ 100% + Branches + 0/0 +
+ + +
+ 100% + Functions + 0/0 +
+ + +
+ 100% + Lines + 2/2 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+

+
1 +22x +2x
const now = new Intl.DateTimeFormat('en-US', { dateStyle: 'medium', timeStyle: 'long' }).format(Date.now())
+export default now;
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/sort-arrow-sprite.png b/server/coverage/lcov-report/sort-arrow-sprite.png new file mode 100644 index 0000000000000000000000000000000000000000..6ed68316eb3f65dec9063332d2f69bf3093bbfab GIT binary patch literal 138 zcmeAS@N?(olHy`uVBq!ia0vp^>_9Bd!3HEZxJ@+%Qh}Z>jv*C{$p!i!8j}?a+@3A= zIAGwzjijN=FBi!|L1t?LM;Q;gkwn>2cAy-KV{dn nf0J1DIvEHQu*n~6U}x}qyky7vi4|9XhBJ7&`njxgN@xNA8m%nc literal 0 HcmV?d00001 diff --git a/server/coverage/lcov-report/sorter.js b/server/coverage/lcov-report/sorter.js new file mode 100644 index 0000000..2bb296a --- /dev/null +++ b/server/coverage/lcov-report/sorter.js @@ -0,0 +1,196 @@ +/* eslint-disable */ +var addSorting = (function() { + 'use strict'; + var cols, + currentSort = { + index: 0, + desc: false + }; + + // returns the summary table element + function getTable() { + return document.querySelector('.coverage-summary'); + } + // returns the thead element of the summary table + function getTableHeader() { + return getTable().querySelector('thead tr'); + } + // returns the tbody element of the summary table + function getTableBody() { + return getTable().querySelector('tbody'); + } + // returns the th element for nth column + function getNthColumn(n) { + return getTableHeader().querySelectorAll('th')[n]; + } + + function onFilterInput() { + const searchValue = document.getElementById('fileSearch').value; + const rows = document.getElementsByTagName('tbody')[0].children; + for (let i = 0; i < rows.length; i++) { + const row = rows[i]; + if ( + row.textContent + .toLowerCase() + .includes(searchValue.toLowerCase()) + ) { + row.style.display = ''; + } else { + row.style.display = 'none'; + } + } + } + + // loads the search box + function addSearchBox() { + var template = document.getElementById('filterTemplate'); + var templateClone = template.content.cloneNode(true); + templateClone.getElementById('fileSearch').oninput = onFilterInput; + template.parentElement.appendChild(templateClone); + } + + // loads all columns + function loadColumns() { + var colNodes = getTableHeader().querySelectorAll('th'), + colNode, + cols = [], + col, + i; + + for (i = 0; i < colNodes.length; i += 1) { + colNode = colNodes[i]; + col = { + key: colNode.getAttribute('data-col'), + sortable: !colNode.getAttribute('data-nosort'), + type: colNode.getAttribute('data-type') || 'string' + }; + cols.push(col); + if (col.sortable) { + col.defaultDescSort = col.type === 'number'; + colNode.innerHTML = + colNode.innerHTML + ''; + } + } + return cols; + } + // attaches a data attribute to every tr element with an object + // of data values keyed by column name + function loadRowData(tableRow) { + var tableCols = tableRow.querySelectorAll('td'), + colNode, + col, + data = {}, + i, + val; + for (i = 0; i < tableCols.length; i += 1) { + colNode = tableCols[i]; + col = cols[i]; + val = colNode.getAttribute('data-value'); + if (col.type === 'number') { + val = Number(val); + } + data[col.key] = val; + } + return data; + } + // loads all row data + function loadData() { + var rows = getTableBody().querySelectorAll('tr'), + i; + + for (i = 0; i < rows.length; i += 1) { + rows[i].data = loadRowData(rows[i]); + } + } + // sorts the table using the data for the ith column + function sortByIndex(index, desc) { + var key = cols[index].key, + sorter = function(a, b) { + a = a.data[key]; + b = b.data[key]; + return a < b ? -1 : a > b ? 1 : 0; + }, + finalSorter = sorter, + tableBody = document.querySelector('.coverage-summary tbody'), + rowNodes = tableBody.querySelectorAll('tr'), + rows = [], + i; + + if (desc) { + finalSorter = function(a, b) { + return -1 * sorter(a, b); + }; + } + + for (i = 0; i < rowNodes.length; i += 1) { + rows.push(rowNodes[i]); + tableBody.removeChild(rowNodes[i]); + } + + rows.sort(finalSorter); + + for (i = 0; i < rows.length; i += 1) { + tableBody.appendChild(rows[i]); + } + } + // removes sort indicators for current column being sorted + function removeSortIndicators() { + var col = getNthColumn(currentSort.index), + cls = col.className; + + cls = cls.replace(/ sorted$/, '').replace(/ sorted-desc$/, ''); + col.className = cls; + } + // adds sort indicators for current column being sorted + function addSortIndicators() { + getNthColumn(currentSort.index).className += currentSort.desc + ? ' sorted-desc' + : ' sorted'; + } + // adds event listeners for all sorter widgets + function enableUI() { + var i, + el, + ithSorter = function ithSorter(i) { + var col = cols[i]; + + return function() { + var desc = col.defaultDescSort; + + if (currentSort.index === i) { + desc = !currentSort.desc; + } + sortByIndex(i, desc); + removeSortIndicators(); + currentSort.index = i; + currentSort.desc = desc; + addSortIndicators(); + }; + }; + for (i = 0; i < cols.length; i += 1) { + if (cols[i].sortable) { + // add the click event handler on the th so users + // dont have to click on those tiny arrows + el = getNthColumn(i).querySelector('.sorter').parentElement; + if (el.addEventListener) { + el.addEventListener('click', ithSorter(i)); + } else { + el.attachEvent('onclick', ithSorter(i)); + } + } + } + } + // adds sorting functionality to the UI + return function() { + if (!getTable()) { + return; + } + cols = loadColumns(); + loadData(); + addSearchBox(); + addSortIndicators(); + enableUI(); + }; +})(); + +window.addEventListener('load', addSorting); diff --git a/server/coverage/lcov-report/util/index.html b/server/coverage/lcov-report/util/index.html new file mode 100644 index 0000000..db2158d --- /dev/null +++ b/server/coverage/lcov-report/util/index.html @@ -0,0 +1,116 @@ + + + + + + Code coverage report for util + + + + + + + + + +
+
+

All files util

+
+ +
+ 100% + Statements + 2/2 +
+ + +
+ 100% + Branches + 0/0 +
+ + +
+ 100% + Functions + 0/0 +
+ + +
+ 100% + Lines + 2/2 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileStatementsBranchesFunctionsLines
now.ts +
+
100%2/2100%0/0100%0/0100%2/2
+
+
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/util/now.ts.html b/server/coverage/lcov-report/util/now.ts.html new file mode 100644 index 0000000..e029f79 --- /dev/null +++ b/server/coverage/lcov-report/util/now.ts.html @@ -0,0 +1,88 @@ + + + + + + Code coverage report for util/now.ts + + + + + + + + + +
+
+

All files / util now.ts

+
+ +
+ 100% + Statements + 2/2 +
+ + +
+ 100% + Branches + 0/0 +
+ + +
+ 100% + Functions + 0/0 +
+ + +
+ 100% + Lines + 2/2 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+

+
1 +21x +1x
const now = new Intl.DateTimeFormat('en-US', { dateStyle: 'medium', timeStyle: 'long' }).format(Date.now())
+export default now;
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov.info b/server/coverage/lcov.info new file mode 100644 index 0000000..0569e12 --- /dev/null +++ b/server/coverage/lcov.info @@ -0,0 +1,12 @@ +TN: +SF:dist/util/now.js +FNF:0 +FNH:0 +DA:2,1 +DA:3,1 +DA:4,1 +LF:3 +LH:3 +BRF:0 +BRH:0 +end_of_record diff --git a/server/index.ts b/server/index.ts index a4802fe..4a4c74f 100644 --- a/server/index.ts +++ b/server/index.ts @@ -12,11 +12,12 @@ app.use(cors()); export const appRoot = path.resolve(__dirname); -(async function() { - +export default async function main() { const app = express(); await loaders(app); app.listen(port, () => { console.log('listening on port ' + port); }) -})(); +}; + +main(); \ No newline at end of file diff --git a/server/jest.config.js b/server/jest.config.js new file mode 100644 index 0000000..3770d10 --- /dev/null +++ b/server/jest.config.js @@ -0,0 +1,6 @@ +module.exports = { + preset: 'ts-jest', + testEnvironment: 'node', + setupFiles: ['dotenv/config'], + roots: ['/dist'] +}; \ No newline at end of file diff --git a/server/jest/index.ts b/server/jest/index.ts new file mode 100644 index 0000000..ae4db4d --- /dev/null +++ b/server/jest/index.ts @@ -0,0 +1,5 @@ +import main from ".." + +export default () => { + +} \ No newline at end of file diff --git a/server/jest/tests/now.test.ts b/server/jest/tests/now.test.ts new file mode 100644 index 0000000..bc3a678 --- /dev/null +++ b/server/jest/tests/now.test.ts @@ -0,0 +1,13 @@ +import now from "../../util/now"; + +describe('now utility', () => { + it('returns a string', () => { + expect(typeof now == 'string').toBeTruthy(); + }) + + it('is equal to current datetime', () => { + const expected = Date.now(); + const formatter = Intl.DateTimeFormat('en-US', { dateStyle: 'medium', timeStyle: 'long' }); + expect(formatter.format(expected)).toEqual(now); + }) +}) \ No newline at end of file diff --git a/server/jest/tests/routes/collection.test.ts b/server/jest/tests/routes/collection.test.ts new file mode 100644 index 0000000..e69de29 diff --git a/server/jest/tests/routes/comment.test.ts b/server/jest/tests/routes/comment.test.ts new file mode 100644 index 0000000..e69de29 diff --git a/server/jest/tests/routes/course.test.ts b/server/jest/tests/routes/course.test.ts new file mode 100644 index 0000000..e69de29 diff --git a/server/jest/tests/routes/cuisine.test.ts b/server/jest/tests/routes/cuisine.test.ts new file mode 100644 index 0000000..abe071a --- /dev/null +++ b/server/jest/tests/routes/cuisine.test.ts @@ -0,0 +1,48 @@ +import request from 'supertest'; +import { ICuisine } from '../../../schemas'; + +describe('GET /cuisine', () => { + let data: Array; + + beforeAll(async () => { + const result = await request('localhost:8080') + .get('/cuisine'); + + data = JSON.parse(result.text); + }) + + it('returns a result if one exists', async () => { + expect(data.length).toBeGreaterThan(0); + }) + + it('matches cuisine schema', async () => { + expect(() => { + const expected = new Array(); + for (let key of Object.keys(data[0])) { + expected.push(key as keyof ICuisine); + } + }).not.toThrow(); + }) +}) + +describe('GET /cuisine/:id', () => { + let data: ICuisine + beforeAll(async() => { + const result = await request('localhost:8080') + .get('/cuisine/1'); + data = JSON.parse(result.text); + }) + + it('returns a single object if exists', async () => { + expect(data).toBeDefined(); + }) + + it('matches cuisine schema', async () => { + expect(() => { + const expected = new Array(); + for (let key of Object.keys(data)) { + expected.push(key as keyof ICuisine); + } + }).not.toThrow(); + }) +}) \ No newline at end of file diff --git a/server/jest/tests/routes/friend.test.ts b/server/jest/tests/routes/friend.test.ts new file mode 100644 index 0000000..e69de29 diff --git a/server/jest/tests/routes/groceryList.test.ts b/server/jest/tests/routes/groceryList.test.ts new file mode 100644 index 0000000..e69de29 diff --git a/server/jest/tests/routes/ingredient.test.ts b/server/jest/tests/routes/ingredient.test.ts new file mode 100644 index 0000000..e69de29 diff --git a/server/jest/tests/routes/recipe.test.ts b/server/jest/tests/routes/recipe.test.ts new file mode 100644 index 0000000..e69de29 diff --git a/server/jest/tests/routes/subscription.test.ts b/server/jest/tests/routes/subscription.test.ts new file mode 100644 index 0000000..e69de29 diff --git a/server/jest/tests/routes/users.test.ts b/server/jest/tests/routes/users.test.ts new file mode 100644 index 0000000..db9b832 --- /dev/null +++ b/server/jest/tests/routes/users.test.ts @@ -0,0 +1,44 @@ +import request from 'supertest'; +import { IUser } from '../../../schemas'; + +describe('GET /users', () => { + let data: Array + beforeAll(async() => { + const response = await request('localhost:8080') + .get('/users'); + data = JSON.parse(response.text); + }) + + test('gets data if exists', () => { + expect(data.length).toBeGreaterThan(0); + }) + + test('data matches user schema', () => { + expect(() => { + const expected = new Array(); + for (let key of Object.keys(data[0])) { + expected.push(key as keyof IUser); + } + }).not.toThrow(); + }) +}) + +describe('GET /users/1', () => { + let data: IUser + beforeAll(async() => { + const response = await request('localhost:8080') + .get('/users/1') + data = JSON.parse(response.text); + }) + + test('retrieves a single record', () => { + expect(data).toBeDefined(); + }) + + test('matches user schema', () => { + const expected = new Array(); + for (let key of Object.keys(data)) { + expected.push(key as keyof IUser); + } + }) +}) \ No newline at end of file diff --git a/server/package.json b/server/package.json index 7198456..0eecc3c 100644 --- a/server/package.json +++ b/server/package.json @@ -9,7 +9,8 @@ "populate": "npm run build && node dist/db/examplevals.js", "dev": "rm -rf dist && ./node_modules/.bin/tsc --project ./tsconfig.json --watch & ts-node-dev index.ts", "prod": "npm run build && node dist/index.js", - "test": "echo \"Error: no test specified\" && exit 1" + "test": "jest --coverage", + "test:watch": "jest --watch" }, "author": "", "license": "ISC", @@ -42,6 +43,7 @@ "@types/express": "^4.17.14", "@types/express-session": "^1.17.5", "@types/http-errors": "^2.0.1", + "@types/jest": "^29.2.4", "@types/js-yaml": "^4.0.5", "@types/morgan": "^1.9.3", "@types/node": "^18.11.9", @@ -49,8 +51,12 @@ "@types/passport-local": "^1.0.34", "@types/pg": "^8.6.5", "@types/pg-promise": "^5.4.3", + "@types/supertest": "^2.0.12", "@types/swagger-ui-express": "^4.1.3", + "jest": "^29.3.1", "nodemon": "^2.0.20", + "supertest": "^6.3.3", + "ts-jest": "^29.0.3", "ts-node-dev": "^2.0.0", "tslint": "^6.1.3", "typescript": "^4.9.3"