Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: lib/team.js tweaks and tests #2314

Merged
merged 1 commit into from Dec 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 11 additions & 8 deletions lib/team.js
@@ -1,20 +1,22 @@
'use strict'

const columns = require('cli-columns')
const libteam = require('libnpmteam')

const npm = require('./npm.js')
const output = require('./utils/output.js')
const otplease = require('./utils/otplease.js')
const usageUtil = require('./utils/usage')

const subcommands = ['create', 'destroy', 'add', 'rm', 'ls', 'edit']
const subcommands = ['create', 'destroy', 'add', 'rm', 'ls']

const usage = usageUtil(
'team',
'npm team create <scope:team> [--otp <otpcode>]\n' +
'npm team destroy <scope:team> [--otp <otpcode>]\n' +
'npm team add <scope:team> <user> [--otp <otpcode>]\n' +
'npm team rm <scope:team> <user> [--otp <otpcode>]\n' +
'npm team ls <scope>|<scope:team>\n' +
'npm team edit <scope:team>'
'npm team ls <scope>|<scope:team>\n'
)

const completion = (opts, cb) => {
Expand All @@ -28,7 +30,6 @@ const completion = (opts, cb) => {
case 'destroy':
case 'add':
case 'rm':
case 'edit':
return cb(null, [])
default:
return cb(new Error(argv[2] + ' not recognized'))
Expand Down Expand Up @@ -56,8 +57,6 @@ const team = async ([cmd, entity = '', user = '']) => {
else
return teamListTeams(entity, opts)
}
case 'edit':
throw new Error('`npm team edit` is not implemented yet.')
default:
throw usage
}
Expand Down Expand Up @@ -125,7 +124,9 @@ const teamListUsers = async (entity, opts) => {
else if (opts.parseable)
output(users.join('\n'))
else if (!opts.silent && opts.loglevel !== 'silent') {
output(`\n@${entity} has ${users.length} user${users.length === 1 ? '' : 's'}:\n`)
const plural = users.length === 1 ? '' : 's'
const more = users.length === 0 ? '' : ':\n'
output(`\n@${entity} has ${users.length} user${plural}${more}`)
output(columns(users, { padding: 1 }))
}
}
Expand All @@ -137,7 +138,9 @@ const teamListTeams = async (entity, opts) => {
else if (opts.parseable)
output(teams.join('\n'))
else if (!opts.silent && opts.loglevel !== 'silent') {
output(`\n@${entity} has ${teams.length} team${teams.length === 1 ? '' : 's'}:\n`)
const plural = teams.length === 1 ? '' : 's'
const more = teams.length === 0 ? '' : ':\n'
output(`\n@${entity} has ${teams.length} team${plural}${more}`)
output(columns(teams.map(t => `@${t}`), { padding: 1 }))
}
}
Expand Down
85 changes: 85 additions & 0 deletions tap-snapshots/test-lib-team.js-TAP.test.js
@@ -0,0 +1,85 @@
/* IMPORTANT
* This snapshot file is auto-generated, but designed for humans.
* It should be checked into source control and tracked carefully.
* Re-generate by setting TAP_SNAPSHOT=1 and running tests.
* Make sure to inspect the output below. Do not ignore changes!
*/
'use strict'
exports[`test/lib/team.js TAP team add <scope:team> <user> --parseable > should output success result for parseable add user 1`] = `
foo npmcli:developers added
`

exports[`test/lib/team.js TAP team add <scope:team> <user> default output > should output success result for add user 1`] = `
foo added to @npmcli:developers
`

exports[`test/lib/team.js TAP team create <scope:team> --parseable > should output parseable success result for create team 1`] = `
npmcli:newteam created
`

exports[`test/lib/team.js TAP team create <scope:team> default output > should output success result for create team 1`] = `
+@npmcli:newteam
`

exports[`test/lib/team.js TAP team destroy <scope:team> --parseable > should output parseable result for destroy team 1`] = `
npmcli:newteam deleted
`

exports[`test/lib/team.js TAP team destroy <scope:team> default output > should output success result for destroy team 1`] = `
-@npmcli:newteam
`

exports[`test/lib/team.js TAP team ls <scope:team> --parseable > should list users for a parseable scope:team 1`] = `
darcyclarke
isaacs
nlf
ruyadorno
`

exports[`test/lib/team.js TAP team ls <scope:team> default output > should list users for a given scope:team 1`] = `

@npmcli:developers has 4 users:
darcyclarke isaacs nlf ruyadorno
`

exports[`test/lib/team.js TAP team ls <scope:team> no users > should list no users for a given scope 1`] = `

@npmcli:developers has 0 users
`

exports[`test/lib/team.js TAP team ls <scope:team> single user > should list single user for a given scope 1`] = `

@npmcli:developers has 1 user:
foo
`

exports[`test/lib/team.js TAP team ls <scope> --parseable > should list teams for a parseable scope 1`] = `
npmcli:designers
npmcli:developers
npmcli:product
`

exports[`test/lib/team.js TAP team ls <scope> default output > should list teams for a given scope 1`] = `

@npmcli has 3 teams:
@npmcli:designers @npmcli:developers @npmcli:product
`

exports[`test/lib/team.js TAP team ls <scope> no teams > should list no teams for a given scope 1`] = `

@npmcli has 0 teams
`

exports[`test/lib/team.js TAP team ls <scope> single team > should list single team for a given scope 1`] = `

@npmcli has 1 team:
@npmcli:developers
`

exports[`test/lib/team.js TAP team rm <scope:team> <user> --parseable > should output parseable result for remove user 1`] = `
foo npmcli:newteam removed
`

exports[`test/lib/team.js TAP team rm <scope:team> <user> default output > should output success result for remove user 1`] = `
foo removed from @npmcli:newteam
`