|
19 | 19 | end |
20 | 20 | end |
21 | 21 |
|
22 | | - describe '#request_signature' do |
| 22 | + describe 'working with a document' do |
23 | 23 | let!(:document) { Mifiel::Document.all.first } |
24 | | - let!(:error_body) { { errors: ['some error'] }.to_json } |
25 | 24 |
|
26 | | - it '' do |
27 | | - expect do |
28 | | - document.request_signature('some@email.com') |
29 | | - end.not_to raise_error |
30 | | - end |
| 25 | + describe '#save_file' do |
| 26 | + let!(:path) {'tmp/the-file.pdf' } |
| 27 | + before { File.unlink(path) if File.exist?(path)} |
31 | 28 |
|
32 | | - context 'when bad request' do |
33 | | - before do |
34 | | - url = %r{mifiel.com\/api\/v1\/documents\/#{document.id}\/request_signature} |
35 | | - stub_request(:post, url).to_return(body: error_body, status: 404) |
| 29 | + it 'should get the file' do |
| 30 | + document.save_file(path) |
| 31 | + expect(File.exist?(path)).to be true |
36 | 32 | end |
| 33 | + end |
37 | 34 |
|
38 | | - it '' do |
39 | | - expect do |
40 | | - document.request_signature('some@email.com') |
41 | | - end.to raise_error(Mifiel::BadRequestError) |
| 35 | + describe '#save_file_signed' do |
| 36 | + let!(:path) {'tmp/the-file-signed.pdf' } |
| 37 | + before { File.unlink(path) if File.exist?(path)} |
| 38 | + |
| 39 | + it 'should get the file' do |
| 40 | + document.save_file_signed(path) |
| 41 | + expect(File.exist?(path)).to be true |
42 | 42 | end |
43 | 43 | end |
44 | 44 |
|
45 | | - context 'when server error' do |
46 | | - before do |
47 | | - url = %r{mifiel.com\/api\/v1\/documents\/#{document.id}\/request_signature} |
48 | | - stub_request(:post, url).to_return(body: error_body, status: 500) |
| 45 | + describe '#save_xml' do |
| 46 | + let!(:path) {'tmp/the-xml.xml' } |
| 47 | + before { File.unlink(path) if File.exist?(path)} |
| 48 | + |
| 49 | + it 'should get the file' do |
| 50 | + document.save_xml(path) |
| 51 | + expect(File.exist?(path)).to be true |
49 | 52 | end |
| 53 | + end |
| 54 | + |
| 55 | + describe '#request_signature' do |
| 56 | + let!(:error_body) { { errors: ['some error'] }.to_json } |
50 | 57 |
|
51 | 58 | it '' do |
52 | 59 | expect do |
53 | 60 | document.request_signature('some@email.com') |
54 | | - end.to raise_error(Mifiel::ServerError) |
| 61 | + end.not_to raise_error |
| 62 | + end |
| 63 | + |
| 64 | + context 'when bad request' do |
| 65 | + before do |
| 66 | + url = %r{mifiel.com\/api\/v1\/documents\/#{document.id}\/request_signature} |
| 67 | + stub_request(:post, url).to_return(body: error_body, status: 404) |
| 68 | + end |
| 69 | + |
| 70 | + it '' do |
| 71 | + expect do |
| 72 | + document.request_signature('some@email.com') |
| 73 | + end.to raise_error(Mifiel::BadRequestError) |
| 74 | + end |
| 75 | + end |
| 76 | + |
| 77 | + context 'when server error' do |
| 78 | + before do |
| 79 | + url = %r{mifiel.com\/api\/v1\/documents\/#{document.id}\/request_signature} |
| 80 | + stub_request(:post, url).to_return(body: error_body, status: 500) |
| 81 | + end |
| 82 | + |
| 83 | + it '' do |
| 84 | + expect do |
| 85 | + document.request_signature('some@email.com') |
| 86 | + end.to raise_error(Mifiel::ServerError) |
| 87 | + end |
55 | 88 | end |
56 | 89 | end |
57 | 90 | end |
|
0 commit comments