<commit_before>require 'spec_helper'
require 'active_support/core_ext/hash'

RSpec.describe HackerOne::Client::Activities do
  describe HackerOne::Client::Activities::BountyAwarded do
    let(:example) do
      {
        'id' => '1337',
        'type' => 'activity-bounty-awarded',
        'attributes' => {
          'message' => 'Bounty Awarded!',
          'created_at' => '2016-02-02T04:05:06.000Z',
          'updated_at' => '2016-02-02T04:05:06.000Z',
          'internal' => false,
          'bounty_amount' => '500.00',
          'bonus_amount' => '50.00'
        },
        'relationships' => {
          'actor' => {
            'data' => {
              'id' => '1337',
              'type' => 'program',
              'attributes' => {
                'handle' => 'security',
                'created_at' => '2016-02-02T04:05:06.000Z',
                'updated_at' => '2016-02-02T04:05:06.000Z'
              }
            }
          }
        }
      }.with_indifferent_access
    end

    it 'creates the activity type with attributes' do
      activity = HackerOne::Client::Activities.build example

      expect(activity.class).to eq described_class
      expect(activity.bounty_amount).to eq 500.00
      expect(activity.bonus_amount).to eq 50.00
    end

    it 'does not fail when bounty or bonus amount is not given' do
      example = {
        'type' => 'activity-bounty-awarded',
        'attributes' => {}
      }.with_indifferent_access

      activity = HackerOne::Client::Activities.build example

      expect(activity.bounty_amount).to eq 0
      expect(activity.bonus_amount).to eq 0
    end
  end

  describe HackerOne::Client::Activities::SwagAwarded do
    let(:example) do
      {
        'id' => '1337',
        'type' => 'activity-swag-awarded',
        'attributes' => {
          'message' => 'Swag Awarded!',
          'created_at' => '2016-02-02T04:05:06.000Z',
          'updated_at' => '2016-02-02T04:05:06.000Z',
          'internal' => false
        },
        'relationships' => {
          'actor' => {
            'data' => {
              'id' => '1337',
              'type' => 'user',
              'attributes' => {
                'username' => 'api-example',
                'name' => '<NAME>',
                'disabled' => false,
                'created_at' => '2016-02-02T04:05:06.000Z',
                'profile_picture' => {<commit_msg>Added test for malformed bounty and bonus amount<commit_after>require 'spec_helper'
require 'active_support/core_ext/hash'

RSpec.describe HackerOne::Client::Activities do
  describe HackerOne::Client::Activities::BountyAwarded do
    let(:example) do
      {
        'id' => '1337',
        'type' => 'activity-bounty-awarded',
        'attributes' => {
          'message' => 'Bounty Awarded!',
          'created_at' => '2016-02-02T04:05:06.000Z',
          'updated_at' => '2016-02-02T04:05:06.000Z',
          'internal' => false,
          'bounty_amount' => '500.00',
          'bonus_amount' => '50.00'
        },
        'relationships' => {
          'actor' => {
            'data' => {
              'id' => '1337',
              'type' => 'program',
              'attributes' => {
                'handle' => 'security',
                'created_at' => '2016-02-02T04:05:06.000Z',
                'updated_at' => '2016-02-02T04:05:06.000Z'
              }
            }
          }
        }
      }.with_indifferent_access
    end

    it 'creates the activity type with attributes' do
      activity = HackerOne::Client::Activities.build example

      expect(activity.class).to eq described_class
      expect(activity.bounty_amount).to eq 500.00
      expect(activity.bonus_amount).to eq 50.00
    end

    it 'does not fail when bounty or bonus amount is not given' do
      example = {
        'type' => 'activity-bounty-awarded',
        'attributes' => {}
      }.with_indifferent_access

      activity = HackerOne::Client::Activities.build example

      expect(activity.bounty_amount).to eq 0
      expect(activity.bonus_amount).to eq 0
    end

    it 'returns 0 when bounty amount or bonus amount are malformed' do
      example = {
        'type' => 'activity-bounty-awarded',
        'attributes' => {
          'bounty_amount' => 'steve',
          'bonus_amount' => 'harvey'
        }
      }.with_indifferent_access

      activity = HackerOne::Client::Activities.build example

      expect(activity.bounty_amount).to eq 0
      expect(activity.bonus_amount).to eq 0
    end
  end

  describe HackerOne::Client::Activities::SwagAwarded do
    let(:example) do
      {
        'id' => '1337',
        'type' => 'activity-swag-awarded',
        'attributes' => {
          'message' => 'Swag Awarded!',
          'created_at' => '2016-02-02T04:05:06.000Z',
          'updated_at' => '2016-02-02T04:05:06.000Z',
          'internal' => false
        },
        'relationships' => {
          'actor' => {
            'data' => {
              'id' => '1337',
              'type' => 'user',
              'attributes' => {
                'username' => 'api-example',
                'name' => '<NAME>',
                'disabled' => false,
                'created_at' => '2016-02-02T04:05:06.000Z',
                'profile_picture' => {
{'fraction_non_alphanumeric': 0.14890788224121557, 'fraction_numerical': 0.05944919278252612, 'mean_word_length': 1.85729788388497, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 85, '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': '6945377', 'n_tokens_mistral': 1896, 'n_tokens_neox': 1649, 'n_words': 302}