unit_tests:
  - name: global_test_fan_total_points_correct_calculation
    description: >
      Test that aggregations for calculating
      total events, total decay and non-decay points
      and log total points and non-decay log total
      points work as expected.
    model: GLOBAL_STG_FANS_TOTAL_POINTS_DBT
    given:
      - input: ref('GLOBAL_STG_ALL_FANS_ARTISTS_DBT')
        rows:
          - {
              fan_id: 'john1',
              global_participant_id: 'artist a',
              first_event_date: 2023-11-07 00:00:00-0,
              last_event_date: 2024-05-07 00:00:00-0,
            }
      - input: ref('GLOBAL_STG_FANS_POINT_CALCULATION_DBT')
        rows:
          - {
              fan_id: 'john1',
              source_type: '4316',
              global_participant_id: 'artist a',
              period_name: 'LE11',
              nr_of_events: 20,
              worth: 5,
              decay_flag: 1,
              decay_factor: 0.1,
              cap: 9999999,
              description: 'This is feature called 4316',
              final_feature_points: 10,
              non_decay_feature_points: 100,
          }
          - {
            fan_id: 'john1',
            source_type: 'campaign',
            global_participant_id: 'artist a',
            period_name: 'LE11',
            nr_of_events: 1,
            worth: 100,
            decay_flag: 0,
            decay_factor: 0.1,
            cap: 9999999,
            description: 'This is feature called campaign',
            final_feature_points: 100,
            non_decay_feature_points: 100,
          }
    expect:
      rows:
        - {
          fan_id: 'john1',
          global_participant_id: 'artist a',
          total_events: 21,
          total_points: 111,
          log_total_points: 2.04922,
          non_decay_total_points: 200,
          non_decay_log_total_points: 2.3032,
          last_event_date: 2024-05-07 00:00:00-0,
          }
  - name: global_test_updated_artist_bin_intervals
    description: >
      Test that segmentation bins are updated
      as expected.
    model: GLOBAL_STG_UPDATED_ARTIST_BIN_INTERVALS_DBT
    given:
      - input: ref('GLOBAL_STG_ARTIST_BIN_INTERVALS_DBT')
        rows:
          - {
            global_participant_id: 'artist a',
            min_total_points: 200,
            max_total_points: 4000,
            min_log_total_points: 2.6,
            max_log_total_points: 3.5,
            segment: 1,
            bin_width: 500,
            bin_start: 200,
            bin_end: 700,
            log_bin_width: 0.2,
            log_bin_start: 2.6,
            log_bin_end: 2.8,
          }
          - {
            global_participant_id: 'artist a',
            min_total_points: 200,
            max_total_points: 4000,
            min_log_total_points: 2.6,
            max_log_total_points: 3.5,
            segment: 2,
            bin_width: 2100,
            bin_start: 700,
            bin_end: 2800,
            log_bin_width: 0.5,
            log_bin_start: 2.8,
            log_bin_end: 3.3,
          }
          - {
            global_participant_id: 'artist a',
            min_total_points: 200,
            max_total_points: 4000,
            min_log_total_points: 2.6,
            max_log_total_points: 3.5,
            segment: 3,
            bin_width: 1200,
            bin_start: 2800,
            bin_end: 4000,
            log_bin_width: 0.2,
            log_bin_start: 3.3,
            log_bin_end: 3.5,
          }
    expect:
        rows:
          - {
            global_participant_id: 'artist a',
            min_total_points: 200,
            max_total_points: 4000,
            min_log_total_points: 2.6,
            max_log_total_points: 3.5,
            segment: 1,
            bin_width: 500,
            bin_start: 200,
            bin_end: 700,
            log_bin_width: 0.2,
            log_bin_start: 2.6,
            log_bin_end: 3.135,
          }
          - {
            global_participant_id: 'artist a',
            min_total_points: 200,
            max_total_points: 4000,
            min_log_total_points: 2.6,
            max_log_total_points: 3.5,
            segment: 2,
            bin_width: 2100,
            bin_start: 700,
            bin_end: 2800,
            log_bin_width: 0.5,
            log_bin_start: 3.135,
            log_bin_end: 3.325,
          }
          - {
            global_participant_id: 'artist a',
            min_total_points: 200,
            max_total_points: 4000,
            min_log_total_points: 2.6,
            max_log_total_points: 3.5,
            segment: 3,
            bin_width: 1200,
            bin_start: 2800,
            bin_end: 4000,
            log_bin_width: 0.2,
            log_bin_start: 3.325,
            log_bin_end: 3.5,
          }
  - name: global_test_engineered_feature_13703
    description: >
      Test that feature 13703 from Apple is
      correctly used when assigning events
      to fans.
    model: GLOBAL_STG_FANS_ENGINEERED_FEATURES_DBT
    given:
      - input: ref('GLOBAL_STG_FANS_FOR_SEGMENTATION_DBT')
        rows:
          - {
            fan_id: 'fan1',
            global_participant_id: 'artist a',
            source_type: '13703',
            period_name: 'LE_0',
            nr_of_events: 1
          }
          - {
            fan_id: 'fan1',
            global_participant_id: 'artist a',
            source_type: '13703',
            period_name: 'LE_4',
            nr_of_events: 3
          }
          - {
            fan_id: 'fan2',
            global_participant_id: 'artist b',
            source_type: '13703',
            period_name: 'LE_11',
            nr_of_events: 1
          }
      - input: ref('SEGMENTATION_DECAY_FACTORS_DBT')
        format: sql
        rows: select * from SEGMENTATION_DECAY_FACTORS_DBT
      - input: ref('FAN_ARTIST_ACQUISITION_CHANNEL_DBT')
        format: sql
        rows: select * from FAN_ARTIST_ACQUISITION_CHANNEL_DBT where 1=0
      - input: ref('STG_SEGMENTATION_DECAY_INTERVALS_DBT')
        format: sql
        rows: select * from STG_SEGMENTATION_DECAY_INTERVALS_DBT
    expect:
        rows:
          - {
            fan_id: 'fan1',
            global_participant_id: 'artist a',
            source_type: '13703_APPLE_MUSIC_FIRST',
            period_name: 'LE_4',
            nr_of_events: 1
          }
          - {
            fan_id: 'fan1',
            global_participant_id: 'artist a',
            source_type: '13703_APPLE_MUSIC_AFTER_FIRST',
            period_name: 'LE_4',
            nr_of_events: 2
          }
          - {
            fan_id: 'fan1',
            global_participant_id: 'artist a',
            source_type: '13703_APPLE_MUSIC_AFTER_FIRST',
            period_name: 'LE_0',
            nr_of_events: 1
          }
          - {
            fan_id: 'fan2',
            global_participant_id: 'artist b',
            source_type: '13703_APPLE_MUSIC_FIRST',
            period_name: 'LE_11',
            nr_of_events: 1
          }
          - {
            fan_id: 'fan2',
            global_participant_id: 'artist b',
            source_type: '13703_APPLE_MUSIC_AFTER_FIRST',
            period_name: 'LE_11',
            nr_of_events: 0
          }
