require 'spec_helper'
require 'kintone/command/space_thread'
require 'kintone/api'
describe Kintone::Command::SpaceThread do
let(:target) { Kintone::Command::SpaceThread.new(api) }
let(:api) { Kintone::Api.new('example.cybozu.com', 'Administrator', 'cybozu') }
describe '#update' do
before(:each) do
stub_request(
:put,
'https://example.cybozu.com/k/v1/space/thread.json'
)
.with(body: request_body)
.to_return(
body: '{}',
status: 200,
headers: { 'Content-type' => 'application/json' }
)
end
subject { target.update(id, name: name, body: body) }
let(:id) { 1 }
where(:name, :body, :request_body) do
[
[
'example thread',
'awesome thread!',
'{"id":1,"name":"example thread","body":"awesome thread!"}'
],
[
nil,
'awesome thread!',
'{"id":1,"body":"awesome thread!"}'
],
[
'example thread',
nil,
'{"id":1,"name":"example thread"}'
],
[
nil,
nil,
'{"id":1}'
]
]
end
with_them do
it { expect(subject).to be_truthy }
end
context 'fail to request' do
before(:each) do
stub_request(
:put,
'https://example.cybozu.com/k/v1/space/thread.json'
)
.with(body: request_body)
.to_return(
body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
status: 500,
headers: { 'Content-Type' => 'application/json' }
)
end
let(:name) { 'example thread' }
let(:body) { 'awesome thread!' }
let(:request_body) { '{"id":1,"name":"example thread","body":"awesome thread!"}' }
it { expect { subject }.to raise_error Kintone::KintoneError }
end
end
end