import { Eltro as t, assert} from 'eltro'
import encode from '../../api/jwt/encode.mjs'
import decode from '../../api/jwt/decode.mjs'

t.describe('encode', function() {
  t.test('should faile with invalid header and body', function() {
    assert.throws(
      function() {
        encode('', '')
      },
      /both header and body should be of type object/
    )
  })
  t.test('should faile with invalid alg type', function() {
    assert.throws(
      function() {
        encode({ alg: 'asdf' }, {})
      },
      /Only alg HS256, HS384 and HS512 are supported/
    )
  })
  t.test('should have default header options', function() {
    const assertTest = '1234'
    let token = encode(null, { iss: 'test', test: assertTest }, 'bla')
    let decoded = decode(token, { 'test': { 'default@HS256': 'bla' } }, [])
    assert.strictEqual(decoded.test, assertTest)
  })
})
