Sha256: 8f2c97605e3f2ab43000b012c11b58622a8ff4afd6e89afebe8e7a7c2861f519

Contents?: true

Size: 1.67 KB

Versions: 2

Compression:

Stored size: 1.67 KB

Contents

require 'spec_helper'
require 'kintone/command/bulk_request'
require 'kintone/api'

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

  describe '#request' do
    before(:each) do
      stub_request(
        :post,
        'https://example.cybozu.com/k/v1/bulkRequest.json'
      )
        .with(body: { requests: requests }.to_json)
        .to_return(body: { 'results' => results }.to_json, status: 200,
                   headers: { 'Content-type' => 'application/json' })
    end

    subject { target.request(requests) }

    let(:requests) do
      [
        {
          method: 'POST',
          api: '/k/v1/record.json',
          payload: {
            app: 1972,
            record: {
              '文字列__1行' => {
                value: '文字列__1行を追加します。'
              }
            }
          }
        },
        {
          method: 'PUT',
          api: '/k/v1/record.json',
          payload: {
            app: 1973,
            id: 33,
            revision: 2,
            record: {
              '文字列__1行' => {
                value: '文字列__1行を更新します。'
              }
            }
          }
        },
        {
          method: 'DELETE',
          api: '/k/v1/records.json',
          payload: {
            app: 1974,
            ids: [10, 11],
            revisions: [1, 1]
          }
        }
      ]
    end

    let(:results) do
      [
        { 'id' => '39', 'revision' => '1' },
        { 'revision' => '34' },
        {}
      ]
    end

    it { is_expected.to eq results }
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
kintone-0.1.4 spec/kintone/command/bulk_request_spec.rb
kintone-0.1.3 spec/kintone/command/bulk_request_spec.rb