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()
7 var cache = require('./fixtures/underscore/cache.json')
11 var REV = '/-rev/72-47f2986bfd8e8b55068b204588bbf484'
12 var URI = 'http://localhost:1337/underscore'
13 var TOKEN = 'of-glad-tidings'
23 test('unpublish call contract', function (t) {
24 t.throws(function () {
25 client.unpublish(undefined, AUTH, nop)
28 t.throws(function () {
29 client.unpublish([], AUTH, nop)
30 }, 'requires URI to be a string')
32 t.throws(function () {
33 client.unpublish(URI, undefined, nop)
34 }, 'requires params object')
36 t.throws(function () {
37 client.unpublish(URI, '', nop)
38 }, 'params must be object')
40 t.throws(function () {
41 client.unpublish(URI, AUTH, undefined)
42 }, 'requires callback')
44 t.throws(function () {
45 client.unpublish(URI, AUTH, 'callback')
46 }, 'callback must be function')
53 client.unpublish(URI, params, nop)
55 { name: 'AssertionError', message: 'must pass auth to unpublish' },
56 'must pass auth to unpublish'
62 test('unpublish a package', function (t) {
63 server.expect('GET', '/underscore?write=true', function (req, res) {
64 t.equal(req.method, 'GET')
69 server.expect('PUT', '/underscore' + REV, function (req, res) {
70 t.equal(req.method, 'PUT')
73 req.setEncoding('utf-8')
74 req.on('data', function (d) {
78 req.on('end', function () {
79 var updated = JSON.parse(b)
80 t.notOk(updated.versions[VERSION])
86 server.expect('GET', '/underscore', function (req, res) {
87 t.equal(req.method, 'GET')
92 server.expect('DELETE', '/underscore/-/underscore-1.3.2.tgz' + REV, function (req, res) {
93 t.equal(req.method, 'DELETE')
95 res.json({ unpublished: true })
98 client.unpublish(URI, PARAMS, function (error) {
99 t.ifError(error, 'no errors')