Skip to content

Commit

Permalink
styles: arrow function all the things in query-test.js
Browse files Browse the repository at this point in the history
Cause code consistency is king -- first test with arrow function just
added while creating a new query related test.
  • Loading branch information
phillipj committed Apr 16, 2017
1 parent ac4236c commit d62fc88
Showing 1 changed file with 39 additions and 41 deletions.
80 changes: 39 additions & 41 deletions test/query-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,125 +6,123 @@ var CLIENTS_URL = '/clients';

var PlexAPI = require('..');

describe('query()', function() {
describe('query()', () => {
var api;

beforeEach(function() {
beforeEach(() => {
server.start();

api = new PlexAPI('localhost');
});

afterEach(server.stop);

it('should exist', function() {
it('should exist', () => {
expect(api.query).to.be.a('function');
});

describe('options', function() {
it('requires url options', function() {
expect(function() {
describe('options', () => {
it('requires url options', () => {
expect(() => {
api.query();
}).to.throwException('TypeError');
});

it('can accept url option as only parameter', function() {
return api.query('/').then(function(result) {
it('can accept url option as only parameter', () => {
return api.query('/').then(result => {
expect(result).to.be.an('object');
});
});

it('can accept url option as part of an options object', function() {
return api.query({ uri: '/' }).then(function(result) {
it('can accept url option as part of an options object', () => {
return api.query({ uri: '/' }).then(result => {
expect(result).to.be.an('object');
});
});

it('uses extra headers passed in options', function() {
it('uses extra headers passed in options', () => {
server.stop();
var nockServer = server.start({
reqheaders: {
'X-TEST-HEADER': 'X-TEST-HEADER-VAL'
}
});

return api
.query({ uri: '/', extraHeaders: { 'X-TEST-HEADER': 'X-TEST-HEADER-VAL' } })
.then(function(result) {
expect(result).to.be.an('object');
nockServer.done();
});
return api.query({ uri: '/', extraHeaders: { 'X-TEST-HEADER': 'X-TEST-HEADER-VAL' } }).then(result => {
expect(result).to.be.an('object');
nockServer.done();
});
});
});

it('promise should fail when server fails', function(done) {
it('promise should fail when server fails', done => {
server.fails();

api
.query(ROOT_URL)
.then(function() {
.then(() => {
done(Error('Shouldnt succeed!'));
})
.catch(function(err) {
.catch(err => {
expect(err).not.to.be(null);
done();
});
});

it('promise should succeed when server responds', function() {
return api.query(ROOT_URL).then(function(result) {
it('promise should succeed when server responds', () => {
return api.query(ROOT_URL).then(result => {
expect(result).to.be.an('object');
});
});

it('should have response MediaContainer attributes as properties on the resolved result object', function() {
return api.query(ROOT_URL).then(function(result) {
it('should have response MediaContainer attributes as properties on the resolved result object', () => {
return api.query(ROOT_URL).then(result => {
expect(result.version).to.contain('0.9.11.4.739-a4e710f');
});
});

it('should have response child Directory items as result._children', function() {
return api.query(ROOT_URL).then(function(result) {
it('should have response child Directory items as result._children', () => {
return api.query(ROOT_URL).then(result => {
expect(result._children.length).to.be(16);
});
});

describe('Directory URI', function() {
it('should provide an uri property', function() {
return api.query(ROOT_URL).then(function(result) {
describe('Directory URI', () => {
it('should provide an uri property', () => {
return api.query(ROOT_URL).then(result => {
expect(result._children[0].uri).not.to.be(undefined);
});
});

it('should provide an uri property combined of parent URI and the item key attribute', function() {
return api.query('/library/sections').then(function(result) {
it('should provide an uri property combined of parent URI and the item key attribute', () => {
return api.query('/library/sections').then(result => {
expect(result._children[0].uri).to.be('/library/sections/1');
});
});

it('should use the key as the uri if the key is a root-relative path', function() {
return api.query('/library/sections/1/all').then(function(result) {
it('should use the key as the uri if the key is a root-relative path', () => {
return api.query('/library/sections/1/all').then(result => {
expect(result._children[0].uri).to.be(result._children[0].key);
});
});
});

describe('Server URI', function() {
it('should provide an uri property', function() {
return api.query(CLIENTS_URL).then(function(result) {
describe('Server URI', () => {
it('should provide an uri property', () => {
return api.query(CLIENTS_URL).then(result => {
expect(result._children[0].uri).not.to.be(undefined);
});
});

it('should provide uri property used to control Plex application', function() {
return api.query(CLIENTS_URL).then(function(result) {
it('should provide uri property used to control Plex application', () => {
return api.query(CLIENTS_URL).then(result => {
expect(result._children[0].uri).to.be('/system/players/192.168.0.47');
});
});
});

describe('XML responses', function() {
it('should convert XML to a JSON object', function() {
describe('XML responses', () => {
it('should convert XML to a JSON object', () => {
var plexTvApi = new PlexAPI({
hostname: 'plex.tv',
port: 443
Expand All @@ -137,7 +135,7 @@ describe('query()', function() {
contentType: 'application/xml'
});

return plexTvApi.query('/devices.xml').then(function(result) {
return plexTvApi.query('/devices.xml').then(result => {
expect(result.MediaContainer).to.be.an('object');
expect(result.MediaContainer.attributes.publicAddress).to.equal('47.1.2.4');
});
Expand Down

0 comments on commit d62fc88

Please sign in to comment.