UNPKG

openhim-core

Version:

The OpenHIM core application that provides logging and routing of http requests

279 lines (278 loc) 10.3 kB
<!doctype html> <html lang="en"> <head> <title>Code coverage report for src/utils.coffee</title> <meta charset="utf-8" /> <link rel="stylesheet" href="../prettify.css" /> <link rel="stylesheet" href="../base.css" /> <meta name="viewport" content="width=device-width, initial-scale=1"> <style type='text/css'> .coverage-summary .sorter { background-image: url(../sort-arrow-sprite.png); } </style> </head> <body> <div class='wrapper'> <div class='pad1'> <h1> <a href="../index.html">All files</a> / <a href="index.html">src</a> utils.coffee </h1> <div class='clearfix'> <div class='fl pad1y space-right2'> <span class="strong">44.44% </span> <span class="quiet">Statements</span> <span class='fraction'>16/36</span> </div> <div class='fl pad1y space-right2'> <span class="strong">9.09% </span> <span class="quiet">Branches</span> <span class='fraction'>1/11</span> </div> <div class='fl pad1y space-right2'> <span class="strong">0% </span> <span class="quiet">Functions</span> <span class='fraction'>0/11</span> </div> <div class='fl pad1y space-right2'> <span class="strong">47.06% </span> <span class="quiet">Lines</span> <span class='fraction'>16/34</span> </div> </div> </div> <div class='status-line low'></div> <pre><table class="coverage"> <tr><td class="line-count quiet">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</td><td class="line-coverage quiet"><span class="cline-any cline-yes">1x</span> <span class="cline-any cline-yes">1x</span> <span class="cline-any cline-yes">1x</span> <span class="cline-any cline-yes">1x</span> <span class="cline-any cline-yes">1x</span> <span class="cline-any cline-yes">1x</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">1x</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">1x</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">1x</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">1x</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">1x</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">1x</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">1x</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">1x</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">1x</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">1x</span> <span class="cline-any cline-no">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">logger = require 'winston' config = require './config/config' config.caching = config.get('caching') Channel = require("./model/channels").Channel Keystore = require("./model/keystore").Keystore momentTZ = require 'moment-timezone' &nbsp; # function to log errors and return response exports.logAndSetResponse = <span class="fstat-no" title="function not covered" >(</span>ctx, status, msg, logLevel) -&gt; <span class="cstat-no" title="statement not covered" > logger[logLevel] msg</span> <span class="cstat-no" title="statement not covered" > ctx.body = m</span>sg ctx.status = status &nbsp; &nbsp; cacheValueStore = {} &nbsp; refreshMillis = config.caching.refreshMillis &nbsp; getCachedValues = <span class="fstat-no" title="function not covered" >(</span>store, callback) -&gt; <span class="cstat-no" title="statement not covered" > lastCheck = cacheValueStore["#{store}"]?.l</span>astCheck &nbsp; if not config.caching.enabled or not lastCheck? or ((new Date)-lastCheck) &gt; refreshMillis &nbsp; <span class="cstat-no" title="statement not covered" > handler = <span class="fstat-no" title="function not covered" >(</span></span>err, results) -&gt; <span class="cstat-no" title="statement not covered" ></span> return callback err if err &nbsp; if config.caching.enabled i</span>f not lastCheck then <span class="cstat-no" title="statement not covered" >cacheValueStore["#{store}"] = {} <span class="cstat-no" title="statement not covered" > cacheValueStore["#{store}"].value = r</span>esults <span class="cstat-no" title="statement not covered" > cacheValueStore["#{store}"].lastCheck = new Date</span> &nbsp; callback null, results &nbsp; #TODO make this more generic (had issues passing Channel.find as a param [higher order function]) <span class="cstat-no" title="statement not covered" > if store is 'channels'</span> Channel.find({}).sort(priority: 1).exec <span class="fstat-no" title="function not covered" >(</span>err, channels) -&gt; <span class="cstat-no" title="statement not covered" ></span> return handler err if err <span class="cstat-no" title="statement not covered" > noPriorityChannels = [</span>] <span class="cstat-no" title="statement not covered" > sortedChannels = [</span>] <span class="cstat-no" title="statement not covered" > channels.forEach <span class="fstat-no" title="function not covered" >(</span>channel) -&gt;</span> if not channel.priority? noPriorityChannels.push channel else sortedChannels.push channel handler null, sortedChannels.concat(noPriorityChannels) else <span class="cstat-no" title="statement not covered" >if store is 'keystore'</span> Keystore.findOne {}, handler else callback "Internal error: Invalid store #{store}" &nbsp; else callback null, cacheValueStore["#{store}"].value &nbsp; exports.getAllChannelsInPriorityOrder = <span class="fstat-no" title="function not covered" >(</span>callback) -&gt; getCachedValues 'channels', callback &nbsp; exports.getKeystore = <span class="fstat-no" title="function not covered" >(</span>callback) -&gt; getCachedValues 'keystore', callback &nbsp; # function to check if string match status code pattern exports.statusCodePatternMatch = <span class="fstat-no" title="function not covered" >(</span>string, callback) -&gt; /\dxx/.test string &nbsp; # returns an array with no duplicates exports.uniqArray = <span class="fstat-no" title="function not covered" >(</span>arr) -&gt; <span class="cstat-no" title="statement not covered" > dict = {</span>} <span class="cstat-no" title="statement not covered" ><span class="cstat-no" title="statement not covered" > dict[k] = k</span> for k in arr</span> return (<span class="cstat-no" title="statement not covered" >v for k, v of dict)</span> &nbsp; # thanks to https://coffeescript-cookbook.github.io/chapters/arrays/check-type-is-array exports.typeIsArray = Array.isArray || <span class="fstat-no" title="function not covered" ><span class="branch-1 cbranch-no" title="branch not covered" >( </span>value ) -&gt; <span class="cstat-no" title="statement not covered" >return {}.toString.call( value ) is '</span>[object Array]'</span> &nbsp; # get the server timezone exports.serverTimezone = <span class="fstat-no" title="function not covered" ></span>() -&gt; <span class="cstat-no" title="statement not covered" > return m</span>omentTZ.tz.guess()</pre></td></tr> </table></pre> <div class='push'></div><!-- for sticky footer --> </div><!-- /wrapper --> <div class='footer quiet pad2 space-top1 center small'> Code coverage generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Mon Oct 10 2016 13:39:22 GMT+0200 (SAST) </div> </div> <script src="../prettify.js"></script> <script> window.onload = function () { if (typeof prettyPrint === 'function') { prettyPrint(); } }; </script> <script src="../sorter.js"></script> </body> </html>