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'
21 test('distTags.fetch call contract', function (t) {
22 t.throws(function () {
23 client.distTags.fetch(undefined, AUTH, nop)
26 t.throws(function () {
27 client.distTags.fetch([], PARAMS, nop)
28 }, 'requires URI to be a string')
30 t.throws(function () {
31 client.distTags.fetch(BASE_URL, undefined, nop)
32 }, 'requires params object')
34 t.throws(function () {
35 client.distTags.fetch(BASE_URL, '', nop)
36 }, 'params must be object')
38 t.throws(function () {
39 client.distTags.fetch(BASE_URL, PARAMS, undefined)
40 }, 'requires callback')
42 t.throws(function () {
43 client.distTags.fetch(BASE_URL, PARAMS, 'callback')
44 }, 'callback must be function')
51 client.distTags.fetch(BASE_URL, params, nop)
54 name: 'AssertionError',
55 message: 'must pass package name to distTags.fetch'
57 'distTags.fetch must include package name'
65 client.distTags.fetch(BASE_URL, params, nop)
67 { name: 'AssertionError', message: 'must pass auth to distTags.fetch' },
68 'distTags.fetch must include auth'
74 test('fetch dist-tags for a package', function (t) {
75 server.expect('GET', URI, function (req, res) {
76 t.equal(req.method, 'GET')
79 req.setEncoding('utf8')
80 req.on('data', function (d) {
84 req.on('end', function () {
85 t.notOk(b, 'no request body')
88 res.json({ a: '1.0.0', b: '2.0.0', _etag: 'xxx' })
92 client.distTags.fetch(BASE_URL, PARAMS, function (error, data) {
93 t.ifError(error, 'no errors')
94 t.same(data, { a: '1.0.0', b: '2.0.0' }, 'etag filtered from response')