summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/npm-registry-client/test/tag.js
blob: e10490ee6c51c6894d7b5b787091de3afb318405 (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
104
105
106
107
108
var test = require('tap').test

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

function nop () {}

var URI = 'http://localhost:1337/underscore'
var USERNAME = 'username'
var PASSWORD = '%1234@asdf%'
var EMAIL = 'i@izs.me'
var VERSION = '1.3.2'
var TAG = 'not-lodash'
var AUTH = {
  username: USERNAME,
  password: PASSWORD,
  email: EMAIL
}
var PARAMS = {
  tag: TAG,
  version: VERSION,
  auth: AUTH
}

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

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

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

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

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

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

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

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

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

  t.end()
})

test('tag a package', function (t) {
  server.expect('PUT', '/underscore/not-lodash', function (req, res) {
    t.equal(req.method, 'PUT')

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

    req.on('end', function () {
      var updated = JSON.parse(b)

      t.deepEqual(updated, '1.3.2')

      res.statusCode = 201
      res.json({ tagged: true })
    })
  })

  client.tag(URI, PARAMS, function (error, data) {
    t.ifError(error, 'no errors')
    t.ok(data.tagged, 'was tagged')

    server.close()
    t.end()
  })
})