Sha256: 221a7f078d5444b10d3c32424c2e765efaee92c308daefccbba5f86c98c25ea6

Contents?: true

Size: 1.95 KB

Versions: 4

Compression:

Stored size: 1.95 KB

Contents

require 'spec_helper'
require 'kintone/command/file'
require 'kintone/api'

describe Kintone::Command::File do
  let(:target) { Kintone::Command::File.new(api) }
  let(:api) { Kintone::Api.new('example.cybozu.com', 'Administrator', 'cybozu') }

  describe '#get' do
    before(:each) do
      stub_request(
        :get,
        'https://example.cybozu.com/k/v1/file.json'
      )
        .with(body: request_body.to_json)
        .to_return(body: attachment, status: 200, headers: { 'Content-type' => 'image/gif' })
    end

    subject { target.get(fileKey) }

    let(:attachment) { Base64.decode64('data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==') } # rubocop:disable Metrics/LineLength
    let(:fileKey) { 'file-key-string' }
    let(:request_body) { { fileKey: fileKey } }

    it { expect(subject).to eq attachment }

    context 'fail to request' do
      before(:each) do
        stub_request(
          :get,
          'https://example.cybozu.com/k/v1/file.json'
        )
          .with(body: request_body.to_json)
          .to_return(
            body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
            status: 500,
            headers: { 'Content-Type' => 'application/json' }
          )
      end

      it { expect { subject }.to raise_error Kintone::KintoneError }
    end
  end

  describe '#register' do
    before(:each) do
      expect(api)
        .to receive(:post_file)
        .with(target.instance_variable_get('@url'), path, content_type, original_filename)
        .and_return('c15b3870-7505-4ab6-9d8d-b9bdbc74f5d6')
    end

    subject { target.register(path, content_type, original_filename) }

    let(:path) { '/path/to/file.txt' }
    let(:content_type) { 'text/plain' }
    let(:original_filename) { 'fileName.txt' }

    it { is_expected.to eq 'c15b3870-7505-4ab6-9d8d-b9bdbc74f5d6' }

    xcontext 'fail to request' do
      # Should consider how to test
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
kintone_rb-1.0.1 spec/kintone/command/file_spec.rb
kintone_rb-1.0.0 spec/kintone/command/file_spec.rb
kintone-oauth-extension-0.2.2 spec/kintone/command/file_spec.rb
kintone-oauth-extension-0.2.1 spec/kintone/command/file_spec.rb