From 208a579a003f140016f6e91bb422959cb6f30b34 Mon Sep 17 00:00:00 2001 From: Tobiah Date: Wed, 14 Jul 2021 19:27:39 +0000 Subject: [PATCH] fix: allow skipping, tests --- .github/workflows/docs.yaml | 4 +- index.js | 85 +++++---- lib/AttachmentCreator.js | 9 +- lib/Settings.js | 17 +- lib/market/v1/MarketFetcher.js | 10 +- lib/market/v1/summary.js | 2 +- package-lock.json | 326 --------------------------------- package.json | 20 +- test/attachment-test.js | 42 +++++ test/test.js | 84 ++++++--- 10 files changed, 208 insertions(+), 391 deletions(-) create mode 100644 test/attachment-test.js diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml index 43faaa2..d5ec68f 100644 --- a/.github/workflows/docs.yaml +++ b/.github/workflows/docs.yaml @@ -11,8 +11,8 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v2 - - name: Install Supplemental Dependencies - run: npm i + - run: npm i + - run: npm i ink-docstrap jsdoc - name: Build uses: andstor/jsdoc-action@v1 with: diff --git a/index.js b/index.js index 0152a79..02f15b0 100644 --- a/index.js +++ b/index.js @@ -13,7 +13,7 @@ const NexusFetcher = require('./lib/nexus/v2/NexusFetcher'); const noResultAttachment = { type: 'rich', - description: 'No result', + title: 'No results', color: '0xff55ff', url: 'https://warframe.market', footer: { @@ -28,29 +28,41 @@ if (!global.__basedir) { /** * Represents a queryable datastore of information derived from `https://nexus-stats.com/api` */ -class PriceCheckQuerier { +module.exports = class PriceCheckQuerier { /** * Creates an instance representing a WarframeNexusStats data object * @constructor */ - constructor({ logger = console, nexusApi = undefined, marketCache } = {}) { + constructor({ + logger = console, + nexusApi = undefined, + marketCache = undefined, + skipNexus = false, + skipMarket = false, + }) { this.settings = new Settings(); this.logger = logger; + this.skipNexus = skipNexus; + this.skipMarket = skipMarket; - try { - this.nexusFetcher = new NexusFetcher({ settings: this.settings, nexusApi, logger }); - } catch (e) { - this.logger.error(`couldn't set up nexus fetcher: ${e.message}`); + if (!skipNexus) { + try { + this.nexusFetcher = new NexusFetcher({ settings: this.settings, nexusApi, logger }); + } catch (e) { + this.logger.error(`couldn't set up nexus fetcher: ${e.message}`); + } } - try { - /** - * Fetch market data - * @type {MarketFetcher} - */ - this.marketFetcher = new MarketFetcher({ logger, settings: this.settings, marketCache }); - } catch (e) { - this.logger.error(`couldn't set up market fetcher: ${e.message}`); + if (!skipMarket) { + try { + /** + * Fetch market data + * @type {MarketFetcher} + */ + this.marketFetcher = new MarketFetcher({ logger, settings: this.settings, marketCache }); + } catch (e) { + this.logger.error(`couldn't set up market fetcher: ${e.message}`); + } } /** @@ -67,36 +79,47 @@ class PriceCheckQuerier { * @returns {Promise>} a Promise of an array of Item objects */ async priceCheckQuery(query, platform = 'pc') { + this.logger.info(`state:\n\tskipNexus: ${this.skipNexus}\n\tskipMarket: ${this.skipMarket}\n\tquery: ${query}\n\tplatform: ${platform}`); if (!query) { throw new Error('This funtcion requires a query to be provided'); } // eslint-disable-next-line no-param-reassign - platform = this.settings.platforms[platform.toLowerCase()]; + platform = this.settings.lookupAlias(platform.toLowerCase()); let nexusResults; let successfulQuery; let attachments = []; - if (platform !== 'switch') { - try { - const nexusPromise = this.nexusFetcher.queryNexus(query, platform); - nexusResults = await promiseTimeout(this.settings.timeouts.nexus, nexusPromise); - ({ successfulQuery, attachments } = nexusResults); - } catch (e) { - this.logger.error(`Couldn't process ${query} on nexus-hub... time out.`); + if (!this.skipNexus) { + this.logger.info(`querying nexus for ${query} on ${platform}`); + if (platform !== 'switch') { + try { + const nexusPromise = this.nexusFetcher.queryNexus(query, platform); + nexusResults = await promiseTimeout(this.settings.timeouts.nexus, nexusPromise); + ({ successfulQuery, attachments } = nexusResults); + } catch (e) { + this.logger.error(`Couldn't process ${query} on nexus-hub... time out.`); + } } + } else { + this.logger.info('skipNexus'); } - if (this.marketFetcher) { + if (this.marketFetcher && !this.skipMarket) { + this.logger.info(`querying market for ${query} on ${platform}`); try { - const marketPromise = this.marketFetcher.queryMarket(query, { successfulQuery, platform }); + const marketPromise = this.marketFetcher.queryMarket(query, { + successfulQuery, platform: this.settings.lookupAlias(platform, true), + }); const marketResults = await promiseTimeout(this.settings.timeouts.market, marketPromise); attachments = [...attachments, ...marketResults]; } catch (e) { this.logger.error(`Couldn't process ${query} on warframe.market... time out.`); } + } else { + this.logger.info('No market fetcher, skipping market'); } - return attachments.length ? attachments : [noResultAttachment]; + return attachments; } /** @@ -108,7 +131,7 @@ class PriceCheckQuerier { */ async priceCheckQueryString(query, priorResults, platform = 'pc') { const components = priorResults || await this.priceCheckQuery(query, platform); - const tokens = []; + const tokens = [`[${platform.toUpperCase()}] ${query}`]; components.slice(0, 4).forEach((component) => { tokens.push(`${md.lineEnd}${component.toString()}`); }); @@ -138,8 +161,10 @@ class PriceCheckQuerier { * Stop updating caches */ async stopUpdating() { - if (this.marketFetcher.marketCache) { + if (!this.skipMarket && this.marketFetcher.marketCache) { this.marketFetcher.marketCache.stop(); + } else { + this.logger.log('no market cache, or skipMarket was true'); } if (fss.existsSync(`${global.__basedir}/tmp`)) { @@ -159,6 +184,4 @@ class PriceCheckQuerier { } } } -} - -module.exports = PriceCheckQuerier; +}; diff --git a/lib/AttachmentCreator.js b/lib/AttachmentCreator.js index b27c1b8..efefa84 100644 --- a/lib/AttachmentCreator.js +++ b/lib/AttachmentCreator.js @@ -13,7 +13,7 @@ const wfcdLogo = 'https://warframestat.us/wfcd_logo_color.png'; const noResultAttachment = { type: 'rich', - description: 'No result', + title: 'No result', color: 0xff55ff, url: 'https://warframe.market', footer: { @@ -146,13 +146,14 @@ class AttachmentCreator { * @returns {Object} Discord-ready attachment describing the item */ attachmentFromComponents(components, query, platform = 'pc') { - const attachment = JSON.parse(JSON.stringify(baseAttachment)); + if (!components || !components.length || !Array.isArray(components)) return noResultAttachment; + const attachment = JSON.parse(JSON.stringify(baseAttachment)); const nexusComponents = components .filter((component) => component && component.components && component.components[0].type === 'nexus-v2'); - const marketComponents = components - .filter((component) => component && component.type === 'market-v1' && typeof component.prices.soldPrice !== 'undefined'); + .filter((component) => component && component.type === 'market-v1' + && typeof component.prices.soldPrice !== 'undefined'); if (nexusComponents.length > 0) { nexusComponents.forEach((nexusComponent) => { diff --git a/lib/Settings.js b/lib/Settings.js index aad3179..c0422e3 100644 --- a/lib/Settings.js +++ b/lib/Settings.js @@ -28,6 +28,7 @@ class Settings { marketAssets: process.env.MARKET_ASSETS_URL_OVERRIDE || 'https://warframe.market/static/assets/', }; + this.platforms = { pc: 'pc', ps4: 'ps4', @@ -38,6 +39,17 @@ class Settings { swi: 'switch', switch: 'switch', ns: 'switch', + market: { + pc: 'pc', + ps4: 'ps4', + playstation: 'ps4', + xbone: 'xbox', + xbox: 'xbox', + xb1: 'xbox', + swi: 'switch', + switch: 'switch', + ns: 'switch', + }, }; this.timeouts = { @@ -51,10 +63,11 @@ class Settings { /** * Look up real platform for platform alias * @param {string} platformAlias Alias of platform + * @param {boolean} market Whether or not to use market-specific aliases * @returns {string} Real platform identifier */ - lookupAlias(platformAlias) { - return this.platforms[platformAlias.toLowerCase()]; + lookupAlias(platformAlias, market = false) { + return market ? this.platforms.market[platformAlias.toLowerCase()] : this.platforms[platformAlias.toLowerCase()]; } } diff --git a/lib/market/v1/MarketFetcher.js b/lib/market/v1/MarketFetcher.js index a9cd14a..db86dd5 100644 --- a/lib/market/v1/MarketFetcher.js +++ b/lib/market/v1/MarketFetcher.js @@ -27,6 +27,8 @@ class MarketFetcher { }; this.logger = logger; + + this.logger.info('finished setting up market fetcher'); } async averagesForItem(urlName, platform = 'pc') { @@ -108,15 +110,21 @@ class MarketFetcher { } async queryMarket(query, { successfulQuery, platform = 'pc' }) { + this.logger.info(`querying market for ${query} on ${platform}`); const attachments = []; try { // get market data const marketData = await this.marketCache.getDataJson(); - const marketResults = jsonQuery(`items[*item_name~/${successfulQuery || query}.*/i]`, { + if (!marketData) { + this.logger.info('No market data!'); + return []; + } + const marketResults = jsonQuery(`items[*item_name~/^${successfulQuery || query}.*/i]`, { data: marketData.payload || {}, allowRegexp: true, }).value; if (!marketResults || marketResults.length < 1) { + this.logger.info('No market results!'); return []; } diff --git a/lib/market/v1/summary.js b/lib/market/v1/summary.js index e186e34..2a667bc 100644 --- a/lib/market/v1/summary.js +++ b/lib/market/v1/summary.js @@ -36,7 +36,7 @@ class Summary { * @param {string} opt Option, either 'codex', 'item', 'location', 'all' * @returns {string} */ - toString(opt) { + toString(opt = 'item') { let value = this.name; if (opt === 'codex' || opt === 'all') { value += '```\n' diff --git a/package-lock.json b/package-lock.json index d94fe84..f7883e4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -526,12 +526,6 @@ "es-abstract": "^1.7.0" } }, - "array-uniq": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/array-uniq/-/array-uniq-1.0.3.tgz", - "integrity": "sha1-r2rId6Jcx/dOBYiUdThY39sk/bY=", - "dev": true - }, "array.prototype.flat": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/array.prototype.flat/-/array.prototype.flat-1.2.2.tgz", @@ -606,12 +600,6 @@ "integrity": "sha512-Phlt0plgpIIBOGTT/ehfFnbNlfsDEiqmzE2KRXoX1bLIlir4X/MR+zSyBEkL05ffWgnRSf/DXv+WrUAVr93/ow==", "dev": true }, - "bluebird": { - "version": "3.7.2", - "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz", - "integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==", - "dev": true - }, "boolbase": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/boolbase/-/boolbase-1.0.0.tgz", @@ -671,15 +659,6 @@ "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=" }, - "catharsis": { - "version": "0.8.11", - "resolved": "https://registry.npmjs.org/catharsis/-/catharsis-0.8.11.tgz", - "integrity": "sha512-a+xUyMV7hD1BrDQA/3iPV7oc+6W26BgVJO05PGEoatMyIuPScQKsde6i3YorWX1qs+AZjnJ18NqdKoCtKiNh1g==", - "dev": true, - "requires": { - "lodash": "^4.17.14" - } - }, "chai": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/chai/-/chai-4.2.0.tgz", @@ -2132,16 +2111,6 @@ "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" }, - "ink-docstrap": { - "version": "1.3.2", - "resolved": "https://registry.npmjs.org/ink-docstrap/-/ink-docstrap-1.3.2.tgz", - "integrity": "sha512-STx5orGQU1gfrkoI/fMU7lX6CSP7LBGO10gXNgOZhwKhUqbtNjCkYSewJtNnLmWP1tAGN6oyEpG1HFPw5vpa5Q==", - "dev": true, - "requires": { - "moment": "^2.14.1", - "sanitize-html": "^1.13.0" - } - }, "inquirer": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/inquirer/-/inquirer-7.0.0.tgz", @@ -2516,57 +2485,12 @@ "esprima": "^4.0.0" } }, - "js2xmlparser": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/js2xmlparser/-/js2xmlparser-4.0.1.tgz", - "integrity": "sha512-KrPTolcw6RocpYjdC7pL7v62e55q7qOMHvLX1UCLc5AAS8qeJ6nukarEJAF2KL2PZxlbGueEbINqZR2bDe/gUw==", - "dev": true, - "requires": { - "xmlcreate": "^2.0.3" - } - }, "jsbn": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=", "optional": true }, - "jsdoc": { - "version": "3.6.6", - "resolved": "https://registry.npmjs.org/jsdoc/-/jsdoc-3.6.6.tgz", - "integrity": "sha512-znR99e1BHeyEkSvgDDpX0sTiTu+8aQyDl9DawrkOGZTTW8hv0deIFXx87114zJ7gRaDZKVQD/4tr1ifmJp9xhQ==", - "dev": true, - "requires": { - "@babel/parser": "^7.9.4", - "bluebird": "^3.7.2", - "catharsis": "^0.8.11", - "escape-string-regexp": "^2.0.0", - "js2xmlparser": "^4.0.1", - "klaw": "^3.0.0", - "markdown-it": "^10.0.0", - "markdown-it-anchor": "^5.2.7", - "marked": "^0.8.2", - "mkdirp": "^1.0.4", - "requizzle": "^0.2.3", - "strip-json-comments": "^3.1.0", - "taffydb": "2.6.2", - "underscore": "~1.10.2" - }, - "dependencies": { - "escape-string-regexp": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-2.0.0.tgz", - "integrity": "sha512-UpzcLCXolUWcNu5HtVMHYdXJjArjsF9C0aNnquZYY4uW/Vu0miy5YoWvbV345HauVvcAUnpRuhMMcqTcGOY2+w==", - "dev": true - }, - "mkdirp": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", - "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==", - "dev": true - } - } - }, "jsesc": { "version": "2.5.2", "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz", @@ -2624,15 +2548,6 @@ "verror": "1.10.0" } }, - "klaw": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/klaw/-/klaw-3.0.0.tgz", - "integrity": "sha512-0Fo5oir+O9jnXu5EefYbVK+mHMBeEVEy2cmctR1O1NECcCkPRreJKrS6Qt/j3KC2C148Dfo9i3pCmCMsdqGr0g==", - "dev": true, - "requires": { - "graceful-fs": "^4.1.9" - } - }, "lcov-parse": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/lcov-parse/-/lcov-parse-1.0.0.tgz", @@ -2649,15 +2564,6 @@ "type-check": "~0.3.2" } }, - "linkify-it": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-2.2.0.tgz", - "integrity": "sha512-GnAl/knGn+i1U/wjBz3akz2stz+HrHLsxMwHQGofCDfPvlf+gDKN58UtfmUquTY4/MXeE2x7k19KQmeoZi94Iw==", - "dev": true, - "requires": { - "uc.micro": "^1.0.1" - } - }, "load-json-file": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-2.0.0.tgz", @@ -2696,12 +2602,6 @@ "resolved": "https://registry.npmjs.org/lodash.bind/-/lodash.bind-4.2.1.tgz", "integrity": "sha1-euMBfpOWIqwxt9fX3LGzTbFpDTU=" }, - "lodash.clonedeep": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz", - "integrity": "sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8=", - "dev": true - }, "lodash.compact": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/lodash.compact/-/lodash.compact-3.0.1.tgz", @@ -2712,12 +2612,6 @@ "resolved": "https://registry.npmjs.org/lodash.defaults/-/lodash.defaults-4.2.0.tgz", "integrity": "sha1-0JF4cW/+pN3p5ft7N/bwgCJ0WAw=" }, - "lodash.escaperegexp": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/lodash.escaperegexp/-/lodash.escaperegexp-4.1.2.tgz", - "integrity": "sha1-ZHYsSGGAglGKw99Mz11YhtriA0c=", - "dev": true - }, "lodash.filter": { "version": "4.6.0", "resolved": "https://registry.npmjs.org/lodash.filter/-/lodash.filter-4.6.0.tgz", @@ -2739,18 +2633,6 @@ "resolved": "https://registry.npmjs.org/lodash.foreach/-/lodash.foreach-4.5.0.tgz", "integrity": "sha1-Gmo16s5AEoDH8G3d7DUWWrJ+PlM=" }, - "lodash.isplainobject": { - "version": "4.0.6", - "resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz", - "integrity": "sha1-fFJqUtibRcRcxpC4gWO+BJf1UMs=", - "dev": true - }, - "lodash.isstring": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz", - "integrity": "sha1-1SfftUVuynzJu5XV2ur4i6VKVFE=", - "dev": true - }, "lodash.map": { "version": "4.6.0", "resolved": "https://registry.npmjs.org/lodash.map/-/lodash.map-4.6.0.tgz", @@ -2761,12 +2643,6 @@ "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==" }, - "lodash.mergewith": { - "version": "4.6.2", - "resolved": "https://registry.npmjs.org/lodash.mergewith/-/lodash.mergewith-4.6.2.tgz", - "integrity": "sha512-GK3g5RPZWTRSeLSpgP8Xhra+pnjBC56q9FZYe1d5RN3TJ35dbkGy3YqBSMbyCrlbi+CM9Z3Jk5yTL7RCsqboyQ==", - "dev": true - }, "lodash.pick": { "version": "4.4.0", "resolved": "https://registry.npmjs.org/lodash.pick/-/lodash.pick-4.4.0.tgz", @@ -2837,45 +2713,6 @@ } } }, - "markdown-it": { - "version": "10.0.0", - "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-10.0.0.tgz", - "integrity": "sha512-YWOP1j7UbDNz+TumYP1kpwnP0aEa711cJjrAQrzd0UXlbJfc5aAq0F/PZHjiioqDC1NKgvIMX+o+9Bk7yuM2dg==", - "dev": true, - "requires": { - "argparse": "^1.0.7", - "entities": "~2.0.0", - "linkify-it": "^2.0.0", - "mdurl": "^1.0.1", - "uc.micro": "^1.0.5" - }, - "dependencies": { - "entities": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/entities/-/entities-2.0.3.tgz", - "integrity": "sha512-MyoZ0jgnLvB2X3Lg5HqpFmn1kybDiIfEQmKzTb5apr51Rb+T3KdmMiqa70T+bhGnyv7bQ6WMj2QMHpGMmlrUYQ==", - "dev": true - } - } - }, - "markdown-it-anchor": { - "version": "5.3.0", - "resolved": "https://registry.npmjs.org/markdown-it-anchor/-/markdown-it-anchor-5.3.0.tgz", - "integrity": "sha512-/V1MnLL/rgJ3jkMWo84UR+K+jF1cxNG1a+KwqeXqTIJ+jtA8aWSHuigx8lTzauiIjBDbwF3NcWQMotd0Dm39jA==", - "dev": true - }, - "marked": { - "version": "0.8.2", - "resolved": "https://registry.npmjs.org/marked/-/marked-0.8.2.tgz", - "integrity": "sha512-EGwzEeCcLniFX51DhTpmTom+dSA/MG/OBUDjnWtHbEnjAH180VzUeAw+oE4+Zv+CoYBWyRlYOTR0N8SO9R1PVw==", - "dev": true - }, - "mdurl": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/mdurl/-/mdurl-1.0.1.tgz", - "integrity": "sha1-/oWy7HWlkDfyrf7BAP1sYBdhFS4=", - "dev": true - }, "mime-db": { "version": "1.30.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.30.0.tgz", @@ -3017,12 +2854,6 @@ } } }, - "moment": { - "version": "2.22.2", - "resolved": "https://registry.npmjs.org/moment/-/moment-2.22.2.tgz", - "integrity": "sha1-PCV/mDn8DpP/UxSWMiOeuQeD/2Y=", - "dev": true - }, "ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", @@ -3141,12 +2972,6 @@ "boolbase": "~1.0.0" } }, - "number-is-nan": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz", - "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=", - "dev": true - }, "numeral": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/numeral/-/numeral-2.0.6.tgz", @@ -3667,40 +3492,12 @@ "resolved": "https://registry.npmjs.org/pngjs/-/pngjs-2.3.1.tgz", "integrity": "sha1-EdHhK5y2TWPjDBQ6Mw9MH1Z9qF8=" }, - "postcss": { - "version": "6.0.22", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-6.0.22.tgz", - "integrity": "sha512-Toc9lLoUASwGqxBSJGTVcOQiDqjK+Z2XlWBg+IgYwQMY9vA2f7iMpXVc1GpPcfTSyM5lkxNo0oDwDRO+wm7XHA==", - "dev": true, - "requires": { - "chalk": "^2.4.1", - "source-map": "^0.6.1", - "supports-color": "^5.4.0" - }, - "dependencies": { - "supports-color": { - "version": "5.4.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.4.0.tgz", - "integrity": "sha512-zjaXglF5nnWpsq470jSv6P9DwPvgLkuapYmfDm3JWOm0vkNTVF2tI4UrN2r6jH1qM/uc/WtxYY1hYoA2dOKj5w==", - "dev": true, - "requires": { - "has-flag": "^3.0.0" - } - } - } - }, "prelude-ls": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz", "integrity": "sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=", "dev": true }, - "process-nextick-args": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-1.0.7.tgz", - "integrity": "sha1-FQ4gt1ZZCtP5EJPyWk8q2L/zC6M=", - "dev": true - }, "process-on-spawn": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/process-on-spawn/-/process-on-spawn-1.0.0.tgz", @@ -3758,21 +3555,6 @@ "read-pkg": "^2.0.0" } }, - "readable-stream": { - "version": "2.3.3", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.3.tgz", - "integrity": "sha512-m+qzzcn7KUxEmd1gMbchF+Y2eIUbieUaxkWtptyHywrX0rE8QEYqPC07Vuy4Wm32/xE16NcdBctb8S0Xe/5IeQ==", - "dev": true, - "requires": { - "core-util-is": "~1.0.0", - "inherits": "~2.0.3", - "isarray": "~1.0.0", - "process-nextick-args": "~1.0.6", - "safe-buffer": "~5.1.1", - "string_decoder": "~1.0.3", - "util-deprecate": "~1.0.1" - } - }, "readdirp": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.2.0.tgz", @@ -3836,15 +3618,6 @@ "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==", "dev": true }, - "requizzle": { - "version": "0.2.3", - "resolved": "https://registry.npmjs.org/requizzle/-/requizzle-0.2.3.tgz", - "integrity": "sha512-YanoyJjykPxGHii0fZP0uUPEXpvqfBDxWV7s6GKAiiOsiqhX6vHNyW3Qzdmqp/iq/ExbhaGbVrjB4ruEVSM4GQ==", - "dev": true, - "requires": { - "lodash": "^4.17.14" - } - }, "resolve": { "version": "1.13.1", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.13.1.tgz", @@ -3924,50 +3697,6 @@ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", "dev": true }, - "sanitize-html": { - "version": "1.18.2", - "resolved": "https://registry.npmjs.org/sanitize-html/-/sanitize-html-1.18.2.tgz", - "integrity": "sha512-52ThA+Z7h6BnvpSVbURwChl10XZrps5q7ytjTwWcIe9bmJwnVP6cpEVK2NvDOUhGupoqAvNbUz3cpnJDp4+/pg==", - "dev": true, - "requires": { - "chalk": "^2.3.0", - "htmlparser2": "^3.9.0", - "lodash.clonedeep": "^4.5.0", - "lodash.escaperegexp": "^4.1.2", - "lodash.isplainobject": "^4.0.6", - "lodash.isstring": "^4.0.1", - "lodash.mergewith": "^4.6.0", - "postcss": "^6.0.14", - "srcset": "^1.0.0", - "xtend": "^4.0.0" - }, - "dependencies": { - "domutils": { - "version": "1.7.0", - "resolved": "https://registry.npmjs.org/domutils/-/domutils-1.7.0.tgz", - "integrity": "sha512-Lgd2XcJ/NjEw+7tFvfKxOzCYKZsdct5lczQ2ZaQY8Djz7pfAD3Gbp8ySJWtreII/vDlMVmxwa6pHmdxIYgttDg==", - "dev": true, - "requires": { - "dom-serializer": "0", - "domelementtype": "1" - } - }, - "htmlparser2": { - "version": "3.9.2", - "resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-3.9.2.tgz", - "integrity": "sha1-G9+HrMoPP55T+k/M6w9LTLsAszg=", - "dev": true, - "requires": { - "domelementtype": "^1.3.0", - "domhandler": "^2.3.0", - "domutils": "^1.5.1", - "entities": "^1.1.1", - "inherits": "^2.0.1", - "readable-stream": "^2.0.2" - } - } - } - }, "semver": { "version": "5.4.1", "resolved": "https://registry.npmjs.org/semver/-/semver-5.4.1.tgz", @@ -4098,16 +3827,6 @@ "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", "dev": true }, - "srcset": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/srcset/-/srcset-1.0.0.tgz", - "integrity": "sha1-pWad4StC87HV6D7QPHEEb8SPQe8=", - "dev": true, - "requires": { - "array-uniq": "^1.0.2", - "number-is-nan": "^1.0.0" - } - }, "sshpk": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.14.1.tgz", @@ -4177,15 +3896,6 @@ "function-bind": "^1.1.1" } }, - "string_decoder": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz", - "integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==", - "dev": true, - "requires": { - "safe-buffer": "~5.1.0" - } - }, "strip-ansi": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", @@ -4209,12 +3919,6 @@ "integrity": "sha1-IzTBjpx1n3vdVv3vfprj1YjmjtM=", "dev": true }, - "strip-json-comments": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", - "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==", - "dev": true - }, "supports-color": { "version": "5.5.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", @@ -4279,12 +3983,6 @@ } } }, - "taffydb": { - "version": "2.6.2", - "resolved": "https://registry.npmjs.org/taffydb/-/taffydb-2.6.2.tgz", - "integrity": "sha1-fLy2S1oUG2ou/CxdLGe04VCyomg=", - "dev": true - }, "test-exclude": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/test-exclude/-/test-exclude-6.0.0.tgz", @@ -4405,18 +4103,6 @@ "is-typedarray": "^1.0.0" } }, - "uc.micro": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-1.0.6.tgz", - "integrity": "sha512-8Y75pvTYkLJW2hWQHXxoqRgV7qb9B+9vFEtidML+7koHUFapnVJAZ6cKs+Qjz5Aw3aZWHMC6u0wJE3At+nSGwA==", - "dev": true - }, - "underscore": { - "version": "1.10.2", - "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.10.2.tgz", - "integrity": "sha512-N4P+Q/BuyuEKFJ43B9gYuOj4TQUHXX+j2FqguVOpjkssLUUrnJofCcBccJSCoeturDoZU6GorDTHSvUDlSQbTg==", - "dev": true - }, "uniq": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/uniq/-/uniq-1.0.1.tgz", @@ -4594,18 +4280,6 @@ "resolved": "https://registry.npmjs.org/ws/-/ws-7.4.6.tgz", "integrity": "sha512-YmhHDO4MzaDLB+M9ym/mDA5z0naX8j7SIlT8f8z+I0VtzsRbekxEutHSme7NPS2qE8StCYQNUnfWdXta/Yu85A==" }, - "xmlcreate": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/xmlcreate/-/xmlcreate-2.0.3.tgz", - "integrity": "sha512-HgS+X6zAztGa9zIK3Y3LXuJes33Lz9x+YyTxgrkIdabu2vqcGOWwdfCpf1hWLRrd553wd4QCDf6BBO6FfdsRiQ==", - "dev": true - }, - "xtend": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz", - "integrity": "sha1-pcbVMr5lbiPbgg77lDofBJmNY68=", - "dev": true - }, "y18n": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.1.tgz", diff --git a/package.json b/package.json index 9807b52..f70bb0b 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Query prices form nexus-stats.com and warframe.market.", "main": "index.js", "scripts": { - "test": "nyc --reporter=lcov mocha", + "test": "nyc mocha", "coverage": "npm test && nyc report --reporter=text-lcov | coveralls", "build-docs": "jsdoc -c jsdoc-config.json -d docs", "lint": "eslint index.js lib/ test/", @@ -51,8 +51,6 @@ "eslint": "^6.1.0", "eslint-config-airbnb-base": "^14.0.0", "eslint-plugin-import": "^2.19.1", - "ink-docstrap": "^1.3.2", - "jsdoc": "^3.6.6", "mocha": "^7.1.1", "nyc": "^15.1.0" }, @@ -106,5 +104,21 @@ "no-await-in-loop": "off", "import/no-unresolved": 0 } + }, + "mocha": { + "spec": "test/test.js", + "timeout": 10000, + "bail": true + }, + "nyc": { + "reporter": [ + "lcov", + "text" + ], + "skip-full": true, + "exclude": [ + "test/*", + "lib/nexus/*" + ] } } diff --git a/test/attachment-test.js b/test/attachment-test.js new file mode 100644 index 0000000..851a412 --- /dev/null +++ b/test/attachment-test.js @@ -0,0 +1,42 @@ +'use strict'; + +/* eslint-disable no-console */ + +const fetch = require('node-fetch'); +const Querier = require('../index.js'); + +const id = process.env.TEST_WH_ID; +const token = process.env.TEST_WH_TOKEN; +const webhook = `https://canary.discord.com/api/webhooks/${id}/${token}`; + +const querier = new Querier({ logger: console, skipNexus: true }); + +const tearDown = async () => { + try { + await querier.stopUpdating(); + console.log('tore down stuff'); + process.exit(0); + } catch (e) { + console.error(e); + process.exit(1); + } +}; + +setTimeout(async () => { + const embeds = await querier.priceCheckQueryAttachment('gara prime', null, 'xb1'); + if (embeds && embeds[0] && embeds[0].fields && embeds[0].fields.length) { + const res = await fetch(webhook, { + method: 'POST', + body: JSON.stringify({ embeds }), + headers: { 'Content-Type': 'application/json' }, + }); + console.log(`response: ${await res.text()}`); + if (res.ok) { + } else { + console.error(`fail! ${res.ok} ${JSON.stringify(embeds)}`); + } + } else { + console.error(JSON.stringify(embeds)); + } + tearDown(); +}, 5000); diff --git a/test/test.js b/test/test.js index 2799de9..a115a1e 100644 --- a/test/test.js +++ b/test/test.js @@ -16,7 +16,8 @@ const logger = { log: () => {}, info: () => {}, // eslint-disable-next-line no-console - // turn on to debug error: (e) => console.error(e), + // turn on to debug + // error: (e) => console.error(e), error: () => {}, silly: () => {}, }; @@ -24,45 +25,68 @@ const logger = { const settings = new Settings(); const marketCache = new Cache(settings.urls.market, settings.maxCacheLength, { logger, - delayStart: true, + delayStart: false, }); const should = chai.should(); const querystring = 'loki prime'; -const nexus = new WFNQ({ logger, marketCache }); +const nexus = new WFNQ({ logger, marketCache, skipNexus: true }); -beforeEach((done) => setTimeout(done, 500)); describe('Nexus Query', () => { - const testQueryWithPlatform = async (platform) => { - const result = await nexus.priceCheckQueryAttachment(querystring, null, platform); - - result.should.be.an('array'); - const embed = result[0]; - embed.should.be.an('object'); - embed.type.should.equal('rich'); - embed.should.have.own.property('title'); - embed.title.should.have.string(`[${settings.lookupAlias(platform).toUpperCase()}]`); - embed.title.toLowerCase().should.have.string(querystring); - }; + beforeEach(done => setTimeout(done, 750)); - describe('price check query attachment', () => { + describe('price check query string', () => { it('should throw errors when called without query', async () => { try { - await nexus.priceCheckQueryAttachment(); + await nexus.priceCheckQueryString(); } catch (error) { should.exist(error); } }); + it('should create a string when called with string query', async () => { + const result = await nexus.priceCheckQueryString(querystring); + result.should.be.an('string'); + }); + it('should create a string when querying for a mod', async () => { + const modString = 'Vermillion Storm'; + const result = await nexus.priceCheckQueryString(modString); + result.should.be.a('string'); + result.should.have.string(modString); + }); + it('should create an no results string for query', async () => { + try { + const result = await nexus.priceCheckQueryString('nonagon'); + result.should.be.a('string'); + } catch (error) { + should.not.exist(error); + } + }); describe('when providing a platform', () => { - beforeEach((done) => setTimeout(done, 7000)); + const testQueryWithPlatform = async (platform) => { + const result = await nexus.priceCheckQueryString(querystring, null, platform); + result.should.be.a('string'); + result.should.have.string(querystring); + }; + Object.keys(settings.platforms).forEach(async (platform) => { - it(`should accomodate ${platform}`, async () => testQueryWithPlatform(platform)); + if (typeof settings.platforms[platform] === 'string') { + it(`should accomodate ${platform}`, async () => testQueryWithPlatform(platform)); + } }); }); + }); + describe('price check query attachment', () => { + it('should throw errors when called without query', async () => { + try { + await nexus.priceCheckQueryAttachment(); + } catch (error) { + should.exist(error); + } + }); it('should create an attachment when called with attachment query', async () => { const result = await nexus.priceCheckQueryAttachment(querystring); result.should.be.an('array'); @@ -72,7 +96,6 @@ describe('Nexus Query', () => { result[0].fields.should.be.an('array'); result[0].fields.length.should.equal(5); }); - it('should create an attachment when querying for a mod', async () => { const modString = 'Vermillion Storm'; const result = await nexus.priceCheckQueryAttachment(modString); @@ -84,7 +107,6 @@ describe('Nexus Query', () => { embed.fields[0].should.be.an('object'); }); - it('should create an no results for attachment query', async () => { try { const result = await nexus.priceCheckQueryAttachment('nonagon'); @@ -95,5 +117,25 @@ describe('Nexus Query', () => { should.not.exist(error); } }); + + describe('when providing a platform', () => { + const testQueryWithPlatform = async (platform) => { + const result = await nexus.priceCheckQueryAttachment(querystring, null, platform); + + result.should.be.an('array'); + const embed = result[0]; + embed.should.be.an('object'); + embed.type.should.equal('rich'); + embed.should.have.own.property('title'); + embed.title.should.have.string(`[${settings.lookupAlias(platform).toUpperCase()}]`); + embed.title.toLowerCase().should.have.string(querystring); + }; + + Object.keys(settings.platforms).forEach(async (platform) => { + if (typeof settings.platforms[platform] === 'string') { + it(`should accomodate ${platform}`, async () => testQueryWithPlatform(platform)); + } + }); + }); }); });