Skip to content

Commit

Permalink
Added specs on path
Browse files Browse the repository at this point in the history
  • Loading branch information
gridanjbf committed Jul 2, 2024
1 parent c98ae3d commit c0d9886
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 9 deletions.
83 changes: 83 additions & 0 deletions spec/fixtures/responses/get_document_having_path.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
35 changes: 26 additions & 9 deletions spec/lib/sharepoint/client_methods_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit c0d9886

Please sign in to comment.