11cb0ef41Sopenharmony_ciconst t = require('tap')
21cb0ef41Sopenharmony_ciconst { load: loadMockNpm } = require('../../fixtures/mock-npm.js')
31cb0ef41Sopenharmony_ciconst MockRegistry = require('@npmcli/mock-registry')
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ciconst pkgName = '@npmcli/test-package'
61cb0ef41Sopenharmony_ciconst authToken = 'test-auth-token'
71cb0ef41Sopenharmony_ciconst username = 'test-user'
81cb0ef41Sopenharmony_ciconst auth = { '//registry.npmjs.org/:_authToken': authToken }
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_cit.test('no args', async t => {
111cb0ef41Sopenharmony_ci  const { npm } = await loadMockNpm(t)
121cb0ef41Sopenharmony_ci  await t.rejects(
131cb0ef41Sopenharmony_ci    npm.exec('star', []),
141cb0ef41Sopenharmony_ci    { code: 'EUSAGE' },
151cb0ef41Sopenharmony_ci    'should throw usage error'
161cb0ef41Sopenharmony_ci  )
171cb0ef41Sopenharmony_ci})
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_cit.test('first person to star a package unicode:false', async t => {
201cb0ef41Sopenharmony_ci  const { npm, joinedOutput } = await loadMockNpm(t, {
211cb0ef41Sopenharmony_ci    config: { unicode: false, ...auth },
221cb0ef41Sopenharmony_ci  })
231cb0ef41Sopenharmony_ci  const registry = new MockRegistry({
241cb0ef41Sopenharmony_ci    tap: t,
251cb0ef41Sopenharmony_ci    registry: npm.config.get('registry'),
261cb0ef41Sopenharmony_ci    authorization: authToken,
271cb0ef41Sopenharmony_ci  })
281cb0ef41Sopenharmony_ci  const manifest = registry.manifest({ name: pkgName })
291cb0ef41Sopenharmony_ci  await registry.package({ manifest, query: { write: true } })
301cb0ef41Sopenharmony_ci  registry.whoami({ username })
311cb0ef41Sopenharmony_ci  registry.star(manifest, { [username]: true })
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ci  await npm.exec('star', [pkgName])
341cb0ef41Sopenharmony_ci  t.equal(
351cb0ef41Sopenharmony_ci    joinedOutput(),
361cb0ef41Sopenharmony_ci    '(*) @npmcli/test-package',
371cb0ef41Sopenharmony_ci    'should output starred package msg'
381cb0ef41Sopenharmony_ci  )
391cb0ef41Sopenharmony_ci})
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_cit.test('second person to star a package unicode:true', async t => {
421cb0ef41Sopenharmony_ci  const { npm, joinedOutput } = await loadMockNpm(t, {
431cb0ef41Sopenharmony_ci    config: { unicode: true, ...auth },
441cb0ef41Sopenharmony_ci  })
451cb0ef41Sopenharmony_ci  const registry = new MockRegistry({
461cb0ef41Sopenharmony_ci    tap: t,
471cb0ef41Sopenharmony_ci    registry: npm.config.get('registry'),
481cb0ef41Sopenharmony_ci    authorization: authToken,
491cb0ef41Sopenharmony_ci  })
501cb0ef41Sopenharmony_ci  const manifest = registry.manifest({ name: pkgName, users: { otheruser: true } })
511cb0ef41Sopenharmony_ci  await registry.package({ manifest, query: { write: true } })
521cb0ef41Sopenharmony_ci  registry.whoami({ username })
531cb0ef41Sopenharmony_ci  registry.star(manifest, { otheruser: true, [username]: true })
541cb0ef41Sopenharmony_ci
551cb0ef41Sopenharmony_ci  await npm.exec('star', [pkgName])
561cb0ef41Sopenharmony_ci  t.equal(
571cb0ef41Sopenharmony_ci    joinedOutput(),
581cb0ef41Sopenharmony_ci    '★  @npmcli/test-package',
591cb0ef41Sopenharmony_ci    'should output starred package msg'
601cb0ef41Sopenharmony_ci  )
611cb0ef41Sopenharmony_ci})
62