Skip to content

Commit

Permalink
🚨 Edit tests to use a single instance
Browse files Browse the repository at this point in the history
  • Loading branch information
aknorw committed Jul 30, 2019
1 parent 4113c20 commit f4d632a
Show file tree
Hide file tree
Showing 47 changed files with 86 additions and 508 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@
],
"no-underscore-dangle": 0,
"import/prefer-default-export": 0
},
"globals": {
"client": true
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"clean": "rimraf lib",
"pretty": "prettier --config .prettierrc --write src/**/*.js",
"lint": "eslint --ext .js src",
"test": "cross-env NODE_ENV=test nyc --reporter=text mocha ./test ./src/**/*.test.js ./src/**/**/*.test.js --require @babel/register --timeout 10000",
"test": "cross-env NODE_ENV=test nyc --reporter=text mocha ./test ./src/**/*.test.js ./src/**/**/*.test.js --require @babel/register --require ./test/setup --globals global --timeout 10000",
"test:ci": "npm run test && nyc report --reporter=text-lcov | coveralls",
"prebuild": "yarn run clean",
"build": "cross-env NODE_ENV=production ./node_modules/.bin/rollup -c"
Expand Down
12 changes: 1 addition & 11 deletions src/database/artists/getArtist.test.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
import chai from 'chai'

import Discojs from '../..'

// eslint-disable-next-line no-unused-vars
const should = chai.should()
let client
chai.should()

const artistId = 108713

describe('Database - Artists - getArtistMethod', () => {
before(() => {
client = new Discojs({
userToken: process.env.USER_TOKEN,
requestLimitAuth: 20,
})
})
it('should get an artist from its id', async () => {
const data = await client.getArtist(artistId)
data.should.be.an('object').and.have.property('id')
Expand Down
11 changes: 1 addition & 10 deletions src/database/artists/getReleasesForArtist.test.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
import { parse } from 'querystring'
import chai from 'chai'

import Discojs from '../..'
import { sortFields } from './getReleasesForArtist'
import { sortOrders } from '../../utils/sort'

// eslint-disable-next-line no-unused-vars
const should = chai.should()
let client
chai.should()

const URL_REGEX = /^https:\/\/api\.discogs\.com\/.*\?(.*)$/

const artistId = 108713

describe('Database - Artists - getReleasesForArtistMethod', () => {
before(() => {
client = new Discojs({
userToken: process.env.USER_TOKEN,
requestLimitAuth: 20,
})
})
it('should get releases for an artist from its id', async () => {
const data = await client.getReleasesForArtist(artistId)
data.should.be.an('object').and.have.property('releases')
Expand Down
17 changes: 1 addition & 16 deletions src/database/artists/searchArtist.test.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
import { parse } from 'querystring'
import chai from 'chai'

import Discojs from '../..'
import { AuthError } from '../../errors'

// eslint-disable-next-line no-unused-vars
const should = chai.should()
let client
chai.should()

const URL_REGEX = /^https:\/\/api\.discogs\.com\/.*\?(.*)$/

const query = 'Unknown Artist'

describe('Database - Releases - searchArtistMethod', () => {
before(() => {
client = new Discojs({
userToken: process.env.USER_TOKEN,
requestLimitAuth: 20,
})
})
it('should search for an artist from `query`', async () => {
const data = await client.searchArtist(query)
data.should.be.an('object').and.have.property('results')
Expand Down Expand Up @@ -47,8 +36,4 @@ describe('Database - Releases - searchArtistMethod', () => {
data.pagination.should.have.property('page')
data.pagination.page.should.be.equal(page)
})
it('should return an AuthError if not authenticated', () => {
client = new Discojs()
client.searchArtist(query).catch(err => err.should.be.an.instanceOf(AuthError))
})
})
12 changes: 1 addition & 11 deletions src/database/labels/getLabel.test.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
import chai from 'chai'

import Discojs from '../..'

// eslint-disable-next-line no-unused-vars
const should = chai.should()
let client
chai.should()

const labelId = 1

describe('Database - Labels - getLabelMethod', () => {
before(() => {
client = new Discojs({
userToken: process.env.USER_TOKEN,
requestLimitAuth: 20,
})
})
it('should get a label from its id', async () => {
const data = await client.getLabel(labelId)
data.should.be.an('object').and.have.property('id')
Expand Down
12 changes: 1 addition & 11 deletions src/database/labels/getReleasesForLabel.test.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
import chai from 'chai'

import Discojs from '../..'

// eslint-disable-next-line no-unused-vars
const should = chai.should()
let client
chai.should()

const labelId = 108713

describe('Database - Labels - getReleasesForLabelMethod', () => {
before(() => {
client = new Discojs({
userToken: process.env.USER_TOKEN,
requestLimitAuth: 20,
})
})
it('should get releases for the label from its id', async () => {
const data = await client.getReleasesForLabel(labelId)
data.should.be.an('object').and.have.property('releases')
Expand Down
17 changes: 1 addition & 16 deletions src/database/labels/searchLabel.test.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
import { parse } from 'querystring'
import chai from 'chai'

import Discojs from '../..'
import { AuthError } from '../../errors'

// eslint-disable-next-line no-unused-vars
const should = chai.should()
let client
chai.should()

const URL_REGEX = /^https:\/\/api\.discogs\.com\/.*\?(.*)$/

const query = 'Test'

describe('Database - Labels - searchLabelMethod', () => {
before(() => {
client = new Discojs({
userToken: process.env.USER_TOKEN,
requestLimitAuth: 20,
})
})
it('should search for a label from `query`', async () => {
const data = await client.searchLabel(query)
data.should.be.an('object').and.have.property('results')
Expand Down Expand Up @@ -47,8 +36,4 @@ describe('Database - Labels - searchLabelMethod', () => {
data.pagination.should.have.property('page')
data.pagination.page.should.be.equal(page)
})
it('should return an AuthError if not authenticated', () => {
client = new Discojs()
client.searchLabel(query).catch(err => err.should.be.an.instanceOf(AuthError))
})
})
12 changes: 1 addition & 11 deletions src/database/masters/getMaster.test.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
import chai from 'chai'

import Discojs from '../..'

// eslint-disable-next-line no-unused-vars
const should = chai.should()
let client
chai.should()

const masterId = 96559

describe('Database - Masters - getMasterMethod', () => {
before(() => {
client = new Discojs({
userToken: process.env.USER_TOKEN,
requestLimitAuth: 20,
})
})
it('should get a master release from its id', async () => {
const data = await client.getMaster(masterId)
data.should.be.an('object').and.have.property('id')
Expand Down
12 changes: 1 addition & 11 deletions src/database/masters/getVersionsForMaster.test.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
import chai from 'chai'

import Discojs from '../..'

// eslint-disable-next-line no-unused-vars
const should = chai.should()
let client
chai.should()

const masterId = 96559

describe('Database - Masters - getVersionsForMasterMethod', () => {
before(() => {
client = new Discojs({
userToken: process.env.USER_TOKEN,
requestLimitAuth: 20,
})
})
it('should list releases that are versions of a master release from its id', async () => {
const data = await client.getVersionsForMaster(masterId)
data.should.be.an('object').and.have.property('versions')
Expand Down
11 changes: 1 addition & 10 deletions src/database/releases/getRelease.test.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
import chai from 'chai'

import Discojs from '../..'
import { CURRENCIES } from '../../constants'

// eslint-disable-next-line no-unused-vars
const should = chai.should()
let client
chai.should()

const releaseId = 249504

describe('Database - Releases - getReleaseMethod', () => {
before(() => {
client = new Discojs({
userToken: process.env.USER_TOKEN,
requestLimitAuth: 20,
})
})
it('should get a release from its id', async () => {
const data = await client.getRelease(releaseId)
data.should.be.an('object').and.have.property('id')
Expand Down
17 changes: 1 addition & 16 deletions src/database/releases/searchRelease.test.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
import { parse } from 'querystring'
import chai from 'chai'

import Discojs from '../..'
import { AuthError } from '../../errors'

// eslint-disable-next-line no-unused-vars
const should = chai.should()
let client
chai.should()

const URL_REGEX = /^https:\/\/api\.discogs\.com\/.*\?(.*)$/

const query = 'test'

describe('Database - Releases - searchReleaseMethod', () => {
before(() => {
client = new Discojs({
userToken: process.env.USER_TOKEN,
requestLimitAuth: 20,
})
})
it('should search for a release from `query`', async () => {
const data = await client.searchRelease(query)
data.should.be.an('object').and.have.property('results')
Expand Down Expand Up @@ -47,8 +36,4 @@ describe('Database - Releases - searchReleaseMethod', () => {
data.pagination.should.have.property('page')
data.pagination.page.should.be.equal(page)
})
it('should return an AuthError if not authenticated', () => {
client = new Discojs()
client.searchRelease(query).catch(err => err.should.be.an.instanceOf(AuthError))
})
})
17 changes: 1 addition & 16 deletions src/database/search.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { parse } from 'querystring'
import chai from 'chai'

import Discojs from '..'
import { AuthError } from '../errors'

// eslint-disable-next-line no-unused-vars
const should = chai.should()
let client
chai.should()

const URL_REGEX = /^https:\/\/api\.discogs\.com\/.*\?(.*)$/

Expand All @@ -30,12 +25,6 @@ const submitter = 'milKt'
const contributor = 'jerome99'

describe('Database - searchDatabaseMethod', () => {
before(() => {
client = new Discojs({
userToken: process.env.USER_TOKEN,
requestLimitAuth: 20,
})
})
it('should search for all releases if no param', async () => {
const data = await client.searchDatabase()
data.should.be.an('object').and.have.property('results')
Expand Down Expand Up @@ -231,8 +220,4 @@ describe('Database - searchDatabaseMethod', () => {
data.pagination.should.have.property('page')
data.pagination.page.should.be.equal(page)
})
it('should return an AuthError if not authenticated', () => {
client = new Discojs()
client.searchDatabase({ query }).catch(err => err.should.be.an.instanceOf(AuthError))
})
})
14 changes: 2 additions & 12 deletions src/lists/getItemsInList.test.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
import chai from 'chai'

import Discojs from '..'
chai.should()

// eslint-disable-next-line no-unused-vars
const should = chai.should()
let client

const listId = 405348
const listId = 342829

describe('Lists - getItemsInListMethod', () => {
before(() => {
client = new Discojs({
userToken: process.env.USER_TOKEN,
requestLimitAuth: 20,
})
})
it('should get list items from its id', async () => {
const data = await client.getItemsInList(listId)
data.should.be.an('object').and.have.property('items')
Expand Down
12 changes: 1 addition & 11 deletions src/marketplace/getFee.test.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
import chai from 'chai'

import Discojs from '..'

// eslint-disable-next-line no-unused-vars
const should = chai.should()
let client
chai.should()

// CANNOT TEST WITHOUT SELLER SETTINGS

describe('Marketplace - getFeeMethod', () => {
before(() => {
client = new Discojs({
userToken: process.env.USER_TOKEN,
requestLimitAuth: 20,
})
})
it('should return a TypeError if `price` is not a number', () => {
client.getFee('100').catch(err => err.should.be.an.instanceOf(TypeError))
})
Expand Down
12 changes: 1 addition & 11 deletions src/marketplace/getPriceSuggestions.test.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
import chai from 'chai'

import Discojs from '..'

// eslint-disable-next-line no-unused-vars
const should = chai.should()
let client
chai.should()

// CANNOT TEST WITHOUT SELLER SETTINGS

describe('Marketplace - getPriceSuggestionsMethod', () => {
before(() => {
client = new Discojs({
userToken: process.env.USER_TOKEN,
requestLimitAuth: 20,
})
})
it('should return a TypeError if `id` is not a number', () => {
client.getPriceSuggestions('test').catch(err => err.should.be.an.instanceOf(TypeError))
})
Expand Down

0 comments on commit f4d632a

Please sign in to comment.