<commit_before># encoding: utf-8

require 'test_helper'

describe Api::StoryRepresenter do

  let(:story)       { build_stubbed(:story_with_audio, audio_versions_count: 1, id: 212) }
  let(:representer) { Api::StoryRepresenter.new(story) }
  let(:json)        { JSON.parse(representer.to_json) }

  it 'create representer' do
    representer.wont_be_nil
  end

  it 'use representer to create json' do
    json['id'].must_equal story.id
  end

  it 'does not serialize a length property' do
    json.keys.wont_include('length')
  end

  it 'serializes the length of the story as duration' do
    story.stub(:duration, 212) do
      json['duration'].must_equal 212
    end
  end

  it 'serializes the default image' do
    image = create(:story_image)
    story.stub(:default_image, image) do
      json['_links']['prx:image']['href'].must_match /#{image.id}/
    end
  end

  it 'will not serialize default image when not available' do
    story.stub(:default_image, nil) do
      json['_links'].keys.wont_include 'prx:image'
    end
  end

  it 'has a profile for the default image' do
    image = create(:story_image)
    representer.stub(:prx_model_uri, 'string') do
      story.stub(:default_image, image) do
        json['_links']['prx:image']['profile'].must_equal 'string'
      end
    end
  end

  it 'includes a content advisory' do
    sigil = 'sigil'
    story.stub(:content_advisory, sigil) do
      json['contentAdvisory'].must_equal sigil
    end
  end

  it 'includes timing and cues' do
    sigil = 'sigil'
    story.stub(:timing_and_cues, sigil) do
      json['timingAndCues'].must_equal sigil
    end
  end

  it 'includes topics and tones as tags' do
    topics = create_list(:topic, 2, story: story)
    tones = create_list(:tone, 2, story: story)
    story.stub(:tags, story.tags) do
      json['tags'].must_equal story.tags
    end
  end

  describe Api::Min::StoryRepresenter do
    let(:representer) { Api::Min::StoryRepresenter.new(story) }

    it 'serializes the length of the story as duration' do
      story.stub(:duration, 212) do
        json['duration'].must_equal 212<commit_msg>change story representer test to use hardcoded tag names<commit_after># encoding: utf-8

require 'test_helper'

describe Api::StoryRepresenter do

  let(:story)       { build_stubbed(:story_with_audio, audio_versions_count: 1, id: 212) }
  let(:representer) { Api::StoryRepresenter.new(story) }
  let(:json)        { JSON.parse(representer.to_json) }

  it 'create representer' do
    representer.wont_be_nil
  end

  it 'use representer to create json' do
    json['id'].must_equal story.id
  end

  it 'does not serialize a length property' do
    json.keys.wont_include('length')
  end

  it 'serializes the length of the story as duration' do
    story.stub(:duration, 212) do
      json['duration'].must_equal 212
    end
  end

  it 'serializes the default image' do
    image = create(:story_image)
    story.stub(:default_image, image) do
      json['_links']['prx:image']['href'].must_match /#{image.id}/
    end
  end

  it 'will not serialize default image when not available' do
    story.stub(:default_image, nil) do
      json['_links'].keys.wont_include 'prx:image'
    end
  end

  it 'has a profile for the default image' do
    image = create(:story_image)
    representer.stub(:prx_model_uri, 'string') do
      story.stub(:default_image, image) do
        json['_links']['prx:image']['profile'].must_equal 'string'
      end
    end
  end

  it 'includes a content advisory' do
    sigil = 'sigil'
    story.stub(:content_advisory, sigil) do
      json['contentAdvisory'].must_equal sigil
    end
  end

  it 'includes timing and cues' do
    sigil = 'sigil'
    story.stub(:timing_and_cues, sigil) do
      json['timingAndCues'].must_equal sigil
    end
  end

  it 'includes topics and tones as tags' do
    tags = ['Art', 'Women', 'Fresh Air-ish']
    story.stub(:tags, tags) do
      json['tags'].must_equal tags
    end
  end

  describe Api::Min::StoryRepresenter do
    let(:representer) { Api::Min::StoryRepresenter.new(story) }

    it 'serializes the length of the story as duration' do
      story.stub(:duration, 212) do
        json['duration'].must_equal 212
{'fraction_non_alphanumeric': 0.11269614835948645, 'fraction_numerical': 0.008559201141226819, 'mean_word_length': 3.373180873180873, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5317868', 'n_tokens_mistral': 1442, 'n_tokens_neox': 1374, 'n_words': 382}