<commit_before>require_relative '../spec_helper'
require 'webmock/rspec'
require 'json'
require 'securerandom'
require 'pp'
require 'rspec/its'

RSpec.describe SonataVnfRepository do
  describe 'GET \'/\'' do
    before do
      stub_request(:get, 'localhost:5000').to_return(status: 200, body: '---\n- uri: \"/\"\n  method: GET\n  purpose: REST API Structure and Capability Discovery\n- uri: \"/records/nsr/\"\n  method: GET\n  purpose: REST API Structure and Capability Discovery nsr\n- uri: \"/records/vnfr/\"\n  method: GET\n  purpose: REST API Structure and Capability Discovery vnfr\n- uri: \"/catalogues/\"\n  method: GET\n  purpose: REST API Structure and Capability Discovery catalogues\n')
      get '/'
    end
    subject { last_response }
    its(:status) { is_expected.to eq 200 }
  end

  let(:vnf_instance_record) {Rack::Test::UploadedFile.new('./spec/fixtures/vnfr-example.json','application/json', true)}
  describe 'POST \'/vnf-instances\'' do
    context 'with correct parameters' do
      it 'Submit an vnfr' do
        headers = { 'CONTENT_TYPE' => 'application/json' }
        post '/vnf-instances', vnf_instance_record, headers
        expect(last_response).to be_ok
      end
    end
  end

  let(:vnf_instance_record) {Rack::Test::UploadedFile.new('./spec/fixtures/vnfr-example.json','application/json', true)}
  describe 'POST \'/vnf-instances\'' do
    context 'Duplicated vnfr' do
      it 'Submit a duplicated vnfr' do
        headers = { 'CONTENT_TYPE' => 'application/json' }
        post '/vnf-instances', vnf_instance_record, headers
        expect(last_response.status).to eq(409)
      end
    end
  end

  let(:vnf_instance_bad_record) {Rack::Test::UploadedFile.new('./spec/fixtures/vnfr-example-with-errors.json','application/json', true)}
  describe 'POST \'/vnf-instances-bad\'' do
    context 'with incorrect parameters' do
      it 'Submit an invalid vnfr' do
        headers = { 'CONTENT_TYPE' => 'application/json' }
        post '/vnf-instances', vnf_instance_bad_record, headers
        expect(last_response.status).to eq(422)
      end
    end
  end

  describe 'GET /vnf-instances' do
    context 'without (UU)ID given' do
      before do
        get '/vnf-instances'
      end
      subject { last_response }
      its(:status) { is_expected.to eq 200 }
    end
  end

  describe 'GET /vnf-instances/:uuid' do
    context 'with (UU)ID given' do
      before do
        get '/vnf-instances/0f168346-77a5-d93d-4e83-cce571f7a96d'
      end
      subject { last_response }
      its(:status) { is_expected.to eq 200 }
    end
  end

  describe 'DELETE /vnf-instances/:uuid' do
    context 'with (UU)ID given' do
      before do
        delete '/vnf-instances/0f168346-77a5-d93d-4e83-cce571f7a96d'
      end
      subject { last_response }
      its(:status) { is_expected.to eq 200 }
    end
  end
end<commit_msg>Adding Unit Test VNF Repo<commit_after>require_relative '../spec_helper'
require 'webmock/rspec'
require 'json'
require 'securerandom'
require 'pp'
require 'rspec/its'

RSpec.describe SonataVnfRepository do
  describe 'GET \'/\'' do
    before do
      stub_request(:get, 'localhost:5000').to_return(status: 200, body: '---\n- uri: \"/\"\n  method: GET\n  purpose: REST API Structure and Capability Discovery\n- uri: \"/records/nsr/\"\n  method: GET\n  purpose: REST API Structure and Capability Discovery nsr\n- uri: \"/records/vnfr/\"\n  method: GET\n  purpose: REST API Structure and Capability Discovery vnfr\n- uri: \"/catalogues/\"\n  method: GET\n  purpose: REST API Structure and Capability Discovery catalogues\n')
      get '/'
    end
    subject { last_response }
    its(:status) { is_expected.to eq 200 }
  end

  let(:vnf_instance_record) {Rack::Test::UploadedFile.new('./spec/fixtures/vnfr-example.json','application/json', true)}
  describe 'POST \'/vnf-instances\'' do
    context 'with correct parameters' do
      it 'Submit an vnfr' do
        headers = { 'CONTENT_TYPE' => 'application/json' }
        post '/vnf-instances', vnf_instance_record, headers
        expect(last_response).to be_ok
      end
    end
  end

  let(:vnf_instance_record) {Rack::Test::UploadedFile.new('./spec/fixtures/vnfr-example.json','application/json', true)}
  describe 'POST \'/vnf-instances\'' do
    context 'Duplicated vnfr' do
      it 'Submit a duplicated vnfr' do
        headers = { 'CONTENT_TYPE' => 'application/json' }
        post '/vnf-instances', vnf_instance_record, headers
        expect(last_response.status).to eq(409)
      end
    end
  end

  let(:vnf_instance_bad_record) {Rack::Test::UploadedFile.new('./spec/fixtures/vnfr-example-with-errors.json','application/json', true)}
  describe 'POST \'/vnf-instances-bad\'' do
    context 'with incorrect parameters' do
      it 'Submit an invalid vnfr' do
        headers = { 'CONTENT_TYPE' => 'application/json' }
        post '/vnf-instances', vnf_instance_bad_record, headers
        expect(last_response.status).to eq(422)
      end
    end
  end

  describe 'GET /vnf-instances' do
    context 'without (UU)ID given' do
      before do
        get '/vnf-instances'
      end
      subject { last_response }
      its(:status) { is_expected.to eq 200 }
    end
  end

  describe 'GET /vnf-instances/:uuid' do
    context 'with (UU)ID given' do
      before do
        get '/vnf-instances/62b21f06-154e-0893-3e95-0123c541a54f'
      end
      subject { last_response }
      its(:status) { is_expected.to eq 200 }
    end
  end

  describe 'DELETE /vnf-instances/:uuid' do
    context 'with (UU)ID given' do
      before do
        delete '/vnf-instances/62b21f06-154e-0893-3e95-0123c541a54f'
      end
      subject { last_response }
      its(:status) { is_expected.to eq 200 }
    end
  end
end
{'fraction_non_alphanumeric': 0.12639664804469275, 'fraction_numerical': 0.02479050279329609, 'mean_word_length': 2.9483115093039283, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '5183396', 'n_tokens_mistral': 2060, 'n_tokens_neox': 1906, 'n_words': 475}