require 'test_helper'

class GetAcceptDocumentTest < Minitest::Test
  def test_all_gets_array_of_documents
    VCR.use_cassette('all_documents') do
      response = api.document.all
      refute_nil response
      assert_instance_of Array, response
    end
  end

  def test_create_create_new_document
    data = fixture('document', 'from_template')
    VCR.use_cassette('new_document') do
      response = api.document.create(data)
      refute_nil response['id']
      assert_equal 1, response['recipients'].size
    end
  end

  def test_send_sends_the_document
    VCR.use_cassette('sent_document') do
      response = api.document.send('re28s73qr')
      refute_nil response['id']
      assert_includes %w( sent processing), response['status']
    end
  end

  def test_find_document_retrieves_document
    VCR.use_cassette('retrieved_document') do
      response = api.document.find('re28s73qr')
      assert_equal 're28s73qr', response['id']
    end
  end

  def test_find_by_external_id_retrieves_document
    VCR.use_cassette('retrieved_document_by_external_id') do
      response = api.document.find_by_external_id(66976)
      assert_equal '66976', response['external_id']
    end
  end

  def test_delete_will_remove_the_document
    document_to_be_deleted = {}
    VCR.use_cassette('document_to_be_deleted') do
      document_to_be_deleted = api.document.create(fixture('document', 'from_template'))
    end
    VCR.use_cassette('deleted_document') do
      response = api.document.destroy(document_to_be_deleted['id'])
      assert_equal 204, response.status
    end
  end

  def test_recipients_returns_all_recipients_of_document
    document_for_recipients = {}
    VCR.use_cassette('document_for_recipients') do
      document_for_recipients = api.document.create(fixture('document', 'from_template'))
    end
    
    VCR.use_cassette('get_document_recipients') do
      response = api.document.recipients(document_for_recipients['id'])
      assert_instance_of Array, response['recipients']
    end
  end

  # def test_open_url_returns_a_url
  #   assert_equal "https://app.getaccept.com/auth/sso/login?token=fake_token&go=", api.document.open_url('fake_id', 'https://google.com')
  # end
end
