From c0d988683864b0819a090fc8b9d47c8d7f745a63 Mon Sep 17 00:00:00 2001 From: Danilo Grieco Date: Tue, 2 Jul 2024 19:34:44 +0200 Subject: [PATCH] Added specs on path --- .../responses/get_document_having_path.json | 83 +++++++++++++++++++ spec/lib/sharepoint/client_methods_spec.rb | 35 ++++++-- 2 files changed, 109 insertions(+), 9 deletions(-) create mode 100644 spec/fixtures/responses/get_document_having_path.json diff --git a/spec/fixtures/responses/get_document_having_path.json b/spec/fixtures/responses/get_document_having_path.json new file mode 100644 index 0000000..115fe65 --- /dev/null +++ b/spec/fixtures/responses/get_document_having_path.json @@ -0,0 +1,83 @@ +{ + "d": { + "__metadata": { + "id": "Web/Lists(guid'3314c0cf-d5b0-4d1e-a5f1-9a10fca08bc3')/Items(6)", + "uri": "http://win-jamsdpuujgc/_api/Web/Lists(guid'3314c0cf-d5b0-4d1e-a5f1-9a10fca08bc3')/Items(6)", + "etag": "\"4\"", + "type": "SP.Data.DocumentsItem" + }, + "FirstUniqueAncestorSecurableObject": { + "__deferred": { + "uri": "http://win-jamsdpuujgc/_api/Web/Lists(guid'3314c0cf-d5b0-4d1e-a5f1-9a10fca08bc3')/Items(6)/FirstUniqueAncestorSecurableObject" + } + }, + "RoleAssignments": { + "__deferred": { + "uri": "http://win-jamsdpuujgc/_api/Web/Lists(guid'3314c0cf-d5b0-4d1e-a5f1-9a10fca08bc3')/Items(6)/RoleAssignments" + } + }, + "AttachmentFiles": { + "__deferred": { + "uri": "http://win-jamsdpuujgc/_api/Web/Lists(guid'3314c0cf-d5b0-4d1e-a5f1-9a10fca08bc3')/Items(6)/AttachmentFiles" + } + }, + "ContentType": { + "__deferred": { + "uri": "http://win-jamsdpuujgc/_api/Web/Lists(guid'3314c0cf-d5b0-4d1e-a5f1-9a10fca08bc3')/Items(6)/ContentType" + } + }, + "FieldValuesAsHtml": { + "__deferred": { + "uri": "http://win-jamsdpuujgc/_api/Web/Lists(guid'3314c0cf-d5b0-4d1e-a5f1-9a10fca08bc3')/Items(6)/FieldValuesAsHtml" + } + }, + "FieldValuesAsText": { + "__deferred": { + "uri": "http://win-jamsdpuujgc/_api/Web/Lists(guid'3314c0cf-d5b0-4d1e-a5f1-9a10fca08bc3')/Items(6)/FieldValuesAsText" + } + }, + "FieldValuesForEdit": { + "__deferred": { + "uri": "http://win-jamsdpuujgc/_api/Web/Lists(guid'3314c0cf-d5b0-4d1e-a5f1-9a10fca08bc3')/Items(6)/FieldValuesForEdit" + } + }, + "File": { + "__deferred": { + "uri": "http://win-jamsdpuujgc/_api/Web/Lists(guid'3314c0cf-d5b0-4d1e-a5f1-9a10fca08bc3')/Items(6)/File" + } + }, + "Folder": { + "__deferred": { + "uri": "http://win-jamsdpuujgc/_api/Web/Lists(guid'3314c0cf-d5b0-4d1e-a5f1-9a10fca08bc3')/Items(6)/Folder" + } + }, + "ParentList": { + "__deferred": { + "uri": "http://win-jamsdpuujgc/_api/Web/Lists(guid'3314c0cf-d5b0-4d1e-a5f1-9a10fca08bc3')/Items(6)/ParentList" + } + }, + "FileSystemObjectType": 0, + "Id": 6, + "ContentTypeId": "0x0101002E97C997BC5CAC4785AA3F57D34080E3", + "Title": "Bari-Rome boarding-pass", + "OData__dlc_DocId": "QHWH36P2KKT2-1-6", + "OData__dlc_DocIdUrl": { + "__metadata": { + "type": "SP.FieldUrlValue" + }, + "Description": "QHWH36P2KKT2-1-6", + "Path": "http://win-jamsdpuujgc/_layouts/15/DocIdRedir.aspx?ID=QHWH36P2KKT2-1-6" + }, + "URL": null, + "DocumentSetDescription": null, + "EditorId": 1, + "ID": 6, + "Created": "2016-07-17T08:26:35", + "AuthorId": 1, + "Modified": "2016-07-25T05:45:18", + "OData__CopySource": null, + "CheckoutUserId": null, + "OData__UIVersionString": "0.2", + "GUID": "e35ac090-3f54-46aa-8ffd-fb14a0aa1610" + } +} diff --git a/spec/lib/sharepoint/client_methods_spec.rb b/spec/lib/sharepoint/client_methods_spec.rb index 451b156..14a7200 100644 --- a/spec/lib/sharepoint/client_methods_spec.rb +++ b/spec/lib/sharepoint/client_methods_spec.rb @@ -282,20 +282,37 @@ describe '#download' do subject(:download) { client.download file_path: file_path } - let(:document_json) { File.read('spec/fixtures/responses/get_document.json') } - let(:document_meta) { client.send :parse_get_document_response, document_json, [] } let(:file_path) { '/Documents/document.docx' } let(:expected_content) { File.read('spec/fixtures/responses/document.docx') } + let(:document_meta) { client.send :parse_get_document_response, document_json, [] } - before do - allow(client).to receive(:get_document).and_return(document_meta) - mock_responses('document.docx') + context "when meta contains URL" do + let(:document_json) { File.read('spec/fixtures/responses/get_document.json') } + + before do + allow(client).to receive(:get_document).and_return(document_meta) + mock_responses('document.docx') + end + + it 'returns expected hash' do + expect(download).to have_key :file_contents + expect(download).to have_key :link_url + expect(download[:file_contents]).to eq expected_content + end end - it 'returns expected hash' do - expect(download).to have_key :file_contents - expect(download).to have_key :link_url - expect(download[:file_contents]).to eq expected_content + context "when meta contains Path" do + let(:document_json) { File.read('spec/fixtures/responses/get_document_having_path.json') } + before do + allow(client).to receive(:get_document).and_return(document_meta) + mock_responses('document.docx') + end + + it 'returns expected hash' do + expect(download).to have_key :file_contents + expect(download).to have_key :link_url + expect(download[:file_contents]).to eq expected_content + end end end