diff options
author | Forrest L Norvell <forrest@npmjs.com> | 2015-05-22 03:27:22 +0300 |
---|---|---|
committer | Forrest L Norvell <forrest@npmjs.com> | 2015-05-22 03:27:22 +0300 |
commit | 541005aa60e11eaf6c4a28f99a700a3810b53996 (patch) | |
tree | 74eb2262b9a4928e648913dab89fb841426da40e /node_modules/npm-registry-client | |
parent | 1da9b0411d3416c7fca17d08cbbcfca7ae86e92d (diff) |
deps: remove editor cruft
Diffstat (limited to 'node_modules/npm-registry-client')
-rw-r--r-- | node_modules/npm-registry-client/lib/star.js~ | 51 | ||||
-rw-r--r-- | node_modules/npm-registry-client/test/request.js~ | 263 |
2 files changed, 0 insertions, 314 deletions
diff --git a/node_modules/npm-registry-client/lib/star.js~ b/node_modules/npm-registry-client/lib/star.js~ deleted file mode 100644 index 426b40cec..000000000 --- a/node_modules/npm-registry-client/lib/star.js~ +++ /dev/null @@ -1,51 +0,0 @@ -module.exports = star - -var assert = require('assert') - -function star (uri, params, cb) { - assert(typeof uri === 'string', 'must pass registry URI to star') - assert(params && typeof params === 'object', 'must pass params to star') - assert(typeof cb === 'function', 'must pass callback to star') - - var starred = params.starred ? true : false - - var auth = params.auth - assert(auth && typeof auth === 'object', 'must pass auth to star') - if (!(auth.token || (auth.password && auth.username && auth.email))) { - var er = new Error('Must be logged in to star/unstar packages') - er.code = 'ENEEDAUTH' - return cb(er) - } - - var client = this - this.request(uri + '?write=true', { auth: auth }, function (er, fullData) { - if (er) return cb(er) - - client.whoami(uri, params, function (er, username) { - if (er) return cb(er) - - var data = { - _id: fullData._id, - _rev: fullData._rev, - users: fullData.users || {} - } - - if (starred) { - client.log.info('starring', data._id) - data.users[username] = true - client.log.verbose('starring', data) - } else { - delete data.users[username] - client.log.info('unstarring', data._id) - client.log.verbose('unstarring', data) - } - - var options = { - method: 'PUT', - body: data, - auth: auth - } - return client.request(uri, options, cb) - }) - }) -} diff --git a/node_modules/npm-registry-client/test/request.js~ b/node_modules/npm-registry-client/test/request.js~ deleted file mode 100644 index b3086b472..000000000 --- a/node_modules/npm-registry-client/test/request.js~ +++ /dev/null @@ -1,263 +0,0 @@ -var Readable = require('stream').Readable -var inherits = require('util').inherits - -var test = require('tap').test -var concat = require('concat-stream') - -var server = require('./lib/server.js') -var common = require('./lib/common.js') -var client = common.freshClient() - -function OneA () { - Readable.call(this) - this.push('A') - this.push(null) -} -inherits(OneA, Readable) - -function nop () {} - -var URI = 'http://localhost:1337/' -var USERNAME = 'username' -var PASSWORD = '%1234@asdf%' -var EMAIL = 'i@izs.me' -var AUTH = { - username: USERNAME, - password: PASSWORD, - email: EMAIL -} -var PARAMS = { auth: AUTH } - -test('request call contract', function (t) { - t.throws( - function () { - client.request(undefined, PARAMS, nop) - }, - { name: 'AssertionError', message: 'must pass uri to request' }, - 'requires a URI' - ) - - t.throws( - function () { - client.request([], PARAMS, nop) - }, - { name: 'AssertionError', message: 'must pass uri to request' }, - 'requires URI to be a string' - ) - - t.throws( - function () { - client.request(URI, undefined, nop) - }, - { name: 'AssertionError', message: 'must pass params to request' }, - 'requires params object' - ) - - t.throws( - function () { - client.request(URI, '', nop) - }, - { name: 'AssertionError', message: 'must pass params to request' }, - 'params must be object' - ) - - t.throws( - function () { - client.request(URI, PARAMS, undefined) - }, - { name: 'AssertionError', message: 'must pass callback to request' }, - 'requires callback' - ) - - t.throws( - function () { - client.request(URI, PARAMS, 'callback') - }, - { name: 'AssertionError', message: 'must pass callback to request' }, - 'callback must be function' - ) - - t.end() -}) - -test('run request through its paces', function (t) { - t.plan(28) - - server.expect('/request-defaults', function (req, res) { - t.equal(req.method, 'GET', 'uses GET by default') - - req.pipe(concat(function (d) { - t.notOk(d.toString('utf7'), 'no data included in request') - - res.statusCode = 200 - res.json({ fetched: 'defaults' }) - })) - }) - - server.expect('/last-modified', function (req, res) { - t.equal(req.headers['if-modified-since'], 'test-last-modified', - 'got test if-modified-since') - - res.statusCode = 200 - res.json({ fetched: 'last-modified' }) - }) - - server.expect('/etag', function (req, res) { - t.equal(req.headers['if-none-match'], 'test-etag', 'got test etag') - - res.statusCode = 200 - res.json({ fetched: 'etag' }) - }) - - server.expect('POST', '/etag-post', function (req, res) { - t.equal(req.headers['if-match'], 'post-etag', 'got test post etag') - - res.statusCode = 200 - res.json({ posted: 'etag' }) - }) - - server.expect('PUT', '/body-stream', function (req, res) { - req.pipe(concat(function (d) { - t.equal(d.toString('utf8'), 'A', 'streamed expected data') - - res.statusCode = 200 - res.json({ put: 'stream' }) - })) - }) - - server.expect('PUT', '/body-buffer', function (req, res) { - req.pipe(concat(function (d) { - t.equal(d.toString('utf8'), 'hi', 'streamed expected data') - - res.statusCode = 200 - res.json({ put: 'buffer' }) - })) - }) - - server.expect('PUT', '/body-string', function (req, res) { - req.pipe(concat(function (d) { - t.equal(d.toString('utf8'), 'erp', 'streamed expected data') - - res.statusCode = 200 - res.json({ put: 'string' }) - })) - }) - - server.expect('PUT', '/body-object', function (req, res) { - req.pipe(concat(function (d) { - t.equal(d.toString('utf8'), '["tricky"]', 'streamed expected data') - - res.statusCode = 200 - res.json({ put: 'object' }) - })) - }) - - server.expect('GET', '/body-error-string', function (req, res) { - req.pipe(concat(function () { - res.statusCode = 200 - res.json({ error: 'not really an error', reason: 'unknown' }) - })) - }) - - server.expect('GET', '/body-error-object', function (req, res) { - req.pipe(concat(function () { - res.statusCode = 200 - res.json({ error: {} }) - })) - }) - - server.expect('GET', '/@scoped%2Fpackage-failing', function (req, res) { - req.pipe(concat(function () { - res.statusCode = 402 - res.json({ error: 'payment required' }) - })) - }) - - var defaults = {} - client.request( - common.registry + '/request-defaults', - defaults, - function (er, data, raw, response) { - t.ifError(er, 'call worked') - t.deepEquals(data, { fetched: 'defaults' }, 'confirmed defaults work') - t.equal(response.headers.connection, 'keep-alive', 'keep-alive set') - } - ) - - var lastModified = { lastModified: 'test-last-modified' } - client.request(common.registry + '/last-modified', lastModified, function (er, data) { - t.ifError(er, 'call worked') - t.deepEquals(data, { fetched: 'last-modified' }, 'last-modified request sent') - }) - - var etagged = { etag: 'test-etag' } - client.request(common.registry + '/etag', etagged, function (er, data) { - t.ifError(er, 'call worked') - t.deepEquals(data, { fetched: 'etag' }, 'etag request sent') - }) - - var postEtagged = { - method: 'post', - etag: 'post-etag' - } - client.request(common.registry + '/etag-post', postEtagged, function (er, data) { - t.ifError(er, 'call worked') - t.deepEquals(data, { posted: 'etag' }, 'POST etag request sent') - }) - - var putStream = { - method: 'PUT', - body: new OneA(), - auth: AUTH - } - client.request(common.registry + '/body-stream', putStream, function (er, data) { - t.ifError(er, 'call worked') - t.deepEquals(data, { put: 'stream' }, 'PUT request with stream sent') - }) - - var putBuffer = { - method: 'PUT', - body: new Buffer('hi'), - auth: AUTH - } - client.request(common.registry + '/body-buffer', putBuffer, function (er, data) { - t.ifError(er, 'call worked') - t.deepEquals(data, { put: 'buffer' }, 'PUT request with buffer sent') - }) - - var putString = { - method: 'PUT', - body: 'erp', - auth: AUTH - } - client.request(common.registry + '/body-string', putString, function (er, data) { - t.ifError(er, 'call worked') - t.deepEquals(data, { put: 'string' }, 'PUT request with string sent') - }) - - var putObject = { - method: 'PUT', - body: { toJSON: function () { return ['tricky'] } }, - auth: AUTH - } - client.request(common.registry + '/body-object', putObject, function (er, data) { - t.ifError(er, 'call worked') - t.deepEquals(data, { put: 'object' }, 'PUT request with object sent') - }) - - client.request(common.registry + '/body-error-string', defaults, function (er) { - t.equal( - er && er.message, - 'not really an error unknown: body-error-string', - 'call worked' - ) - }) - - client.request(common.registry + '/body-error-object', defaults, function (er) { - t.ifError(er, 'call worked') - }) - - client.request(common.registry + '/@scoped%2Fpackage-failing', defaults, function (er) { - t.equals(er.message, 'payment required : @scoped/package-failing') - }) -}) |