require 'spec_helper' module Patentscope describe WebserviceSoapBuilder, :core do before { Patentscope.configure_from_env} let(:ws_soap_builder) { WebserviceSoapBuilder.new } it "exists" do expect(ws_soap_builder).to_not be_nil end it "has the right methods" do expect(ws_soap_builder).to respond_to(:build_envelope) expect(ws_soap_builder).to respond_to(:strip_envelope) end describe "build_envelope method" do let(:envelope) { ws_soap_builder.build_envelope('foo', {bar: 'baz'}) } it "returns an XML document" do expect(envelope).to include('') end it "has an operation element" do expect(envelope).to include('') end it "has an option value element" do expect(envelope).to include('baz') end describe "specific operations" do context "get_available_documents" do it 'generates an appropriate soap envelope' do envelope = ws_soap_builder.build_envelope(:getAvailableDocuments, { iaNumber: 'SG2009000062' }) expect(envelope).to include('SG2009000062id50000000125222') end end context "get_document_ocr_content" do it 'generates an appropriate soap envelope' do envelope = ws_soap_builder.build_envelope(:getDocumentOcrContent, { docId: 'id50000000125222' }) expect(envelope).to include('id50000000125222') end end context "get_iasr" do it 'generates an appropriate soap envelope' do envelope = ws_soap_builder.build_envelope(:getIASR, { iaNumber: 'SG2009000062' }) expect(envelope).to include('SG2009000062id50000000125222') end end context "get_document_content_page" do it 'generates an appropriate soap envelope' do envelope = ws_soap_builder.build_envelope(:getDocumentContentPage, { docId: 'id50000000125222', pageId: '000031.tif' }) expect(envelope).to include('id50000000125222') expect(envelope).to include('000031.tif') end end end end describe "strip_envelope method" do context "getAvailableDocuments operation" do let(:envelope) { ' ' } let(:stripped) { ws_soap_builder.strip_envelope(envelope, :getAvailableDocuments) } it "retains the xml declaration" do expect(stripped).to include('') end it "strips the getAvailableDocumentsResponse element" do expect(stripped).to_not include('') end it "retains the inner elements" do expect(stripped).to include('') end end context "getDocumentContent operation" do let(:envelope) { ' UEsDBBQACAAIAIyMOy0AAAAAAAAAAAAAAAAKAAAAMDAwMDA...AAAAAA= ' } let(:stripped) { ws_soap_builder.strip_envelope(envelope, :getDocumentContent) } it "retains the xml declaration" do expect(stripped).to include('') end it "strips the getDocumentContentResponse element" do expect(stripped).to_not include('') end it "retains the inner elements" do expect(stripped).to include('UEsDBBQACAAIAIyMOy0AAAAAAAAAAAAAAAAKAAAAMDAwMDA...AAAAAA=') end end context "getDocumentOcrContent operation" do let(:envelope) { ' JVBERi0xLjQKJeLjz9MKOCAwIG9iago8P...DUKJSVFT0YK ' } let(:stripped) { ws_soap_builder.strip_envelope(envelope, :getDocumentOcrContent) } it "retains the xml declaration" do expect(stripped).to include('') end it "strips the getDocumentOcrContentResponse element" do expect(stripped).to_not include('') end it "retains the inner elements" do expect(stripped).to include('JVBERi0xLjQKJeLjz9MKOCAwIG9iago8P...DUKJSVFT0YK') end end context "getIASR operation" do let(:envelope) { ' baz ' } let(:stripped) { ws_soap_builder.strip_envelope(envelope, :getIASR) } it "retains the xml declaration" do expect(stripped).to include('') end it "strips the getIASRResponse element" do expect(stripped).to_not include('') end it "retains the inner elements" do expect(stripped).to include('baz') end end context "getDocumentTableOfContents operation" do let(:envelope) { ' 000001.tif ' } let(:stripped) { ws_soap_builder.strip_envelope(envelope, :getDocumentTableOfContents) } it "retains the xml declaration" do expect(stripped).to include('') end it "strips the getDocumentTableOfContentsResponse element" do expect(stripped).to_not include('') end it "retains the inner elements" do expect(stripped).to include('000001.tif') end end context "getDocumentContentPage operation" do let(:envelope) { ' SUkqAAgAAAASAP4ABAABAAAAAAAAAAABAwABAAAAqwk...//wAQAQAQAQ== ' } let(:stripped) { ws_soap_builder.strip_envelope(envelope, :getDocumentContentPage) } it "retains the xml declaration" do expect(stripped).to include('') end it "strips the getDocumentContentPageResponse element" do expect(stripped).to_not include('') end it "retains the inner elements" do expect(stripped).to include('SUkqAAgAAAASAP4ABAABAAAAAAAAAAABAwABAAAAqwk...//wAQAQAQAQ==') end end end end end