<commit_before>require 'helper'

# test login
class FullLoginTest < Fastly::TestCase
  include CommonTests

  def setup
    @opts = login_opts(:full)
    begin
      @client = Fastly::Client.new(@opts)
      @fastly = Fastly.new(@opts)
    rescue => e
      warn e.inspect
      warn e.backtrace.join("\n")
      exit(-1)
    end
  end

  def test_raw_client
    user     = @client.get('/current_user')
    assert user
    assert_equal @opts[:user], user['login']
    assert_equal @opts[:name], user['name']

    customer = @client.get('/current_customer')
    assert customer
    assert_equal @opts[:customer], customer['name']
  end

  def test_current_user_and_customer
    user     = @fastly.current_user
    assert user
    assert_equal @opts[:user], user.login
    assert_equal @opts[:name], user.name

    customer = @fastly.current_customer
    assert customer
    assert_equal @opts[:customer], customer.name

    tmp_customer = user.customer
    assert_equal customer.id, tmp_customer.id

    tmp_user = customer.owner
    assert tmp_user
    assert_equal user.id, tmp_user.id
  end

  def test_fetching_particular_user
    current_user = @fastly.current_user
    assert current_user

    id_user = @fastly.get_user(current_user.id)
    assert_equal current_user.id, id_user.id
    assert_equal current_user.name, id_user.name

    # FIXME: looking up by login doesn't work yet
    # login_user = @fastly.get_user(current_user.login)
    # assert_equal current_user.id, login_user.id
    # assert_equal current_user.name, login_user.name

    current_customer = @fastly.current_customer
    assert current_customer

    customer = @fastly.get_customer(current_customer.id)
    assert_equal current_customer.id, customer.id
    assert_equal current_customer.name, customer.name
  end

  def test_creating_and_updating_user
    customer = @fastly.current_customer
    email    = "<EMAIL>-#{random_<EMAIL>"
    user     = @fastly.create_user(:login => email, :name => 'New User')
    assert user
    assert_equal customer.id, user.customer_id
    assert_equal 'New User', user.name
    assert_equal email, user.login

    tmp       = @fastly.get_user(user.id)

    assert tmp
    assert_equal user.id, tmp.id
    assert_equal user.name, tmp.name

    user.name = '<NAME>'
    tmp      = @fastly.update_user(user)
    assert tmp
    assert_equal user.id, tmp.id
    assert_equal 'Updated Name', tmp.name

    assert @fastly.delete_user(user)
    tmp       = @fastly.get_user(user.id)
    assert_equal nil, tmp
  end
end<commit_msg>Convert full login test to spec style<commit_after>require 'helper'

class Fastly
  describe 'FullLoginTest' do
    let(:opts)             { login_opts(:full) }
    let(:client)           { Client.new(opts) }
    let(:fastly)           { Fastly.new(opts) }
    let(:current_user)     { fastly.current_user }
    let(:current_customer) { fastly.current_customer }

    describe '#current_{user,customer}' do
      it 'should have access to current user' do
        assert_instance_of User, current_user
        assert_equal opts[:user], current_user.login
        assert_equal opts[:name], current_user.name
      end

      it 'should have access to current customer' do
        assert_instance_of Customer, current_customer
        assert_equal opts[:customer], current_customer.id
      end

      it 'should have an arbitrary test confirming clearly defined relationships' do
        assert_equal current_customer.id, current_user.customer.id
        assert_equal current_user.id, current_customer.owner.id
      end
    end

    describe '#get_user' do
      let(:user) { fastly.get_user(current_user.id) }

      it 'should be able to fetch a user' do
        assert_equal current_user.name, user.name
      end
    end

    describe '#get_customer' do
      let(:customer) { fastly.get_customer(current_customer.id) }

      it 'should be able to fetch a customer' do
        assert_equal current_customer.name, customer.name
      end
    end

    describe '#create_user' do
      let(:email)     { "<EMAIL>ly-ruby-test-#{random_string}-new<EMAIL>" }
      let(:user_name) { 'New User' }
      let(:user)      { fastly.create_user(login: email, name: user_name) }

      it 'should create the user we wanted to create' do
        assert_instance_of User, user
        assert_equal current_customer.id, user.customer_id
        assert_equal user_name, user.name
        assert_equal email, user.login
      end

      after do
        fastly.delete_user(user)
      end
    end

    describe '#update_user' do
      let(:email)     { "<EMAIL>ly-ruby-test-#{random_string}-<EMAIL>" }
      let(:user_name) { 'New User' }
      let(:user)      { fastly.create_user(login: email, name: user_name) }
      let(:new_name)  { '<NAME>' }

      it 'should allow us to update the user' do
        assert_instance_of User, user
        user.name = new_name
        assert_equal new_name, fastly.update_user(user).name
      end

      after do
        fastly.delete_user(user)
      end
    end

    describe '#delete_user' do
      let(:email)     { "<EMAIL>ly-ruby-test-#{random_string}-<EMAIL>" }
      let(:user_name) { 'New User' }
      let(:user)      { fastly.create_user(login: email, name: user_name) }

      it 'should allow us to delete a user' do
        user_id = user.id
        assert_equal true, fastly.delete_user(user)
        assert_equal nil, fastly.get_user(user_id)
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.09557879288203999, 'fraction_numerical': 0.000183452577508714, 'mean_word_length': 2.836734693877551, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1170348', 'n_tokens_mistral': 1717, 'n_tokens_neox': 1683, 'n_words': 406}