Welcome to mirror list, hosted at ThFree Co, Russian Federation.

unpublish.js « test « npm-registry-client « node_modules « npm « deps - github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: afb16b78773a7a97a3b814d57d55ac92be679576 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
var test = require('tap').test

var server = require('./lib/server.js')
var common = require('./lib/common.js')
var client = common.freshClient()

var cache = require('./fixtures/underscore/cache.json')

function nop () {}

var REV = '/-rev/72-47f2986bfd8e8b55068b204588bbf484'
var URI = 'http://localhost:1337/underscore'
var TOKEN = 'of-glad-tidings'
var VERSION = '1.3.2'
var AUTH = {
  token: TOKEN
}
var PARAMS = {
  version: VERSION,
  auth: AUTH
}

test('unpublish call contract', function (t) {
  t.throws(function () {
    client.unpublish(undefined, AUTH, nop)
  }, 'requires a URI')

  t.throws(function () {
    client.unpublish([], AUTH, nop)
  }, 'requires URI to be a string')

  t.throws(function () {
    client.unpublish(URI, undefined, nop)
  }, 'requires params object')

  t.throws(function () {
    client.unpublish(URI, '', nop)
  }, 'params must be object')

  t.throws(function () {
    client.unpublish(URI, AUTH, undefined)
  }, 'requires callback')

  t.throws(function () {
    client.unpublish(URI, AUTH, 'callback')
  }, 'callback must be function')

  t.throws(
    function () {
      var params = {
        version: VERSION
      }
      client.unpublish(URI, params, nop)
    },
    { name: 'AssertionError', message: 'must pass auth to unpublish' },
    'must pass auth to unpublish'
  )

  t.end()
})

test('unpublish a package', function (t) {
  server.expect('GET', '/underscore?write=true', function (req, res) {
    t.equal(req.method, 'GET')

    res.json(cache)
  })

  server.expect('PUT', '/underscore' + REV, function (req, res) {
    t.equal(req.method, 'PUT')

    var b = ''
    req.setEncoding('utf-8')
    req.on('data', function (d) {
      b += d
    })

    req.on('end', function () {
      var updated = JSON.parse(b)
      t.notOk(updated.versions[VERSION])
    })

    res.json(cache)
  })

  server.expect('GET', '/underscore', function (req, res) {
    t.equal(req.method, 'GET')

    res.json(cache)
  })

  server.expect('DELETE', '/underscore/-/underscore-1.3.2.tgz' + REV, function (req, res) {
    t.equal(req.method, 'DELETE')

    res.json({ unpublished: true })
  })

  client.unpublish(URI, PARAMS, function (error) {
    t.ifError(error, 'no errors')

    t.end()
  })
})