<commit_before>require File.dirname(__FILE__) + '/../../test_helper.rb'

class Drip::Client::WorkflowsTest < Drip::TestCase
  def setup
    @stubs = Faraday::Adapter::Test::Stubs.new

    @connection = Faraday.new do |builder|
      builder.adapter :test, @stubs
    end

    @client = Drip::Client.new { |c| c.account_id = "12345" }
    @client.expects(:connection).at_least_once.returns(@connection)
  end

  context "#workflows" do
    setup do
      @response_status = 200
      @response_body = stub

      @stubs.get "12345/workflows" do
        [@response_status, {}, @response_body]
      end
    end

    should "send the right request" do
      expected = Drip::Response.new(@response_status, @response_body)
      assert_equal expected, @client.workflows
    end
  end

  context "#workflow" do
    setup do
      @response_status = 200
      @response_body = stub
      @id = 1234

      @stubs.get "12345/workflows/#{@id}" do
        [@response_status, {}, @response_body]
      end
    end

    should "send the right request" do
      expected = Drip::Response.new(@response_status, @response_body)
      assert_equal expected, @client.workflow(@id)
    end
  end

  context "#activate_workflow" do
    setup do
      @response_status = 204
      @response_body = stub
      @id = 1234

      @stubs.post "12345/workflows/#{@id}/activate" do
        [@response_status, {}, @response_body]
      end
    end

    should "send the right request" do
      expected = Drip::Response.new(@response_status, @response_body)
      assert_equal expected, @client.activate_workflow(@id)
    end
  end

  context "#pause_workflow" do
    setup do
      @response_status = 204
      @response_body = stub
      @id = 1234

      @stubs.post "12345/workflows/#{@id}/pause" do
        [@response_status, {}, @response_body]
      end
    end

    should "send the right request" do
      expected = Drip::Response.new(@response_status, @response_body)
      assert_equal expected, @client.pause_workflow(@id)
    end
  end

  context "#start_subscriber_workflow" do
    setup do
      @data = {
        "email" => "<EMAIL>",
        "time_zone" => "America/Los_Angeles"
      }
      @id = 9999999
      @payload = { "subscribers" => [@data] }.to_json

      @response_status = 204
      @response_body = stub

      @stubs.post "12345/workflows/#{@id}/subscribers", @payload do
        [@response_status, {}, @response_body]
      end
    end

    should "send the right request" do
      expected = Drip::Response.new(@response_status, @response_body)
      assert_equal expected, @client.start_subscriber_workflow(@id, @data)
    end
  end

  context "#remove_subscriber_workflow" do
    setup do
      @response_status = 200
      @response_body = stub
      @id = 1234
      @email = "<EMAIL>"

      @stubs.delete "12345/workflows/#{@id}/subscribers/#{CGI.escape @email}" do
        [@response_status, {}, @response_body]
      end
    end

    should "send the right request" do<commit_msg>Port workflows test<commit_after>require File.dirname(__FILE__) + '/../../test_helper.rb'

class Drip::Client::WorkflowsTest < Drip::TestCase
  def setup
    @client = Drip::Client.new { |c| c.account_id = "12345" }
  end

  context "#workflows" do
    setup do
      @response_status = 200
      @response_body = "stub"

      stub_request(:get, "https://api.getdrip.com/v2/12345/workflows").
        to_return(status: @response_status, body: @response_body, headers: {})
    end

    should "send the right request" do
      expected = Drip::Response.new(@response_status, @response_body)
      assert_equal expected, @client.workflows
    end
  end

  context "#workflow" do
    setup do
      @response_status = 200
      @response_body = "stub"
      @id = 1234

      stub_request(:get, "https://api.getdrip.com/v2/12345/workflows/#{@id}").
        to_return(status: @response_status, body: @response_body, headers: {})
    end

    should "send the right request" do
      expected = Drip::Response.new(@response_status, @response_body)
      assert_equal expected, @client.workflow(@id)
    end
  end

  context "#activate_workflow" do
    setup do
      @response_status = 204
      @response_body = nil
      @id = 1234

      stub_request(:post, "https://api.getdrip.com/v2/12345/workflows/#{@id}/activate").
        to_return(status: @response_status, body: @response_body, headers: {})
    end

    should "send the right request" do
      expected = Drip::Response.new(@response_status, @response_body)
      assert_equal expected, @client.activate_workflow(@id)
    end
  end

  context "#pause_workflow" do
    setup do
      @response_status = 204
      @response_body = nil
      @id = 1234

      stub_request(:post, "https://api.getdrip.com/v2/12345/workflows/#{@id}/pause").
        to_return(status: @response_status, body: @response_body, headers: {})
    end

    should "send the right request" do
      expected = Drip::Response.new(@response_status, @response_body)
      assert_equal expected, @client.pause_workflow(@id)
    end
  end

  context "#start_subscriber_workflow" do
    setup do
      @data = {
        "email" => "<EMAIL>",
        "time_zone" => "America/Los_Angeles"
      }
      @id = 9999999
      @payload = { "subscribers" => [@data] }.to_json

      @response_status = 204
      @response_body = nil

      stub_request(:post, "https://api.getdrip.com/v2/12345/workflows/#{@id}/subscribers").
        to_return(status: @response_status, body: @response_body, headers: {})
    end

    should "send the right request" do
      expected = Drip::Response.new(@response_status, @response_body)
      assert_equal expected, @client.start_subscriber_workflow(@id, @data)
    end
  end

  context "#remove_subscriber_workflow" do
    setup do
      @response_status = 200
      @response_body = "stub"
      @id = 1234
      @email = "<EMAIL>"

      stub_request(:delete, "https://api.getdrip.com/v2/12345/workflows/#{@id}/subscribers/#{CGI.escape @email}").
        to_return(status: @response_status, body: @response_body, headers: {})
    end

    should "send the right request" do
{'fraction_non_alphanumeric': 0.12502040150155053, 'fraction_numerical': 0.025787497959849845, 'mean_word_length': 2.890793650793651, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '1538807', 'n_tokens_mistral': 2126, 'n_tokens_neox': 1962, 'n_words': 437}