1'use strict' 2 3const figgyPudding = require('figgy-pudding') 4const getStream = require('get-stream') 5const test = require('tap').test 6const tnock = require('./util/tnock.js') 7 8const org = require('../index.js') 9 10const OPTS = figgyPudding({ registry: {} })({ 11 registry: 'https://mock.reg/' 12}) 13 14test('set', t => { 15 const memDeets = { 16 org: { 17 name: 'myorg', 18 size: 15 19 }, 20 user: 'myuser', 21 role: 'admin' 22 } 23 tnock(t, OPTS.registry).put('/-/org/myorg/user', { 24 user: 'myuser', 25 role: 'admin' 26 }).reply(201, memDeets) 27 return org.set('myorg', 'myuser', 'admin', OPTS).then(res => { 28 t.deepEqual(res, memDeets, 'got a membership details object back') 29 }) 30}) 31 32test('optional role for set', t => { 33 const memDeets = { 34 org: { 35 name: 'myorg', 36 size: 15 37 }, 38 user: 'myuser', 39 role: 'developer' 40 } 41 tnock(t, OPTS.registry).put('/-/org/myorg/user', { 42 user: 'myuser' 43 }).reply(201, memDeets) 44 return org.set('myorg', 'myuser', OPTS).then(res => { 45 t.deepEqual(res, memDeets, 'got a membership details object back') 46 }) 47}) 48 49test('rm', t => { 50 tnock(t, OPTS.registry).delete('/-/org/myorg/user', { 51 user: 'myuser' 52 }).reply(204) 53 return org.rm('myorg', 'myuser', OPTS).then(() => { 54 t.ok(true, 'request succeeded') 55 }) 56}) 57 58test('ls', t => { 59 const roster = { 60 'zkat': 'developer', 61 'iarna': 'admin', 62 'isaacs': 'owner' 63 } 64 tnock(t, OPTS.registry).get('/-/org/myorg/user').reply(200, roster) 65 return org.ls('myorg', OPTS).then(res => { 66 t.deepEqual(res, roster, 'got back a roster') 67 }) 68}) 69 70test('ls stream', t => { 71 const roster = { 72 'zkat': 'developer', 73 'iarna': 'admin', 74 'isaacs': 'owner' 75 } 76 const rosterArr = Object.keys(roster).map(k => [k, roster[k]]) 77 tnock(t, OPTS.registry).get('/-/org/myorg/user').reply(200, roster) 78 return getStream.array(org.ls.stream('myorg', OPTS)).then(res => { 79 t.deepEqual(res, rosterArr, 'got back a roster, in entries format') 80 }) 81}) 82