1 var test = require('tap').test
3 var server = require('./lib/server.js')
4 var common = require('./lib/common.js')
5 var client = common.freshClient()
9 var BASE_URL = 'http://localhost:1337/'
10 var URI = '/-/package/underscore/dist-tags'
15 var PACKAGE = 'underscore'
26 test('distTags.update call contract', function (t) {
27 t.throws(function () {
28 client.distTags.update(undefined, AUTH, nop)
31 t.throws(function () {
32 client.distTags.update([], PARAMS, nop)
33 }, 'requires URI to be a string')
35 t.throws(function () {
36 client.distTags.update(BASE_URL, undefined, nop)
37 }, 'requires params object')
39 t.throws(function () {
40 client.distTags.update(BASE_URL, '', nop)
41 }, 'params must be object')
43 t.throws(function () {
44 client.distTags.update(BASE_URL, PARAMS, undefined)
45 }, 'requires callback')
47 t.throws(function () {
48 client.distTags.update(BASE_URL, PARAMS, 'callback')
49 }, 'callback must be function')
53 var params = { distTags: DIST_TAGS, auth: AUTH }
54 client.distTags.update(BASE_URL, params, nop)
57 name: 'AssertionError',
58 message: 'must pass package name to distTags.update'
60 'distTags.update must include package name'
65 var params = { 'package': PACKAGE, auth: AUTH }
66 client.distTags.update(BASE_URL, params, nop)
69 name: 'AssertionError',
70 message: 'must pass distTags map to distTags.update'
72 'distTags.update must include dist-tags'
77 var params = { 'package': PACKAGE, distTags: DIST_TAGS }
78 client.distTags.update(BASE_URL, params, nop)
80 { name: 'AssertionError', message: 'must pass auth to distTags.update' },
81 'distTags.update must include auth'
87 test('update dist-tags for a package', function (t) {
88 server.expect('POST', URI, function (req, res) {
89 t.equal(req.method, 'POST')
92 req.setEncoding('utf8')
93 req.on('data', function (d) {
97 req.on('end', function () {
99 t.deepEqual(d, DIST_TAGS, 'got back tags')
106 client.distTags.update(BASE_URL, PARAMS, function (error, data) {
107 t.ifError(error, 'no errors')
108 t.ok(data.a && data.b, 'dist-tags set')