|
253 | 253 | expect(upload[:status_code]).to eq(200)
|
254 | 254 |
|
255 | 255 | end
|
| 256 | + |
| 257 | + it "test_upload_with_checks" do |
| 258 | + request_obj = double |
| 259 | + allow(ImageKitIo::Request) |
| 260 | + .to receive(:new) |
| 261 | + .with(private_key, public_key, url_endpoint) |
| 262 | + .and_return(request_obj) |
| 263 | + |
| 264 | + allow(request_obj) |
| 265 | + .to receive(:create_headers) |
| 266 | + .and_return({}) |
| 267 | + @ac={} |
| 268 | + allow(request_obj) |
| 269 | + .to receive(:request){|method,url,headers,payload| @ac={method: method, url: url, headers: headers, payload:payload}} |
| 270 | + .and_return({status_code: 200}) |
| 271 | + |
| 272 | + SUT = file_api_service.new(request_obj) |
| 273 | + |
| 274 | + upload = SUT.upload(file: "./fake_file.jpg", file_name: "my_file_name", checks: '"file.size" < "1mb"') |
| 275 | + |
| 276 | + expect(@ac[:payload]['checks']).to eq('"file.size" < "1mb"') |
| 277 | + |
| 278 | + expect(upload[:status_code]).to eq(200) |
| 279 | + |
| 280 | + end |
| 281 | + |
| 282 | + it "test_upload_with_is_published" do |
| 283 | + request_obj = double |
| 284 | + allow(ImageKitIo::Request) |
| 285 | + .to receive(:new) |
| 286 | + .with(private_key, public_key, url_endpoint) |
| 287 | + .and_return(request_obj) |
| 288 | + |
| 289 | + allow(request_obj) |
| 290 | + .to receive(:create_headers) |
| 291 | + .and_return({}) |
| 292 | + @ac={} |
| 293 | + allow(request_obj) |
| 294 | + .to receive(:request){|method,url,headers,payload| @ac={method: method, url: url, headers: headers, payload:payload}} |
| 295 | + .and_return({status_code: 200}) |
| 296 | + |
| 297 | + SUT = file_api_service.new(request_obj) |
| 298 | + |
| 299 | + upload = SUT.upload(file: "./fake_file.jpg", file_name: "my_file_name", is_published: true ) |
| 300 | + |
| 301 | + expect(@ac[:payload]['isPublished']).to eq("true") |
| 302 | + |
| 303 | + expect(upload[:status_code]).to eq(200) |
| 304 | + |
| 305 | + end |
| 306 | + |
256 | 307 | end
|
257 | 308 |
|
258 | 309 | describe 'FileListTest' do
|
|
787 | 838 | expect(resp[:body]).to eq(options)
|
788 | 839 | end
|
789 | 840 |
|
| 841 | + it "test_update_file_publication_status" do |
| 842 | + options = { publish: { isPublished: true, includeFileVersions: true }} |
| 843 | + request_obj = double |
| 844 | + allow(ImageKitIo::Request) |
| 845 | + .to receive(:new) |
| 846 | + .with(private_key, public_key, url_endpoint) |
| 847 | + .and_return(request_obj) |
| 848 | + |
| 849 | + allow(request_obj) |
| 850 | + .to receive(:create_headers) |
| 851 | + .and_return({}) |
| 852 | + |
| 853 | + allow(request_obj) |
| 854 | + .to receive(:request){|method,url,headers,payload| @ac={method: method, url: url, headers: headers, payload:payload}} |
| 855 | + .and_return({status_code: 200, body: options}) |
| 856 | + |
| 857 | + SUT = file_api_service.new(request_obj) |
| 858 | + resp = SUT.update_details(file_id: "file_id", **options) |
| 859 | + |
| 860 | + expect(JSON.parse(@ac[:payload])['publish']['isPublished']).to eq(options[:publish][:isPublished]) |
| 861 | + expect(JSON.parse(@ac[:payload])['publish']['isPublished']).to eq(options[:publish][:includeFileVersions]) |
| 862 | + expect(resp[:status_code]).to eq(200) |
| 863 | + expect(resp[:body]).to eq(options) |
| 864 | + end |
| 865 | + |
790 | 866 | it "test_update_file_details_fails_missing_arguments" do
|
791 | 867 | options = { tags: 'custom tag' }
|
792 | 868 | request_obj = double
|
|
0 commit comments