|
1 | | -require "rspec/autorun" |
2 | 1 | require_relative './helper' |
| 2 | +require "rspec/autorun" |
3 | 3 |
|
4 | 4 | RSpec.describe "FileUploadTest" do |
5 | 5 | it "test_upload_with_valid_expected_success_without_tags_and_remote_url" do |
|
124 | 124 |
|
125 | 125 | end |
126 | 126 |
|
| 127 | + it "test_upload_fails_on_invalid_options" do |
| 128 | + request_obj = double |
| 129 | + allow(ImageKitRequest) |
| 130 | + .to receive(:new) |
| 131 | + .with(PRIVATE_KEY, PUBLIC_KEY, URL_ENDPOINT) |
| 132 | + .and_return(request_obj) |
| 133 | + |
| 134 | + allow(request_obj) |
| 135 | + .to receive(:create_headers) |
| 136 | + .and_return({}) |
| 137 | + |
| 138 | + allow(request_obj) |
| 139 | + .to receive(:request){|method,url,headers,payload| @ac={method: method, url: url, headers: headers, payload:payload}} |
| 140 | + .and_return({code: 401, message: nil}) |
| 141 | + |
| 142 | + SUT = ImageKitFile.new(request_obj) |
| 143 | + expect{ |
| 144 | + SUT.upload("fake_file.jpg", "fake_name", { invalid_option: "invalid_option" }) |
| 145 | + }.to raise_error(ArgumentError) |
| 146 | + end |
| 147 | + |
127 | 148 | it "test_upload_fails_on_unauthenticated_request" do |
128 | 149 | request_obj = double |
129 | 150 | allow(ImageKitRequest) |
|
504 | 525 | expect(resp[:code]).to eq(200) |
505 | 526 | expect(resp[:body]).to eq(options) |
506 | 527 | end |
| 528 | + |
| 529 | + it "test_update_file_details_fails_missing_arguments" do |
| 530 | + options = {} |
| 531 | + request_obj = double |
| 532 | + allow(ImageKitRequest) |
| 533 | + .to receive(:new) |
| 534 | + .with(PRIVATE_KEY, PUBLIC_KEY, URL_ENDPOINT) |
| 535 | + .and_return(request_obj) |
| 536 | + |
| 537 | + allow(request_obj) |
| 538 | + .to receive(:create_headers) |
| 539 | + .and_return({}) |
| 540 | + |
| 541 | + allow(request_obj) |
| 542 | + .to receive(:request){|method,url,headers,payload| @ac={method: method, url: url, headers: headers, payload:payload}} |
| 543 | + .and_return({code: 200, body: options}) |
| 544 | + |
| 545 | + SUT = ImageKitFile.new(request_obj) |
| 546 | + expect { |
| 547 | + SUT.update_details("file_id", options) |
| 548 | + }.to raise_error(ArgumentError) |
| 549 | + end |
| 550 | + |
| 551 | + it "test_update_file_details_fails_tags_not_an_array" do |
| 552 | + options = {tags: "RANDOM_TEXT", "custom_coordinates": "10,10,100,100"} |
| 553 | + request_obj = double |
| 554 | + allow(ImageKitRequest) |
| 555 | + .to receive(:new) |
| 556 | + .with(PRIVATE_KEY, PUBLIC_KEY, URL_ENDPOINT) |
| 557 | + .and_return(request_obj) |
| 558 | + |
| 559 | + allow(request_obj) |
| 560 | + .to receive(:create_headers) |
| 561 | + .and_return({}) |
| 562 | + |
| 563 | + allow(request_obj) |
| 564 | + .to receive(:request){|method,url,headers,payload| @ac={method: method, url: url, headers: headers, payload:payload}} |
| 565 | + .and_return({code: 200, body: options}) |
| 566 | + |
| 567 | + SUT = ImageKitFile.new(request_obj) |
| 568 | + expect { |
| 569 | + SUT.update_details("file_id", options) |
| 570 | + }.to raise_error(ArgumentError) |
| 571 | + end |
| 572 | + |
| 573 | + it "test_update_file_details_fails_custom_coordinates_not_a_string" do |
| 574 | + options = {"custom_coordinates": %w[random]} |
| 575 | + request_obj = double |
| 576 | + allow(ImageKitRequest) |
| 577 | + .to receive(:new) |
| 578 | + .with(PRIVATE_KEY, PUBLIC_KEY, URL_ENDPOINT) |
| 579 | + .and_return(request_obj) |
| 580 | + |
| 581 | + allow(request_obj) |
| 582 | + .to receive(:create_headers) |
| 583 | + .and_return({}) |
| 584 | + |
| 585 | + allow(request_obj) |
| 586 | + .to receive(:request){|method,url,headers,payload| @ac={method: method, url: url, headers: headers, payload:payload}} |
| 587 | + .and_return({code: 200, body: options}) |
| 588 | + |
| 589 | + SUT = ImageKitFile.new(request_obj) |
| 590 | + expect { |
| 591 | + SUT.update_details("file_id", options) |
| 592 | + }.to raise_error(ArgumentError) |
| 593 | + end |
507 | 594 | end |
508 | 595 |
|
509 | 596 |
|
| 597 | + |
| 598 | + |
510 | 599 | RSpec.describe "TestBatchDelete" do |
511 | 600 | it "test_batch_delete_fails_on_unauthenticated_request" do |
512 | 601 | file_ids = %w[file_id_1 file_id_2] |
|
605 | 694 |
|
606 | 695 | expect(@ac[:url]).to eq("https://api.imagekit.io/v1/metadata?url=http://example.com/fakefileurl") |
607 | 696 | expect(resp[:code]).to eq(401) |
| 697 | + end |
| 698 | + |
| 699 | + it "test_get_metadata_from_remote_url_fails_on_blank_url" do |
| 700 | + request_obj = double |
| 701 | + allow(ImageKitRequest) |
| 702 | + .to receive(:new) |
| 703 | + .with(PRIVATE_KEY, PUBLIC_KEY, URL_ENDPOINT) |
| 704 | + .and_return(request_obj) |
| 705 | + |
| 706 | + allow(request_obj) |
| 707 | + .to receive(:create_headers) |
| 708 | + .and_return({}) |
608 | 709 |
|
| 710 | + allow(request_obj) |
| 711 | + .to receive(:request){|method,url,headers,payload| @ac={method: method, url: url, headers: headers, payload:payload}} |
| 712 | + .and_return({code: 401, body: {}}) |
| 713 | + |
| 714 | + SUT = ImageKitFile.new(request_obj) |
| 715 | + expect { |
| 716 | + SUT.get_metadata_from_remote_url("") |
| 717 | + }.to raise_error(ArgumentError) |
609 | 718 | end |
610 | 719 |
|
611 | 720 | it "test_get_metadata_from_remote_url_succeeds" do |
|
0 commit comments