import { test } from '@japa/runner'
import { CertificateFile, CertificateFileKind } from '../../../../src/index.js'

const organization = 'test-organization'

test.group('CertificateFile.fromName()', () => {
  test('sets the kind', ({ assert }) => {
    const result = CertificateFile.fromName('name', organization)
    assert.equal(result.kind, CertificateFileKind)
  })

  test('sets the organization', ({ assert }) => {
    const result = CertificateFile.fromName('name', organization)
    assert.equal(result.organization, organization)
  })

  test('sets the name', ({ assert }) => {
    const result = CertificateFile.fromName('name', organization)
    assert.equal(result.info.name, 'name')
  })

  test('sets the key', ({ assert }) => {
    const result = CertificateFile.fromName('name', organization)
    assert.typeOf(result.key, 'string')
    assert.notEqual(result.key, '')
  })

  test('sets the owner', ({ assert }) => {
    const result = CertificateFile.fromName('name', organization, 'other')
    assert.equal(result.owner, 'other')
  })
})
