Skip to content

Commit

Permalink
Extract system module
Browse files Browse the repository at this point in the history
  • Loading branch information
Kai Wood committed Mar 25, 2017
1 parent 5d17d62 commit 8473f08
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 35 deletions.
20 changes: 3 additions & 17 deletions lib/pnut.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const users = require('./users');
const posts = require('./posts');
const channels = require('./channels');
const messages = require('./messages');
const system = require('./system');

/**
* pnut-butter.js
Expand Down Expand Up @@ -101,28 +102,13 @@ const pnut = () => {

return url;
},

/**
* Retrieve a list of parameters for interacting with the API.
* @returns {Promise}
*/
config() {
return api.request('/sys/config');
},

/**
* Retrieve basic statistics for the network.
* @returns {Promise}
*/
stats() {
return api.request('/sys/stats');
}
},

users(api),
posts(api),
channels(api),
messages(api)
messages(api),
system(api)
);
};

Expand Down
24 changes: 24 additions & 0 deletions lib/system.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';

/**
* System
*/
module.exports = (api) => {
return {
/**
* Retrieve a list of parameters for interacting with the API.
* @returns {Promise}
*/
config() {
return api.request('/sys/config');
},

/**
* Retrieve basic statistics for the network.
* @returns {Promise}
*/
stats() {
return api.request('/sys/stats');
}
};
};
18 changes: 0 additions & 18 deletions test/pnut_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@ before(function () {
nock(base)
.patch('/somewhere')
.reply(200, {});

nock(base)
.get('/sys/config')
.reply(200, {});

nock(base)
.get('/sys/stats')
.reply(200, {});
});

after(function () {
Expand Down Expand Up @@ -78,13 +70,3 @@ describe('Authentication', () => {
expect(pnut.authenticateClientURL('mytoken', 'http://github.com')).to.equal(expectedURL);
});
});

describe('System', () => {
it('should be able to fetch sys/config', () => {
return pnut.config().should.become({});
});

it('should be able to fetch sys/stats', () => {
return pnut.stats().should.become({});
});
});
33 changes: 33 additions & 0 deletions test/system_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
const nock = require('nock');
chai.use(chaiAsPromised);
chai.should();

const pnut = require('../lib/pnut');

before(function () {
let base = 'https://api.pnut.io/v0';

nock(base)
.get('/sys/config')
.reply(200, {});

nock(base)
.get('/sys/stats')
.reply(200, {});
});

after(function () {
nock.cleanAll();
});

describe('System', () => {
it('should be able to fetch sys/config', () => {
return pnut.config().should.become({});
});

it('should be able to fetch sys/stats', () => {
return pnut.stats().should.become({});
});
});

0 comments on commit 8473f08

Please sign in to comment.