<commit_before>require 'singleplatform'
require 'webmock/rspec'

describe 'Singleplatform::Client::Locations' do

  before do
    @creds = {
      client_id:     'purplespacesuitfrogboots1',
      client_secret: 'yellowsubmarinesresonatewithmeandmybestbros'
    }
    @client = Singleplatform::Client.new(@creds)
    @location = File.open(Dir.pwd + '/spec/support/fixtures/location.json').read
    @updated_since = File.open(Dir.pwd + '/spec/support/fixtures/updated_since.json').read
    @menus = File.open(Dir.pwd + '/spec/support/fixtures/menus.json').read
  end

  describe ".location" do
    context "when given a valid location id" do
      it "returns data for that location" do
        stub_request(:get, /publishing-api.singleplatform.com/).
          with(headers: {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
          to_return(status: 200, body: @location)
        response = @client.location('island-prime')
        expect(response).to be_a(Singleplatform::Response)
        expect(response.body.location_id).to eql('island-prime')
      end
    end

    context "when missing a location id" do
      it "raises an ArgumentError" do
        expect { @client.location }.to raise_error(ArgumentError)
      end
    end

    context "when including too many params" do
      it "raises an ArgumentError" do
        expect { @client.location('island-prime', 'another-argument') }.to raise_error(ArgumentError)
      end
    end
  end

  describe ".locations_updated_since" do
    context "when given a valid date" do
      it "returns locations updated since that date" do
        stub_request(:get, /publishing-api.singleplatform.com/).
          with(headers: {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
          to_return(status: 200, body: @updated_since)
        response = @client.locations_updated_since('2012-01-01', limit: 3)
        expect(response).to be_a(Singleplatform::Response)
        expect(response.body.results.size).to eql(3)
      end
    end

    context "when missing a date" do
      it "raises an ArgumentError" do 
        expect { @client.locations_updated_since }.to raise_error(ArgumentError
          )
      end
    end
  end

  describe ".menus_for" do
    context "when given a valid location id" do
      it "returns menu data for that location" do
        stub_request(:get, /publishing-api.singleplatform.com/).
          with(headers: {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
          to_return(status: 200, body: @menus)
        response = @client.menus_for('island-prime')
        expect(response).to be_a(Singleplatform::Response)
        expect(response.body.size).to eql(2)
      end
    end<commit_msg>Add more test coverage for Locations methods<commit_after>require 'singleplatform'
require 'webmock/rspec'

describe 'Singleplatform::Client::Locations' do

  before do
    @creds = {
      client_id:     'purplespacesuitfrogboots1',
      client_secret: 'yellowsubmarinesresonatewithmeandmybestbros'
    }
    @client = Singleplatform::Client.new(@creds)
    @location = File.open(Dir.pwd + '/spec/support/fixtures/location.json').read
    @updated_since = File.open(Dir.pwd + '/spec/support/fixtures/updated_since.json').read
    @menus = File.open(Dir.pwd + '/spec/support/fixtures/menus.json').read
    @photos = File.open(Dir.pwd + '/spec/support/fixtures/photos.json').read
  end

  describe ".location" do
    context "when given a valid location id" do
      it "returns data for that location" do
        stub_request(:get, /publishing-api.singleplatform.com/).
          with(headers: {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
          to_return(status: 200, body: @location)
        response = @client.location('island-prime')
        expect(response).to be_a(Singleplatform::Response)
        expect(response.body.location_id).to eql('island-prime')
      end
    end

    context "when missing a location id" do
      it "raises an ArgumentError" do
        expect { @client.location }.to raise_error(ArgumentError)
      end
    end

    context "when including too many params" do
      it "raises an ArgumentError" do
        expect { @client.location('island-prime', 'another-argument') }.to raise_error(ArgumentError)
      end
    end
  end

  describe ".locations_updated_since" do
    context "when given a valid date" do
      it "returns locations updated since that date" do
        stub_request(:get, /publishing-api.singleplatform.com/).
          with(headers: {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
          to_return(status: 200, body: @updated_since)
        response = @client.locations_updated_since('2012-01-01', limit: 3)
        expect(response).to be_a(Singleplatform::Response)
        expect(response.body.results.size).to eql(3)
      end
    end

    context "when missing a date" do
      it "raises an ArgumentError" do 
        expect { @client.locations_updated_since }.to raise_error(ArgumentError
          )
      end
    end
  end

  describe ".menus_for" do
    context "when given a valid location id" do
      it "returns menu data for that location" do
        stub_request(:get, /publishing-api.singleplatform.com/).
          with(headers: {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
          to_return(status: 200, body: @menus)
        response = @client.menus_for('island-prime')
        expect(response).to be_a(Singleplatform::Response)
        expect(response.body.size).to eql(2)
      end
    end

    context "when missing a location id" do
      it "raises an ArgumentError" do
        expect { @client.menus_for }.to raise_error(ArgumentError) 
      end
    end
  end

  describe ".photos_for" do
    context "when given a valid location id" do
      it "returns photos for that location" do
        stub_request(:get, /publishing-api.singleplatform.com/).
          with(headers: {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
          to_return(status: 200, body: @photos)
          response = @client.photos_for('island-prime')
          expect(response).to be_a(Singleplatform::Response)
          expect(response.body.first.title).to eql('Key Lime Pie')
      end
    end
{'fraction_non_alphanumeric': 0.12450787401574803, 'fraction_numerical': 0.0073818897637795275, 'mean_word_length': 2.9539559014267187, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '1205607', 'n_tokens_mistral': 1905, 'n_tokens_neox': 1836, 'n_words': 444}