• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict'
2
3const figgyPudding = require('figgy-pudding')
4const getStream = require('get-stream')
5const { test } = require('tap')
6const tnock = require('./util/tnock.js')
7
8const team = require('../index.js')
9
10const REG = 'http://localhost:1337'
11const OPTS = figgyPudding({})({
12  registry: REG
13})
14
15test('create', t => {
16  tnock(t, REG).put(
17    '/-/org/foo/team', { name: 'cli' }
18  ).reply(201, { name: 'cli' })
19  return team.create('@foo:cli', OPTS).then(ret => {
20    t.deepEqual(ret, { name: 'cli' }, 'request succeeded')
21  })
22})
23
24test('create bad entity name', t => {
25  return team.create('go away', OPTS).then(
26    () => { throw new Error('should not succeed') },
27    err => { t.ok(err, 'error on bad entity name') }
28  )
29})
30
31test('create empty entity', t => {
32  return team.create(undefined, OPTS).then(
33    () => { throw new Error('should not succeed') },
34    err => { t.ok(err, 'error on bad entity name') }
35  )
36})
37
38test('create w/ description', t => {
39  tnock(t, REG).put('/-/org/foo/team', {
40    name: 'cli',
41    description: 'just some cool folx'
42  }).reply(201, { name: 'cli' })
43  return team.create('@foo:cli', OPTS.concat({
44    description: 'just some cool folx'
45  })).then(ret => {
46    t.deepEqual(ret, { name: 'cli' }, 'no desc in return')
47  })
48})
49
50test('destroy', t => {
51  tnock(t, REG).delete(
52    '/-/team/foo/cli'
53  ).reply(204, {})
54  return team.destroy('@foo:cli', OPTS).then(ret => {
55    t.deepEqual(ret, {}, 'request succeeded')
56  })
57})
58
59test('add', t => {
60  tnock(t, REG).put(
61    '/-/team/foo/cli/user', { user: 'zkat' }
62  ).reply(201, {})
63  return team.add('zkat', '@foo:cli', OPTS).then(ret => {
64    t.deepEqual(ret, {}, 'request succeeded')
65  })
66})
67
68test('rm', t => {
69  tnock(t, REG).delete(
70    '/-/team/foo/cli/user', { user: 'zkat' }
71  ).reply(204, {})
72  return team.rm('zkat', '@foo:cli', OPTS).then(ret => {
73    t.deepEqual(ret, {}, 'request succeeded')
74  })
75})
76
77test('lsTeams', t => {
78  tnock(t, REG).get(
79    '/-/org/foo/team?format=cli'
80  ).reply(200, ['foo:bar', 'foo:cli'])
81  return team.lsTeams('foo', OPTS).then(ret => {
82    t.deepEqual(ret, ['foo:bar', 'foo:cli'], 'got teams')
83  })
84})
85
86test('lsTeams error', t => {
87  tnock(t, REG).get(
88    '/-/org/foo/team?format=cli'
89  ).reply(500)
90  return team.lsTeams('foo', OPTS).then(
91    () => { throw new Error('should not succeed') },
92    err => { t.equal(err.code, 'E500', 'got error code') }
93  )
94})
95
96test('lsTeams.stream', t => {
97  tnock(t, REG).get(
98    '/-/org/foo/team?format=cli'
99  ).reply(200, ['foo:bar', 'foo:cli'])
100  return getStream.array(team.lsTeams.stream('foo', OPTS)).then(ret => {
101    t.deepEqual(ret, ['foo:bar', 'foo:cli'], 'got teams')
102  })
103})
104
105test('lsUsers', t => {
106  tnock(t, REG).get(
107    '/-/team/foo/cli/user?format=cli'
108  ).reply(500)
109  return team.lsUsers('@foo:cli', OPTS).then(
110    () => { throw new Error('should not succeed') },
111    err => { t.equal(err.code, 'E500', 'got error code') }
112  )
113})
114
115test('lsUsers error', t => {
116  tnock(t, REG).get(
117    '/-/team/foo/cli/user?format=cli'
118  ).reply(200, ['iarna', 'zkat'])
119  return team.lsUsers('@foo:cli', OPTS).then(ret => {
120    t.deepEqual(ret, ['iarna', 'zkat'], 'got team members')
121  })
122})
123
124test('lsUsers.stream', t => {
125  tnock(t, REG).get(
126    '/-/team/foo/cli/user?format=cli'
127  ).reply(200, ['iarna', 'zkat'])
128  return getStream.array(team.lsUsers.stream('@foo:cli', OPTS)).then(ret => {
129    t.deepEqual(ret, ['iarna', 'zkat'], 'got team members')
130  })
131})
132
133test('edit', t => {
134  t.throws(() => {
135    team.edit()
136  }, /not implemented/)
137  t.done()
138})
139