Skip to content

Commit

Permalink
Remove writeFromStream method. Fix issue with broken deprecated metho…
Browse files Browse the repository at this point in the history
…ds. Add tests for deprecated methods
  • Loading branch information
tormozz48 committed Sep 15, 2015
1 parent 05a2b86 commit 4f46f9d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 12 deletions.
24 changes: 12 additions & 12 deletions index.js
Expand Up @@ -106,15 +106,6 @@ MDS.prototype = {
return this._sendRequest(options, callback);
},

/**
* Writes value for given key as stream
* @param {String} key - key of record
* @param {Stream} stream - streamed value
*/
writeFromStream: function (key, stream) {
return stream.pipe(request(this._getCommonWriteOptions(key)));
},

/**
* Removes value by given string key
* @param {String} key - key of record
Expand All @@ -133,7 +124,10 @@ MDS.prototype = {
* @deprecated
* @returns {Promise}
*/
readP: this.read,
readP: function (key) {
this._log('"readP" method is deprecated. Use "read" instead');
return this.read(key);
},

/**
* Short alias for call write method with promise result
Expand All @@ -142,15 +136,21 @@ MDS.prototype = {
* @deprecated
* @returns {Promise}
*/
writeP: this.write,
writeP: function (key, value) {
this._log('"writeP" method is deprecated. Use "write" instead');
return this.write(key, value);
},

/**
* Short alias for call remove method with promise result
* @param {String} key - key of record
* @deprecated
* @returns {Promise}
*/
removeP: this.remove,
removeP: function (key) {
this._log('"removeP" method is deprecated. Use "remove" instead');
return this.remove(key);
},

/**
* Returns full url on mds storage
Expand Down
35 changes: 35 additions & 0 deletions test/test.js
Expand Up @@ -96,6 +96,17 @@ describe('mds-wrapper', function () {
});
});

it ('should read data by deprecated readP method', function () {
nock('http://127.0.0.1:3000')
.get('/get-my-site/key')
.reply(200, 'Hello World');

var mds = new MDS(getOptions());
return mds.readP('key').then(function (data) {
data.should.equal('Hello World');
});
});

it('should read value as stream as save file on filesystem', function (done) {
nock('http://127.0.0.1:3000')
.get('/get-my-site/key')
Expand Down Expand Up @@ -214,6 +225,18 @@ describe('mds-wrapper', function () {
});
});

it('should write data by deprecated writeP method', function () {
nock('http://127.0.0.1:3001', 'Hello World')
.post('/upload-my-site/key')
.reply(200, 'OK');

var mds = new MDS(getOptions());
return mds.writeP('key', 'Hello World').then(function (data) {
data.should.equal('OK')
});
});

/*
it('should write streamed data from file', function (done) {
var body;
nock('http://127.0.0.1:3001', 'Hello World')
Expand All @@ -231,6 +254,7 @@ describe('mds-wrapper', function () {
done();
});
});
*/

describe('error cases', function () {
it('should return callback with error if ETIMEOUT network error occur', function (done) {
Expand Down Expand Up @@ -320,5 +344,16 @@ describe('mds-wrapper', function () {
data.should.equal('OK')
});
});

it('should remove data by deprecated removeP method', function () {
nock('http://127.0.0.1:3001')
.get('/delete-my-site/key')
.reply(200, 'OK');

var mds = new MDS(getOptions());
return mds.removeP('key').then(function (data) {
data.should.equal('OK')
});
});
});
});

0 comments on commit 4f46f9d

Please sign in to comment.