|
107 | 107 |
|
108 | 108 | end |
109 | 109 |
|
| 110 | + it "test_upload_with_valid_expected_success_with_extensions" do |
| 111 | + request_obj = double |
| 112 | + allow(ImageKitIo::Request) |
| 113 | + .to receive(:new) |
| 114 | + .with(private_key, public_key, url_endpoint) |
| 115 | + .and_return(request_obj) |
| 116 | + |
| 117 | + allow(request_obj) |
| 118 | + .to receive(:create_headers) |
| 119 | + .and_return({}) |
| 120 | + @ac={} |
| 121 | + allow(request_obj) |
| 122 | + .to receive(:request){|method,url,headers,payload| @ac={method: method, url: url, headers: headers, payload:payload}} |
| 123 | + .and_return({code: 200}) |
| 124 | + SUT = file_api_service.new(request_obj) |
| 125 | + upload = SUT.upload(file: "./fake_file.jpg", file_name: "my_file_name", extensions: [ |
| 126 | + { |
| 127 | + name: 'remove-bg', |
| 128 | + options: { |
| 129 | + add_shadow: true |
| 130 | + } |
| 131 | + } |
| 132 | + ]) |
| 133 | + expect(@ac[:payload]['extensions']).to eq("[{\"name\":\"remove-bg\",\"options\":{\"add_shadow\":true}}]") |
| 134 | + expect(upload[:code]).to eq(200) |
| 135 | + end |
| 136 | + |
| 137 | + it "test_upload_with_valid_expected_success_with_customMetadata" do |
| 138 | + request_obj = double |
| 139 | + allow(ImageKitIo::Request) |
| 140 | + .to receive(:new) |
| 141 | + .with(private_key, public_key, url_endpoint) |
| 142 | + .and_return(request_obj) |
| 143 | + |
| 144 | + allow(request_obj) |
| 145 | + .to receive(:create_headers) |
| 146 | + .and_return({}) |
| 147 | + @ac={} |
| 148 | + allow(request_obj) |
| 149 | + .to receive(:request){|method,url,headers,payload| @ac={method: method, url: url, headers: headers, payload:payload}} |
| 150 | + .and_return({code: 200}) |
| 151 | + SUT = file_api_service.new(request_obj) |
| 152 | + upload = SUT.upload( |
| 153 | + file: "./fake_file.jpg", |
| 154 | + file_name: "my_file_name", |
| 155 | + custom_metadata: { |
| 156 | + brand: 'Nike', |
| 157 | + color: 'red' |
| 158 | + } |
| 159 | + ) |
| 160 | + expect(@ac[:payload]['customMetadata']).to eq("{\"brand\":\"Nike\",\"color\":\"red\"}") |
| 161 | + expect(upload[:code]).to eq(200) |
| 162 | + end |
| 163 | + |
110 | 164 | it "test_upload_with_valid_expected_success" do |
111 | 165 | request_obj = double |
112 | 166 | allow(ImageKitIo::Request) |
|
597 | 651 | SUT.update_details(file_id: "file_id", **options) |
598 | 652 | }.to raise_error(ArgumentError) |
599 | 653 | end |
| 654 | + |
| 655 | + it "test_update_file_details_expected_success_with_extensions" do |
| 656 | + request_obj = double |
| 657 | + allow(ImageKitIo::Request) |
| 658 | + .to receive(:new) |
| 659 | + .with(private_key, public_key, url_endpoint) |
| 660 | + .and_return(request_obj) |
| 661 | + |
| 662 | + allow(request_obj) |
| 663 | + .to receive(:create_headers) |
| 664 | + .and_return({}) |
| 665 | + @ac={} |
| 666 | + allow(request_obj) |
| 667 | + .to receive(:request){|method,url,headers,payload| @ac={method: method, url: url, headers: headers, payload:payload}} |
| 668 | + .and_return({code: 200}) |
| 669 | + SUT = file_api_service.new(request_obj) |
| 670 | + upload = SUT.update_details(file_id: "file_id_xyz", extensions: [ |
| 671 | + { |
| 672 | + 'name': 'google-auto-tagging', |
| 673 | + 'maxTags': 5, |
| 674 | + 'minConfidence': 95 |
| 675 | + } |
| 676 | + ]) |
| 677 | + expect(@ac[:payload]).to eq("{\"extensions\":[{\"name\":\"google-auto-tagging\",\"maxTags\":5,\"minConfidence\":95}]}") |
| 678 | + expect(upload[:code]).to eq(200) |
| 679 | + end |
| 680 | + |
| 681 | + it "test_update_with_valid_expected_success_with_customMetadata" do |
| 682 | + request_obj = double |
| 683 | + allow(ImageKitIo::Request) |
| 684 | + .to receive(:new) |
| 685 | + .with(private_key, public_key, url_endpoint) |
| 686 | + .and_return(request_obj) |
| 687 | + |
| 688 | + allow(request_obj) |
| 689 | + .to receive(:create_headers) |
| 690 | + .and_return({}) |
| 691 | + @ac={} |
| 692 | + allow(request_obj) |
| 693 | + .to receive(:request){|method,url,headers,payload| @ac={method: method, url: url, headers: headers, payload:payload}} |
| 694 | + .and_return({code: 200}) |
| 695 | + SUT = file_api_service.new(request_obj) |
| 696 | + upload = SUT.update_details( |
| 697 | + file_id: "file_id_xyz", |
| 698 | + custom_metadata: { |
| 699 | + brand: 'Nike', |
| 700 | + color: 'red' |
| 701 | + } |
| 702 | + ) |
| 703 | + expect(@ac[:payload]).to eq("{\"customMetadata\":{\"brand\":\"Nike\",\"color\":\"red\"}}") |
| 704 | + expect(upload[:code]).to eq(200) |
| 705 | + end |
600 | 706 | end |
601 | 707 |
|
602 | 708 | describe 'TestGetRemoteFileURLMetaData' do |
|
755 | 861 |
|
756 | 862 | end |
757 | 863 |
|
758 | | - it 'test_move' do |
| 864 | + it 'test_rename' do |
759 | 865 | source_file = 'test/dummy.png' |
760 | 866 | new_name = 'my_image.png' |
761 | 867 | resp = @sut.rename(file_path: source_file, new_file_name: new_name) |
762 | 868 | expect(@ac[:url]).to eq("https://api.imagekit.io/v1/files/rename") |
763 | | - expect(@ac[:payload]).to eq({:filePath=>"test/dummy.png", :newFileName=>"my_image.png"}) |
| 869 | + expect(@ac[:payload]).to eq("{\"filePath\":\"test/dummy.png\",\"newFileName\":\"my_image.png\"}") |
764 | 870 | expect(@ac[:method]).to eq('put') |
765 | 871 | expect(resp[:code]).to eq(200) |
766 | 872 | end |
|
0 commit comments