<commit_before>require 'spec_helper'

describe Signifyd::Case do
  let(:hash) { SignifydRequests.valid_case }
  let(:json) { JSON.dump(hash) }
  let(:case_id) { (rand * 1000).ceil }
  let(:investigation) { "{\"investigationId\":#{case_id}}" }
  
  context '.create' do    
    context 'when creating a case with a valid API key' do
      context 'and passing the correct parameters' do
        before {
          Signifyd.api_key = SIGNIFYD_API_KEY
          
          stub_request(:post, "https://#{Signifyd.api_key}@api.signifyd.com/v1/cases").
            with(:body => json, :headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'Content-Length'=>json.size, 'Content-Type'=>'application/json', 'User-Agent'=>'Signifyd Ruby v1'}).
            to_return(:status => 201, :body => investigation, :headers => {})
        }

        after {
          Signifyd.api_key = nil
        }
        
        subject {
          Signifyd::Case.create(hash)
        }
        
        it { should be_true }
        it { should_not be_nil }
        it { expect(subject[:code]).to eq(201) }
        it { expect(subject[:body][:investigationId]).to eq(JSON.parse(investigation)[:investigationId]) }
      end

      context 'and passing incorrect or nil parameters' do
        before {
          Signifyd.api_key = SIGNIFYD_API_KEY
        }

        after {
          Signifyd.api_key = nil
        }

        it { lambda { Signifyd::Case.create() }.should raise_error }
      end
    end
    
    context 'when creating a case with an invalid API key' do
      it { lambda { Signifyd::Case.create(hash) }.should raise_error }
    end
  end
  
  context '.update' do    
    context 'when updating a case' do
      context 'and the proper case_id and parameters have been sent' do
        before {
          Signifyd.api_key = SIGNIFYD_API_KEY
          
          stub_request(:put, "https://#{Signifyd.api_key}@api.signifyd.com/v1/cases/#{case_id}").
            with(:body => json, :headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'Content-Length'=>json.size, 'Content-Type'=>'application/json', 'User-Agent'=>'Signifyd Ruby v1'}).
            to_return(:status => 201, :body => investigation, :headers => {})
        }

        after {
          Signifyd.api_key = nil
        }
        
        subject {
          Signifyd::Case.update(case_id, hash)
        }
        
        it { should be_true }
        it { should_not be_nil }
        it { expect(subject[:code]).to eq(201) }
        it { expect(subject[:body][:investigationId]).to eq(JSON.parse(investigation)[:investigationId]) }
      end
      
      context 'and incorrect parameters have been passed' do
        before {
          Signifyd.api_key = SIGNIFYD_API_KEY
        }
        
        after {
          Signifyd.api_key = nil
        }
        
        it { lambda { Signifyd::Case.update(case_id, {}) }.should raise_error }
      end
    end
  end
end<commit_msg>Updated the case spec for the response code being 200<commit_after>require 'spec_helper'

describe Signifyd::Case do
  let(:hash) { SignifydRequests.valid_case }
  let(:json) { JSON.dump(hash) }
  let(:case_id) { (rand * 1000).ceil }
  let(:investigation) { "{\"investigationId\":#{case_id}}" }
  
  context '.create' do    
    context 'when creating a case with a valid API key' do
      context 'and passing the correct parameters' do
        before {
          Signifyd.api_key = SIGNIFYD_API_KEY
          
          stub_request(:post, "https://#{Signifyd.api_key}@api.signifyd.com/v1/cases").
            with(:body => json, :headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'Content-Length'=>json.size, 'Content-Type'=>'application/json', 'User-Agent'=>'Signifyd Ruby v1'}).
            to_return(:status => 201, :body => investigation, :headers => {})
        }

        after {
          Signifyd.api_key = nil
        }
        
        subject {
          Signifyd::Case.create(hash)
        }
        
        it { should be_true }
        it { should_not be_nil }
        it { expect(subject[:code]).to eq(201) }
        it { expect(subject[:body][:investigationId]).to eq(JSON.parse(investigation)[:investigationId]) }
      end

      context 'and passing incorrect or nil parameters' do
        before {
          Signifyd.api_key = SIGNIFYD_API_KEY
        }

        after {
          Signifyd.api_key = nil
        }

        it { lambda { Signifyd::Case.create() }.should raise_error }
      end
    end
    
    context 'when creating a case with an invalid API key' do
      it { lambda { Signifyd::Case.create(hash) }.should raise_error }
    end
  end
  
  context '.update' do    
    context 'when updating a case' do
      context 'and the proper case_id and parameters have been sent' do
        before {
          Signifyd.api_key = SIGNIFYD_API_KEY
          
          stub_request(:put, "https://#{Signifyd.api_key}@api.signifyd.com/v1/cases/#{case_id}").
            with(:body => json, :headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'Content-Length'=>json.size, 'Content-Type'=>'application/json', 'User-Agent'=>'Signifyd Ruby v1'}).
            to_return(:status => 200, :body => investigation, :headers => {})
        }

        after {
          Signifyd.api_key = nil
        }
        
        subject {
          Signifyd::Case.update(case_id, hash)
        }
        
        it { should be_true }
        it { should_not be_nil }
        it { expect(subject[:code]).to eq(200) }
        it { expect(subject[:body][:investigationId]).to eq(JSON.parse(investigation)[:investigationId]) }
      end
      
      context 'and incorrect parameters have been passed' do
        before {
          Signifyd.api_key = SIGNIFYD_API_KEY
        }
        
        after {
          Signifyd.api_key = nil
        }
        
        it { lambda { Signifyd::Case.update(case_id, {}) }.should raise_error }
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.13313511727783284, 'fraction_numerical': 0.00842418235877106, 'mean_word_length': 2.170157068062827, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 43, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '6176833', 'n_tokens_mistral': 1905, 'n_tokens_neox': 1879, 'n_words': 408}