diff --git a/.babelrc b/.babelrc index d91fd10..c28415d 100644 --- a/.babelrc +++ b/.babelrc @@ -1,8 +1,10 @@ { - "compact": "true", "presets": ["es2015"], "plugins": ["transform-object-assign"], "env": { + "test": { + "plugins": ["rewire"] + }, "production": { "plugins": ["add-module-exports"] } diff --git a/.eslintrc b/.eslintrc index edca18e..174fb4c 100644 --- a/.eslintrc +++ b/.eslintrc @@ -2,12 +2,16 @@ "extends": "standard", "rules": { "semi": [2, "always"], - "space-before-function-paren": [2, "never"] + "space-before-function-paren": [2, "never"], + "key-spacing": ["error", {"align": "value"}] }, "globals": { "it": true, "should": true, "describe": true, "before": true, + "after": true, + "__Rewire__": true, + "__ResetDependency__": true } } diff --git a/.gitignore b/.gitignore index 3e32e7b..9f6d15d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ node_modules/ npm-debug.log .tmp/ dist/ +docs/web/* coverage/ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..73e35fb --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,33 @@ +# Contributing + +## Rebuild source: + +In case you want to build your own bundle for client + +1. Clone this repository + + ```bash + git clone git@github.com:ticketmaster-api/sdk-javascript.git + ``` + +1. install dependencies + + ```bash + npm install + ``` + +1. Run npm script: + + ```bash + npm run build + ``` + +## Running Tests + + ```bash + npm test + ``` + +## Contact Us + +[internal only] Find us in #open-platform on Ticketmaster Slack! diff --git a/config/docs/index.html b/config/docs/index.html new file mode 100644 index 0000000..ed781db --- /dev/null +++ b/config/docs/index.html @@ -0,0 +1,47 @@ + + + + + <%= htmlWebpackPlugin.options.title %> + + + + +

Logging to console...

+ + + diff --git a/config/webpack/config.js b/config/webpack/config.js index 552d853..dc3f43a 100644 --- a/config/webpack/config.js +++ b/config/webpack/config.js @@ -7,19 +7,19 @@ function getFilename(suffix) { } const settings = (options) => ({ - entry: './lib/index.js', + entry: './lib/index.js', output: Object.assign({}, { - filename: `node/${pkg.name}.js`, - library: pkg.name, + filename: `node/${pkg.name}.js`, + library: pkg.name, libraryTarget: 'umd', - path: path.resolve(process.cwd(), 'dist') + path: path.resolve(process.cwd(), 'dist') }, options.output), devtool: options.devtool, - module: { + module: { loaders: [ { - test: /\.js$/, - loader: 'babel', + test: /\.js$/, + loader: 'babel', include: path.join(process.cwd(), 'lib') } ] diff --git a/config/webpack/webpack.config.dev.babel.js b/config/webpack/webpack.config.dev.babel.js new file mode 100644 index 0000000..753a972 --- /dev/null +++ b/config/webpack/webpack.config.dev.babel.js @@ -0,0 +1,15 @@ +import webpack from 'webpack'; + +import {settings, getFilename} from './config'; + +const config = settings({ + output: { + filename: 'web/' + getFilename('.js') + }, + devtool: 'source-map', + plugins: [ + new webpack.NoErrorsPlugin() + ] +}); + +export default config; diff --git a/config/webpack/webpack.config.prod.babel.js b/config/webpack/webpack.config.prod.babel.js new file mode 100644 index 0000000..052413c --- /dev/null +++ b/config/webpack/webpack.config.prod.babel.js @@ -0,0 +1,34 @@ +import webpack from 'webpack'; +import HtmlWebpackPlugin from 'html-webpack-plugin'; + +import {version} from '../../package.json'; +import {settings, getFilename} from './config'; + +const config = settings({ + devtool: false, + + output: { + filename: 'web/' + getFilename('.min.js') + }, + + plugins: [ + // Webpack2 specific :( + // new webpack.LoaderOptionsPlugin({ + // minimize: true, + // debug: false + // }), + new webpack.optimize.UglifyJsPlugin({ + compress: {warnings: false}, + comments: false, + sourceMap: false + }), + new HtmlWebpackPlugin({ + title: 'Ticketmaster SDK: ' + version, + filename: '../docs/web/index.html', + template: 'config/docs/index.html', + inject: 'head' + }) + ] +}); + +export default config; diff --git a/config/webpack/webpack.config.web.babel.js b/config/webpack/webpack.config.web.babel.js deleted file mode 100644 index af9349c..0000000 --- a/config/webpack/webpack.config.web.babel.js +++ /dev/null @@ -1,23 +0,0 @@ -import webpack from 'webpack'; - -import {settings, getFilename} from './config'; - -const config = settings({ - output: { - filename: 'web/' + getFilename('.min.js') - }, - devtool: false, - plugins: [ - new webpack.LoaderOptionsPlugin({ - minimize: true, - debug: false - }), - new webpack.optimize.UglifyJsPlugin({ - compress: {warnings: false}, - comments: false, - sourceMap: false - }) - ] -}); - -export default config; diff --git a/docs/index.html b/docs/index.html deleted file mode 100644 index ab72c4a..0000000 --- a/docs/index.html +++ /dev/null @@ -1,35 +0,0 @@ - - - - - TMAPI - - - - - - - - diff --git a/docs/node/es5/event.js b/docs/node/es5/event.js new file mode 100644 index 0000000..34402fc --- /dev/null +++ b/docs/node/es5/event.js @@ -0,0 +1,17 @@ +var Event = require('../../../dist/node/discovery/v2').Event + +function logNextPage(page) { + console.log(page.page.number, page.items.map(function(item) { + return item.name + })) + + return page.getNext() +} + +Event('YOUR_API_KEY').all({page: 4, size: 5, city: 'London'}) + .then(logNextPage) + .then(logNextPage) + .then(logNextPage) + .catch(function(e) { + console.log(e) + }) diff --git a/docs/test.js b/docs/node/es5/sdk.js similarity index 78% rename from docs/test.js rename to docs/node/es5/sdk.js index 421d6cd..a4c1474 100644 --- a/docs/test.js +++ b/docs/node/es5/sdk.js @@ -1,6 +1,6 @@ -var tmapi = require('../dist/node'); +var ticketmaster = require('../../../dist/node/index'); -var sdk = tmapi('YOUR_KEY_HERE'); +var sdk = ticketmaster('YOUR_API_KEY'); function logNextPage(page) { console.log(page.page.number, page.items.map(function(item) { diff --git a/docs/node/es6/event.js b/docs/node/es6/event.js new file mode 100644 index 0000000..7c8cfdc --- /dev/null +++ b/docs/node/es6/event.js @@ -0,0 +1,13 @@ +import {Event} from '../../../dist/node/discovery/v2' + +const logNextPage = (page) => { + console.log(page.page.number, page.items.map(({name}) => name)) + + return page.getNext() +} + +Event('YOUR_API_KEY').all({page: 4, size: 5, city: 'London'}) + .then(logNextPage) + .then(logNextPage) + .then(logNextPage) + .catch((e) => console.log(e)) diff --git a/docs/node/es6/sdk.js b/docs/node/es6/sdk.js new file mode 100644 index 0000000..9368f25 --- /dev/null +++ b/docs/node/es6/sdk.js @@ -0,0 +1,17 @@ +import ticketmaster from '../../../dist/node' + +const sdk = ticketmaster('YOUR_API_KEY') + +const logNextPage = (page) => { + console.log(page.page.number, page.items.map(({name}) => name)) + + return page.getNext() +} + +if (sdk) { + sdk.discovery.v2.event.all({page: 4, size: 5, city: 'London'}) + .then(logNextPage) + .then(logNextPage) + .then(logNextPage) + .catch((e) => console.log(e)) +} diff --git a/lib/commerce/v2.js b/lib/commerce/v2.js new file mode 100644 index 0000000..d2a0ec3 --- /dev/null +++ b/lib/commerce/v2.js @@ -0,0 +1,11 @@ +import find from '../utils/find'; + +const api = 'commerce/v2'; + +export const Offer = (apikey) => ({ + find: find(api, apikey, 'events', 'offers') +}); + +export default (apikey) => ({ + offer: Offer(apikey) +}); diff --git a/lib/commerce/v2/index.js b/lib/commerce/v2/index.js deleted file mode 100644 index 383bc9d..0000000 --- a/lib/commerce/v2/index.js +++ /dev/null @@ -1,7 +0,0 @@ -import offer from './offer'; - -export const api = 'commerce/v2'; - -export default (apikey) => ({ - offer: offer(apikey) -}); diff --git a/lib/commerce/v2/offer.js b/lib/commerce/v2/offer.js deleted file mode 100644 index 20c3d7b..0000000 --- a/lib/commerce/v2/offer.js +++ /dev/null @@ -1,7 +0,0 @@ -import find from '../../utils/find'; - -import {api} from './'; - -export default (apikey) => ({ - find: find(api, apikey, 'events', 'offers') -}); diff --git a/lib/discovery/v1.js b/lib/discovery/v1.js new file mode 100644 index 0000000..e5b41c1 --- /dev/null +++ b/lib/discovery/v1.js @@ -0,0 +1,32 @@ +import all from '../utils/all'; +import find from '../utils/find'; + +export const api = 'discovery/v1'; + +export const Attraction = (apikey) => ({ + all: all(api, apikey, 'attractions'), + find: find(api, apikey, 'attractions') +}); + +export const Category = (apikey) => ({ + all: all(api, apikey, 'categories'), + find: find(api, apikey, 'categories') +}); + +export const Event = (apikey) => ({ + all: all(api, apikey, 'events'), + find: find(api, apikey, 'events'), + findImages: find(api, apikey, 'events', 'images') +}); + +export const Venue = (apikey) => ({ + all: all(api, apikey, 'venues'), + find: find(api, apikey, 'venues') +}); + +export default (apikey) => ({ + attraction: Attraction(apikey), + category: Category(apikey), + event: Event(apikey), + venue: Venue(apikey) +}); diff --git a/lib/discovery/v1/attraction.js b/lib/discovery/v1/attraction.js deleted file mode 100644 index 34957c4..0000000 --- a/lib/discovery/v1/attraction.js +++ /dev/null @@ -1,9 +0,0 @@ -import all from '../../utils/all'; -import find from '../../utils/find'; - -import {api} from './'; - -export default (apiKey) => ({ - all: all(api, apiKey, 'attractions'), - find: find(api, apiKey, 'attractions') -}); diff --git a/lib/discovery/v1/category.js b/lib/discovery/v1/category.js deleted file mode 100644 index 3fa29a9..0000000 --- a/lib/discovery/v1/category.js +++ /dev/null @@ -1,9 +0,0 @@ -import all from '../../utils/all'; -import find from '../../utils/find'; - -import {api} from './'; - -export default (apiKey) => ({ - all: all(api, apiKey, 'categories'), - find: find(api, apiKey, 'categories') -}); diff --git a/lib/discovery/v1/event.js b/lib/discovery/v1/event.js deleted file mode 100644 index 7bc63c2..0000000 --- a/lib/discovery/v1/event.js +++ /dev/null @@ -1,9 +0,0 @@ -import all from '../../utils/all'; -import find from '../../utils/find'; - -import {api} from './'; - -export default (apiKey) => ({ - all: all(api, apiKey, 'events'), - find: find(api, apiKey, 'events') -}); diff --git a/lib/discovery/v1/index.js b/lib/discovery/v1/index.js deleted file mode 100644 index ccf6f01..0000000 --- a/lib/discovery/v1/index.js +++ /dev/null @@ -1,13 +0,0 @@ -import attraction from './attraction'; -import category from './category'; -import event from './event'; -import venue from './venue'; - -export const api = 'discovery/v1'; - -export default (apiKey) => ({ - attraction: attraction(apiKey), - category: category(apiKey), - event: event(apiKey), - venue: venue(apiKey) -}); diff --git a/lib/discovery/v1/venue.js b/lib/discovery/v1/venue.js deleted file mode 100644 index c33fe1d..0000000 --- a/lib/discovery/v1/venue.js +++ /dev/null @@ -1,9 +0,0 @@ -import all from '../../utils/all'; -import find from '../../utils/find'; - -import {api} from './'; - -export default (apiKey) => ({ - all: all(api, apiKey, 'venues'), - find: find(api, apiKey, 'venues') -}); diff --git a/lib/discovery/v2.js b/lib/discovery/v2.js new file mode 100644 index 0000000..c84299a --- /dev/null +++ b/lib/discovery/v2.js @@ -0,0 +1,32 @@ +import all from '../utils/all'; +import find from '../utils/find'; + +const api = 'discovery/v2'; + +export const Attraction = (apikey) => ({ + all: all(api, apikey, 'attractions'), + find: find(api, apikey, 'attractions') +}); + +export const Classification = (apikey) => ({ + all: all(api, apikey, 'classifications'), + find: find(api, apikey, 'classifications') +}); + +export const Event = (apikey) => ({ + all: all(api, apikey, 'events'), + find: find(api, apikey, 'events'), + findImages: find(api, apikey, 'events', 'images') +}); + +export const Venue = (apikey) => ({ + all: all(api, apikey, 'venues'), + find: find(api, apikey, 'venues') +}); + +export default (apikey) => ({ + attraction: Attraction(apikey), + classification: Classification(apikey), + event: Event(apikey), + venue: Venue(apikey) +}); diff --git a/lib/discovery/v2/attraction.js b/lib/discovery/v2/attraction.js deleted file mode 100644 index 34957c4..0000000 --- a/lib/discovery/v2/attraction.js +++ /dev/null @@ -1,9 +0,0 @@ -import all from '../../utils/all'; -import find from '../../utils/find'; - -import {api} from './'; - -export default (apiKey) => ({ - all: all(api, apiKey, 'attractions'), - find: find(api, apiKey, 'attractions') -}); diff --git a/lib/discovery/v2/classification.js b/lib/discovery/v2/classification.js deleted file mode 100644 index 0ebfd02..0000000 --- a/lib/discovery/v2/classification.js +++ /dev/null @@ -1,9 +0,0 @@ -import all from '../../utils/all'; -import find from '../../utils/find'; - -import {api} from './'; - -export default (apiKey) => ({ - all: all(api, apiKey, 'classifications'), - find: find(api, apiKey, 'classifications') -}); diff --git a/lib/discovery/v2/event.js b/lib/discovery/v2/event.js deleted file mode 100644 index 3534d59..0000000 --- a/lib/discovery/v2/event.js +++ /dev/null @@ -1,10 +0,0 @@ -import all from '../../utils/all'; -import find from '../../utils/find'; - -import {api} from './'; - -export default (apiKey) => ({ - all: all(api, apiKey, 'events'), - find: find(api, apiKey, 'events'), - findImages: find(api, apiKey, 'events', 'images') -}); diff --git a/lib/discovery/v2/index.js b/lib/discovery/v2/index.js deleted file mode 100644 index a48b00d..0000000 --- a/lib/discovery/v2/index.js +++ /dev/null @@ -1,13 +0,0 @@ -import attraction from './attraction'; -import classification from './classification'; -import event from './event'; -import venue from './venue'; - -export const api = 'discovery/v2'; - -export default (apiKey) => ({ - attraction: attraction(apiKey), - classification: classification(apiKey), - event: event(apiKey), - venue: venue(apiKey) -}); diff --git a/lib/discovery/v2/venue.js b/lib/discovery/v2/venue.js deleted file mode 100644 index c33fe1d..0000000 --- a/lib/discovery/v2/venue.js +++ /dev/null @@ -1,9 +0,0 @@ -import all from '../../utils/all'; -import find from '../../utils/find'; - -import {api} from './'; - -export default (apiKey) => ({ - all: all(api, apiKey, 'venues'), - find: find(api, apiKey, 'venues') -}); diff --git a/lib/index.js b/lib/index.js index 16ed79d..7958439 100644 --- a/lib/index.js +++ b/lib/index.js @@ -2,14 +2,14 @@ import discovery from './discovery/index'; import commerce from './commerce/index'; const API = (apikey) => { - if (apikey === 'YOUR_KEY_HERE') { + if (apikey === 'YOUR_API_KEY') { return console.log('Please apply for your key at https://live-livenation.devportal.apigee.com/user/register'); } return { apikey, discovery: discovery(apikey), - commerce: commerce(apikey) + commerce: commerce(apikey) }; }; diff --git a/lib/page.js b/lib/page.js index f407298..d560a20 100644 --- a/lib/page.js +++ b/lib/page.js @@ -6,7 +6,7 @@ import getData from './utils/getData'; * @constructor */ class Page { - constructor({_embedded, page}, path, qs) { + constructor({_embedded = [], page}, path, qs) { const itemKey = Object.keys(_embedded)[0]; this.items = _embedded[itemKey]; @@ -24,7 +24,7 @@ class Page { getAt(n) { const qs = Object.assign({}, this.qs, {page: n}); - if (n > 0 && n <= this.page.totalPages) { + if (n >= 0 && n <= this.page.totalPages) { return getData({path: this.path, qs}); } @@ -58,13 +58,17 @@ class Page { const n = this.page.number - step; const qs = Object.assign({}, this.qs, {page: n}); - if (n > 0) { + if (n >= 0) { return getData({path: this.path, qs}); } return Promise.reject({message: 'No previous page! You are on the first one.', qs}); }; + isFirst() { + return this.page.number === 0; + }; + /** * Method of Page object type * Checker if current result page is the last one @@ -75,12 +79,20 @@ class Page { }; /** - * Method of Page object type - * @returns {number} quantity of all items of the same type + * Quantity of all items matching criteria + * @returns {number} */ count() { return this.page.totalElements; }; + + /** + * Quantity of all pages matching criteria + * @returns {number} + */ + pages() { + return this.page.totalPages; + }; } export default Page; diff --git a/lib/utils/all.js b/lib/utils/all.js index 5206d5c..06483a6 100644 --- a/lib/utils/all.js +++ b/lib/utils/all.js @@ -5,7 +5,7 @@ export default (api, apikey, type) => (qs = {}) => { const params = { path: [api, type], - qs: qs + qs: qs }; return getData(params); diff --git a/lib/utils/find.js b/lib/utils/find.js index d2f06e5..2e883eb 100644 --- a/lib/utils/find.js +++ b/lib/utils/find.js @@ -3,7 +3,7 @@ import getData from './getData'; export default (api, apikey, type, ...path) => (eventId) => { const params = { path: [api, type, eventId, ...path], - qs: {apikey} + qs: {apikey} }; return getData(params); diff --git a/lib/utils/getData.js b/lib/utils/getData.js index 76cb810..f1aba6a 100644 --- a/lib/utils/getData.js +++ b/lib/utils/getData.js @@ -4,7 +4,7 @@ import queryString from 'query-string'; import config from '../config'; import Page from '../page'; -const getURL = (path, qs) => { +export const getURL = (path, qs) => { return `${[config.baseURL].concat(path).join('/')}?${queryString.stringify(qs)}`; }; diff --git a/package.json b/package.json index 5001474..3a95ebd 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "clean": "rimraf ./dist", "build": "npm run prod:web && npm run prod:node", "prod:node": "cross-env NODE_ENV=production babel lib -d dist/node", - "prod:web": "cross-env NODE_ENV=production webpack --config ./config/webpack/webpack.config.web.babel.js", + "prod:web": "cross-env NODE_ENV=production webpack --config ./config/webpack/webpack.config.prod.babel.js", "stats:web": "npm run prod:web -- --display-modules --sort-modules-by size", "test": "cross-env NODE_ENV=test mocha", "lint": "eslint ./lib ./test", @@ -31,29 +31,30 @@ "author": "Adam Meghji", "license": "MIT", "devDependencies": { - "babel-cli": "6.11.4", - "babel-core": "6.13.1", - "babel-loader": "6.2.4", + "babel-cli": "6.14.0", + "babel-core": "6.14.0", + "babel-loader": "6.2.5", "babel-plugin-add-module-exports": "0.2.1", + "babel-plugin-rewire": "1.0.0-rc-7", "babel-plugin-transform-object-assign": "6.8.0", - "babel-preset-es2015": "6.13.1", - "babel-preset-es2015-webpack": "6.4.2", - "babel-register": "6.11.6", + "babel-preset-es2015": "6.14.0", + "babel-register": "6.14.0", "chai": "3.5.0", - "cross-env": "2.0.0", - "eslint": "3.2.2", - "eslint-config-standard": "5.3.5", - "eslint-plugin-promise": "2.0.0", + "cross-env": "2.0.1", + "eslint": "3.4.0", + "eslint-config-standard": "6.0.0", + "eslint-plugin-promise": "2.0.1", "eslint-plugin-standard": "2.0.0", + "html-webpack-plugin": "2.22.0", "husky": "0.11.6", "inherits": "2.0.1", - "mocha": "3.0.1", + "mocha": "3.0.2", "nock": "8.0.0", "rimraf": "2.5.4", - "webpack": "2.1.0-beta.20" + "webpack": "1.13.2" }, "dependencies": { - "query-string": "4.2.2", + "query-string": "4.2.3", "isomorphic-fetch": "2.2.1" }, "homepage": "https://github.com/ticketmaster-api/sdk-javascript" diff --git a/test/commerce/v2/offer/find.js b/test/commerce/v2/offer/find.js index 16e9287..85d3125 100644 --- a/test/commerce/v2/offer/find.js +++ b/test/commerce/v2/offer/find.js @@ -1,6 +1,6 @@ import {back as nockBack} from 'nock'; -import Offer from '../../../../lib/commerce/v2/offer'; +import {Offer} from '../../../../lib/commerce/v2'; describe('commerce.v2.offer.find', () => { before(() => { diff --git a/test/commerce/v2/offer/index.js b/test/commerce/v2/offer/index.js index 519822c..4d9a2cb 100644 --- a/test/commerce/v2/offer/index.js +++ b/test/commerce/v2/offer/index.js @@ -1,8 +1,8 @@ -import event from '../../../../lib/commerce/v2/offer'; +import {Offer} from '../../../../lib/commerce/v2'; describe('commerce.v2.offer', () => { it('should provide find', (done) => { - event().should.have.property('find'); + Offer().should.have.property('find'); done(); }); }); diff --git a/test/discovery/v1/attraction/find.js b/test/discovery/v1/attraction/find.js index e7307aa..3b04807 100644 --- a/test/discovery/v1/attraction/find.js +++ b/test/discovery/v1/attraction/find.js @@ -1,6 +1,6 @@ import {back as nockBack} from 'nock'; -import Attraction from '../../../../lib/discovery/v1/attraction'; +import {Attraction} from '../../../../lib/discovery/v1'; describe('discovery.v1.attraction.find', () => { before(() => { diff --git a/test/discovery/v1/attraction/index.js b/test/discovery/v1/attraction/index.js deleted file mode 100644 index cc400f6..0000000 --- a/test/discovery/v1/attraction/index.js +++ /dev/null @@ -1,8 +0,0 @@ -import attraction from '../../../../lib/discovery/v1/attraction'; - -describe('discovery.v1.attraction', () => { - it('should provide find', done => { - attraction().should.have.property('find'); - done(); - }); -}); diff --git a/test/discovery/v1/category/find.js b/test/discovery/v1/category/find.js index c55b75c..cb4aab8 100644 --- a/test/discovery/v1/category/find.js +++ b/test/discovery/v1/category/find.js @@ -1,6 +1,6 @@ import {back as nockBack} from 'nock'; -import Category from '../../../../lib/discovery/v1/category'; +import {Category} from '../../../../lib/discovery/v1'; describe('discovery.v1.category.find', () => { before(() => { diff --git a/test/discovery/v1/category/index.js b/test/discovery/v1/category/index.js deleted file mode 100644 index 008d7e5..0000000 --- a/test/discovery/v1/category/index.js +++ /dev/null @@ -1,8 +0,0 @@ -import category from '../../../../lib/discovery/v1/category'; - -describe('discovery.v1.category', () => { - it('should provide find', done => { - category().should.have.property('find'); - done(); - }); -}); diff --git a/test/discovery/v1/event/all.js b/test/discovery/v1/event/all.js index 90d5226..448a86c 100644 --- a/test/discovery/v1/event/all.js +++ b/test/discovery/v1/event/all.js @@ -1,6 +1,6 @@ import {back as nockBack} from 'nock'; -import Event from '../../../../lib/discovery/v1/event'; +import {Event} from '../../../../lib/discovery/v1'; describe('discovery.v1.event.all', () => { before(() => { diff --git a/test/discovery/v1/event/find.js b/test/discovery/v1/event/find.js index d5d7960..515bc06 100644 --- a/test/discovery/v1/event/find.js +++ b/test/discovery/v1/event/find.js @@ -1,6 +1,6 @@ import {back as nockBack} from 'nock'; -import Event from '../../../../lib/discovery/v1/event'; +import {Event} from '../../../../lib/discovery/v1'; describe('discovery.v1.event.find', () => { before(() => { diff --git a/test/discovery/v1/event/index.js b/test/discovery/v1/event/index.js deleted file mode 100644 index 18e2145..0000000 --- a/test/discovery/v1/event/index.js +++ /dev/null @@ -1,13 +0,0 @@ -import event from '../../../../lib/discovery/v1/event'; - -describe('discovery.v1.event', () => { - it('should provide find', done => { - event().should.have.property('find'); - done(); - }); - - it('should provide all', done => { - event().should.have.property('all'); - done(); - }); -}); diff --git a/test/discovery/v1/venue/find.js b/test/discovery/v1/venue/find.js index 967a531..13cc6bc 100644 --- a/test/discovery/v1/venue/find.js +++ b/test/discovery/v1/venue/find.js @@ -1,6 +1,6 @@ import {back as nockBack} from 'nock'; -import Venue from '../../../../lib/discovery/v1/venue'; +import {Venue} from '../../../../lib/discovery/v1'; describe('discovery.v1.venue.find', () => { before(() => { diff --git a/test/discovery/v1/venue/index.js b/test/discovery/v1/venue/index.js deleted file mode 100644 index a58c185..0000000 --- a/test/discovery/v1/venue/index.js +++ /dev/null @@ -1,8 +0,0 @@ -import venue from '../../../../lib/discovery/v1/venue'; - -describe('discovery.v1.venue', () => { - it('should provide find', (done) => { - venue().should.have.property('find'); - done(); - }); -}); diff --git a/test/discovery/v2/attraction/all.js b/test/discovery/v2/attraction/all.js index dcba7da..a548027 100644 --- a/test/discovery/v2/attraction/all.js +++ b/test/discovery/v2/attraction/all.js @@ -1,6 +1,6 @@ import {back as nockBack} from 'nock'; -import Attraction from '../../../../lib/discovery/v2/attraction'; +import {Attraction} from '../../../../lib/discovery/v2'; describe('discovery.v2.attraction.all', () => { before(() => { diff --git a/test/discovery/v2/attraction/find.js b/test/discovery/v2/attraction/find.js index 2c110a4..d991f82 100644 --- a/test/discovery/v2/attraction/find.js +++ b/test/discovery/v2/attraction/find.js @@ -1,6 +1,6 @@ import {back as nockBack} from 'nock'; -import Attraction from '../../../../lib/discovery/v2/attraction'; +import {Attraction} from '../../../../lib/discovery/v2'; describe('discovery.v2.attraction.find', () => { before(() => { diff --git a/test/discovery/v2/attraction/index.js b/test/discovery/v2/attraction/index.js deleted file mode 100644 index 29a3aad..0000000 --- a/test/discovery/v2/attraction/index.js +++ /dev/null @@ -1,13 +0,0 @@ -import Attraction from '../../../../lib/discovery/v2/attraction'; - -describe('discovery.v2.attraction', () => { - it('should provide all', (done) => { - Attraction().should.have.property('all'); - done(); - }); - - it('should provide find', (done) => { - Attraction().should.have.property('find'); - done(); - }); -}); diff --git a/test/discovery/v2/classification/all.js b/test/discovery/v2/classification/all.js index 5ca1162..f48b070 100644 --- a/test/discovery/v2/classification/all.js +++ b/test/discovery/v2/classification/all.js @@ -1,6 +1,6 @@ import {back as nockBack} from 'nock'; -import Classification from '../../../../lib/discovery/v2/classification'; +import {Classification} from '../../../../lib/discovery/v2'; describe('discovery.v2.classification.all', () => { before(() => { diff --git a/test/discovery/v2/classification/find.js b/test/discovery/v2/classification/find.js index 4de9ca6..3dd69b8 100644 --- a/test/discovery/v2/classification/find.js +++ b/test/discovery/v2/classification/find.js @@ -1,6 +1,6 @@ import {back as nockBack} from 'nock'; -import Classification from '../../../../lib/discovery/v2/classification'; +import {Classification} from '../../../../lib/discovery/v2'; describe('discovery.v2.classification.find', () => { before(() => { diff --git a/test/discovery/v2/event/all.js b/test/discovery/v2/event/all.js index 4ceb255..ac256a9 100644 --- a/test/discovery/v2/event/all.js +++ b/test/discovery/v2/event/all.js @@ -1,9 +1,9 @@ import {back as nockBack} from 'nock'; -import sdk from '../../../../lib'; -import Event from '../../../../lib/discovery/v2/event'; +import tmapi from '../../../../lib'; +import {Event} from '../../../../lib/discovery/v2'; -const api = sdk('mock-api-key'); +const api = tmapi('mock-api-key'); const onResult = (done) => (page) => { page.items[0].name.should.equal('OSEA Membership Registration'); diff --git a/test/discovery/v2/event/find.js b/test/discovery/v2/event/find.js index 4bd2487..8bb26e6 100644 --- a/test/discovery/v2/event/find.js +++ b/test/discovery/v2/event/find.js @@ -1,6 +1,6 @@ import {back as nockBack} from 'nock'; -import Event from '../../../../lib/discovery/v2/event'; +import {Event} from '../../../../lib/discovery/v2'; describe('discovery.v2.event.find', () => { before(() => { @@ -25,10 +25,10 @@ describe('discovery.v2.event.find', () => { Event('mock-api-key').findImages('vv17FZfdGkSrrMju') .then((result) => { result.images[0].should.deep.equal({ - 'ratio': '3_2', - 'url': 'http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_ARTIST_PAGE_3_2.jpg', - 'width': 305, - 'height': 203, + 'ratio': '3_2', + 'url': 'http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_ARTIST_PAGE_3_2.jpg', + 'width': 305, + 'height': 203, 'fallback': true }); nockDone(); diff --git a/test/discovery/v2/event/index.js b/test/discovery/v2/event/index.js deleted file mode 100644 index cdbed0b..0000000 --- a/test/discovery/v2/event/index.js +++ /dev/null @@ -1,13 +0,0 @@ -import event from '../../../../lib/discovery/v2/event'; - -describe('discovery.v2.event', () => { - it('should provide all', done => { - event().should.have.property('all'); - done(); - }); - - it('should provide find', done => { - event().should.have.property('find'); - done(); - }); -}); diff --git a/test/discovery/v2/event/options.js b/test/discovery/v2/event/options.js index 6c95636..ab481d0 100644 --- a/test/discovery/v2/event/options.js +++ b/test/discovery/v2/event/options.js @@ -1,12 +1,12 @@ import {back as nockBack} from 'nock'; -import Event from '../../../../lib/discovery/v2/event'; +import {Event} from '../../../../lib/discovery/v2'; nockBack.fixtures = './test/fixtures/discovery/v2'; describe('discovery.v2.event.options', () => { describe('options', () => { - it('works', (done) => { + it('should produce a formatted query string from params', (done) => { nockBack('event/all-200-options.json', (nockDone) => { nockDone(); diff --git a/test/discovery/v2/index.js b/test/discovery/v2/index.js index 00376a3..03963ef 100644 --- a/test/discovery/v2/index.js +++ b/test/discovery/v2/index.js @@ -1,18 +1,25 @@ import v2 from '../../../lib/discovery/v2'; +const api = v2(); + describe('discovery.v2', () => { it('should provide attraction', (done) => { - v2().should.have.property('attraction'); + api.should.have.property('attraction'); + done(); + }); + + it('should provide classification', (done) => { + api.should.have.property('classification'); done(); }); it('should provide event', (done) => { - v2().should.have.property('event'); + api.should.have.property('event'); done(); }); it('should provide venue', (done) => { - v2().should.have.property('venue'); + api.should.have.property('venue'); done(); }); }); diff --git a/test/discovery/v2/venue/find.js b/test/discovery/v2/venue/find.js index 03df1a7..e9c9a90 100644 --- a/test/discovery/v2/venue/find.js +++ b/test/discovery/v2/venue/find.js @@ -1,6 +1,6 @@ import {back as nockBack} from 'nock'; -import Venue from '../../../../lib/discovery/v2/venue'; +import {Venue} from '../../../../lib/discovery/v2'; describe('discovery.v2.venue.find', () => { before(() => { diff --git a/test/discovery/v2/venue/index.js b/test/discovery/v2/venue/index.js deleted file mode 100644 index 1c2ecd5..0000000 --- a/test/discovery/v2/venue/index.js +++ /dev/null @@ -1,8 +0,0 @@ -import venue from '../../../../lib/discovery/v2/venue'; - -describe('discovery.v2.venue', () => { - it('should provide find', (done) => { - venue().should.have.property('find'); - done(); - }); -}); diff --git a/test/utils/all.js b/test/utils/all.js new file mode 100644 index 0000000..b37a378 --- /dev/null +++ b/test/utils/all.js @@ -0,0 +1,22 @@ +import all from '../../lib/utils/all'; + +describe('utils.all', () => { + before(() => { + all.__Rewire__('getData', (params) => params); + }); + + it('should parse params correctly', (done) => { + const query = all('discovery/v2', 'a3b2c1d4e5f6', 'events'); + + query({city: 'london'}).should.deep.equal({ + path: ['discovery/v2', 'events'], + qs: {city: 'london', apikey: 'a3b2c1d4e5f6'} + }); + + done(); + }); + + after(() => { + all.__ResetDependency__('getData'); + }); +}); diff --git a/test/utils/find.js b/test/utils/find.js new file mode 100644 index 0000000..8f9af0d --- /dev/null +++ b/test/utils/find.js @@ -0,0 +1,33 @@ +import find from '../../lib/utils/find'; + +describe('utils.find', () => { + before(() => { + find.__Rewire__('getData', (params) => params); + }); + + it('should parse params for a resource', (done) => { + const query = find('discovery/v2', 'a3b2c1d4e5f6', 'events'); + + query(1).should.deep.equal({ + path: ['discovery/v2', 'events', 1], + qs: {apikey: 'a3b2c1d4e5f6'} + }); + + done(); + }); + + it('should parse params for a sub-resource', (done) => { + const query = find('discovery/v2', 'a3b2c1d4e5f6', 'events', 'images'); + + query(1).should.deep.equal({ + path: ['discovery/v2', 'events', 1, 'images'], + qs: {apikey: 'a3b2c1d4e5f6'} + }); + + done(); + }); + + after(() => { + find.__ResetDependency__('getData'); + }); +});