<commit_before>require 'spec_helper'
require 'optimus_prime/sources/appsflyer'

describe OptimusPrime::Sources::Appsflyer do
  let(:app_id) { SecureRandom.hex }
  let(:api_token) { SecureRandom.hex }

  let(:installs_report) { File.read 'spec/supports/appsflyer/installs.csv' }

  let(:source) do
    OptimusPrime::Sources::Appsflyer.new app_id: app_id,
                                         api_token: api_token,
                                         report_type: 'installs',
                                         from: Time.utc(2015, 1, 12),
                                         to: Time.utc(2015, 1, 19)
  end

  before do
    stub_request(:get, "https://hq.appsflyer.com/export/#{app_id}/installs_report")
      .with(query: { api_token: api_token, from: '2015-01-12', to: '2015-01-19' })
      .to_return(status: 200, body: installs_report)
  end

  it 'should yield events' do
    source.each do |event|
      expect(event.keys).to match_array [
        'Agency/PMD (af_prt)',
        'App Version',
        'Appsflyer Device Id',
        'Campaign (c)',
        'City',
        'Click Time',
        'Click URL',
        'Contributor 1',
        'Contributor 2',
        'Contributor 3',
        'Cost Per Install (af_cpi)',
        'Country Code',
        'Customer User Id',
        'Device Name',
        'Device Type',
        'IDFA',
        'IP',
        'Install Time',
        'Language',
        'MAC',
        'Media Source (pid)',
        'OS Version',
        'SDK Version',
        'Site Id (af_siteid)',
        'Sub Param 1 (af_sub1)',
        'Sub Param 2 (af_sub2)',
        'Sub Param 3 (af_sub3)',
        'Sub Param 4 (af_sub4)',
        'Sub Param 5 (af_sub5)',<commit_msg>appsflyer source step helpers<commit_after>require 'spec_helper'
require 'optimus_prime/sources/appsflyer'

describe OptimusPrime::Sources::Appsflyer do
  let(:app_id) { SecureRandom.hex }
  let(:api_token) { SecureRandom.hex }
  let(:installs_report) { File.read 'spec/supports/appsflyer/installs.csv' }
  let(:source) do
    OptimusPrime::Sources::Appsflyer.new(
      app_id: app_id, api_token: api_token, report_type: 'installs',
      from: Time.utc(2015, 1, 12), to: Time.utc(2015, 1, 19)
    )
  end

  before do
    stub_request(:get, "https://hq.appsflyer.com/export/#{app_id}/installs_report")
      .with(query: { api_token: api_token, from: '2015-01-12', to: '2015-01-19' })
      .to_return(status: 200, body: installs_report)
  end

  it 'should yield events' do
    source.run_with.each do |event|
      expect(event.keys).to match_array [
        'Agency/PMD (af_prt)',
        'App Version',
        'Appsflyer Device Id',
        'Campaign (c)',
        'City',
        'Click Time',
        'Click URL',
        'Contributor 1',
        'Contributor 2',
        'Contributor 3',
        'Cost Per Install (af_cpi)',
        'Country Code',
        'Customer User Id',
        'Device Name',
        'Device Type',
        'IDFA',
        'IP',
        'Install Time',
        'Language',
        'MAC',
        'Media Source (pid)',
        'OS Version',
        'SDK Version',
        'Site Id (af_siteid)',
        'Sub Param 1 (af_sub1)',
        'Sub Param 2 (af_sub2)',
        'Sub Param 3 (af_sub3)',
        'Sub Param 4 (af_sub4)',
        'Sub Param 5 (af_sub5)',
{'fraction_non_alphanumeric': 0.13762855414398065, 'fraction_numerical': 0.027828191167574106, 'mean_word_length': 2.0677179962894248, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2880364', 'n_tokens_mistral': 1174, 'n_tokens_neox': 1095, 'n_words': 256}