kintone_rb 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/dependabot.yml +7 -0
- data/.github/workflows/rspec.yml +28 -0
- data/.gitignore +20 -0
- data/.rspec +1 -0
- data/.rubocop.yml +47 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +361 -0
- data/Rakefile +6 -0
- data/kintone.gemspec +30 -0
- data/lib/kintone/api/guest.rb +44 -0
- data/lib/kintone/api.rb +121 -0
- data/lib/kintone/command/accessor.rb +109 -0
- data/lib/kintone/command/apis.rb +22 -0
- data/lib/kintone/command/app.rb +11 -0
- data/lib/kintone/command/app_acl.rb +11 -0
- data/lib/kintone/command/apps.rb +12 -0
- data/lib/kintone/command/bulk_request.rb +12 -0
- data/lib/kintone/command/field_acl.rb +11 -0
- data/lib/kintone/command/file.rb +15 -0
- data/lib/kintone/command/form.rb +11 -0
- data/lib/kintone/command/guests.rb +17 -0
- data/lib/kintone/command/preview_form.rb +11 -0
- data/lib/kintone/command/record.rb +23 -0
- data/lib/kintone/command/record_acl.rb +11 -0
- data/lib/kintone/command/records.rb +29 -0
- data/lib/kintone/command/space.rb +15 -0
- data/lib/kintone/command/space_body.rb +11 -0
- data/lib/kintone/command/space_guests.rb +11 -0
- data/lib/kintone/command/space_members.rb +16 -0
- data/lib/kintone/command/space_thread.rb +14 -0
- data/lib/kintone/command/template_space.rb +12 -0
- data/lib/kintone/command.rb +12 -0
- data/lib/kintone/kintone_error.rb +12 -0
- data/lib/kintone/query/extension.rb +23 -0
- data/lib/kintone/query.rb +152 -0
- data/lib/kintone/type/extension/enumerable.rb +5 -0
- data/lib/kintone/type/extension/hash.rb +5 -0
- data/lib/kintone/type/extension/object.rb +5 -0
- data/lib/kintone/type/record.rb +11 -0
- data/lib/kintone/type.rb +6 -0
- data/lib/kintone/version.rb +3 -0
- data/lib/kintone_rb.rb +7 -0
- data/spec/kintone/api/guest_spec.rb +289 -0
- data/spec/kintone/api_spec.rb +566 -0
- data/spec/kintone/command/apis_spec.rb +179 -0
- data/spec/kintone/command/app_acl_spec.rb +43 -0
- data/spec/kintone/command/app_spec.rb +54 -0
- data/spec/kintone/command/apps_spec.rb +90 -0
- data/spec/kintone/command/bulk_request_spec.rb +92 -0
- data/spec/kintone/command/field_acl_spec.rb +47 -0
- data/spec/kintone/command/file_spec.rb +65 -0
- data/spec/kintone/command/form_spec.rb +47 -0
- data/spec/kintone/command/guests_spec.rb +107 -0
- data/spec/kintone/command/preview_form_spec.rb +30 -0
- data/spec/kintone/command/record_acl_spec.rb +48 -0
- data/spec/kintone/command/record_spec.rb +210 -0
- data/spec/kintone/command/records_spec.rb +463 -0
- data/spec/kintone/command/space_body_spec.rb +47 -0
- data/spec/kintone/command/space_guests_spec.rb +55 -0
- data/spec/kintone/command/space_members_spec.rb +117 -0
- data/spec/kintone/command/space_spec.rb +86 -0
- data/spec/kintone/command/space_thread_spec.rb +77 -0
- data/spec/kintone/command/template_space_spec.rb +59 -0
- data/spec/kintone/kintone_error_spec.rb +93 -0
- data/spec/kintone/query_spec.rb +506 -0
- data/spec/kintone/type/record_spec.rb +38 -0
- data/spec/spec_helper.rb +4 -0
- metadata +250 -0
@@ -0,0 +1,179 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'kintone/command/apis'
|
3
|
+
|
4
|
+
describe Kintone::Command::Apis do
|
5
|
+
let(:target) { Kintone::Command::Apis.new(api) }
|
6
|
+
let(:api) { Kintone::Api.new('example.cybozu.com', 'Administrator', 'cybozu') }
|
7
|
+
|
8
|
+
describe '#get' do
|
9
|
+
before(:each) do
|
10
|
+
stub_request(
|
11
|
+
:get,
|
12
|
+
'https://example.cybozu.com/k/v1/apis.json'
|
13
|
+
)
|
14
|
+
.to_return(
|
15
|
+
body: response_data.to_json,
|
16
|
+
status: 200,
|
17
|
+
headers: { 'Content-type' => 'application/json' }
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
subject { target.get }
|
22
|
+
|
23
|
+
def response_data
|
24
|
+
{
|
25
|
+
'baseUrl' => 'https://example.cybozu.com/k/v1/',
|
26
|
+
'apis' => {
|
27
|
+
'records/get' => {
|
28
|
+
'link' => 'apis/records/get.json'
|
29
|
+
}
|
30
|
+
}
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
it { is_expected.to eq(response_data) }
|
35
|
+
|
36
|
+
context 'fail to request' do
|
37
|
+
before(:each) do
|
38
|
+
stub_request(
|
39
|
+
:get,
|
40
|
+
'https://example.cybozu.com/k/v1/apis.json'
|
41
|
+
)
|
42
|
+
.to_return(
|
43
|
+
body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
|
44
|
+
status: 500,
|
45
|
+
headers: { 'Content-Type' => 'application/json' }
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
it { expect { subject }.to raise_error Kintone::KintoneError }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe '#get_details_of' do
|
54
|
+
before(:each) do
|
55
|
+
stub_request(
|
56
|
+
:get,
|
57
|
+
'https://example.cybozu.com/k/v1/apis/records/get.json'
|
58
|
+
)
|
59
|
+
.to_return(
|
60
|
+
body: response_data.to_json,
|
61
|
+
status: 200,
|
62
|
+
headers: { 'Content-type' => 'application/json' }
|
63
|
+
)
|
64
|
+
end
|
65
|
+
|
66
|
+
subject { target.get_details_of(link) }
|
67
|
+
|
68
|
+
let(:link) { 'apis/records/get.json' }
|
69
|
+
|
70
|
+
def response_data
|
71
|
+
{
|
72
|
+
'id' => 'GetRecords',
|
73
|
+
'baseUrl' => 'https://example.cybozu.com/k/v1/',
|
74
|
+
'path' => 'records.json',
|
75
|
+
'httpMethod' => 'GET'
|
76
|
+
}
|
77
|
+
end
|
78
|
+
|
79
|
+
it { is_expected.to eq(response_data) }
|
80
|
+
|
81
|
+
context 'fail to request' do
|
82
|
+
before(:each) do
|
83
|
+
stub_request(
|
84
|
+
:get,
|
85
|
+
'https://example.cybozu.com/k/v1/apis/records/get.json'
|
86
|
+
)
|
87
|
+
.to_return(
|
88
|
+
body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
|
89
|
+
status: 500,
|
90
|
+
headers: { 'Content-Type' => 'application/json' }
|
91
|
+
)
|
92
|
+
end
|
93
|
+
|
94
|
+
it { expect { subject }.to raise_error Kintone::KintoneError }
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe '#get_details_of_key' do
|
99
|
+
before(:each) do
|
100
|
+
stub_request(
|
101
|
+
:get,
|
102
|
+
'https://example.cybozu.com/k/v1/apis.json'
|
103
|
+
)
|
104
|
+
.to_return(
|
105
|
+
body: apis_response_data.to_json,
|
106
|
+
status: 200,
|
107
|
+
headers: { 'Content-type' => 'application/json' }
|
108
|
+
)
|
109
|
+
|
110
|
+
stub_request(
|
111
|
+
:get,
|
112
|
+
'https://example.cybozu.com/k/v1/apis/records/get.json'
|
113
|
+
)
|
114
|
+
.to_return(
|
115
|
+
body: api_response_data.to_json,
|
116
|
+
status: 200,
|
117
|
+
headers: { 'Content-type' => 'application/json' }
|
118
|
+
)
|
119
|
+
end
|
120
|
+
|
121
|
+
subject { target.get_details_of_key(key) }
|
122
|
+
|
123
|
+
def apis_response_data
|
124
|
+
{
|
125
|
+
'baseUrl' => 'https://example.cybozu.com/k/v1/',
|
126
|
+
'apis' => {
|
127
|
+
'records/get' => {
|
128
|
+
'link' => 'apis/records/get.json'
|
129
|
+
}
|
130
|
+
}
|
131
|
+
}
|
132
|
+
end
|
133
|
+
|
134
|
+
def api_response_data
|
135
|
+
{
|
136
|
+
'id' => 'GetRecords',
|
137
|
+
'baseUrl' => 'https://example.cybozu.com/k/v1/',
|
138
|
+
'path' => 'records.json',
|
139
|
+
'httpMethod' => 'GET'
|
140
|
+
}
|
141
|
+
end
|
142
|
+
|
143
|
+
context 'with key that exists' do
|
144
|
+
let(:key) { 'records/get' }
|
145
|
+
|
146
|
+
it { is_expected.to eq(api_response_data) }
|
147
|
+
end
|
148
|
+
|
149
|
+
context 'with key that does not exists' do
|
150
|
+
let(:key) { 'records/hoge' }
|
151
|
+
|
152
|
+
it { expect { subject }.to raise_error NoMethodError }
|
153
|
+
end
|
154
|
+
|
155
|
+
context 'with nil' do
|
156
|
+
let(:key) { nil }
|
157
|
+
|
158
|
+
it { expect { subject }.to raise_error NoMethodError }
|
159
|
+
end
|
160
|
+
|
161
|
+
context 'fail to request' do
|
162
|
+
before(:each) do
|
163
|
+
stub_request(
|
164
|
+
:get,
|
165
|
+
'https://example.cybozu.com/k/v1/apis/records/get.json'
|
166
|
+
)
|
167
|
+
.to_return(
|
168
|
+
body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
|
169
|
+
status: 500,
|
170
|
+
headers: { 'Content-Type' => 'application/json' }
|
171
|
+
)
|
172
|
+
end
|
173
|
+
|
174
|
+
let(:key) { 'records/get' }
|
175
|
+
|
176
|
+
it { expect { subject }.to raise_error Kintone::KintoneError }
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'kintone/command/app_acl'
|
3
|
+
require 'kintone/api'
|
4
|
+
|
5
|
+
describe Kintone::Command::AppAcl do
|
6
|
+
let(:target) { Kintone::Command::AppAcl.new(api) }
|
7
|
+
let(:api) { Kintone::Api.new('example.cybozu.com', 'Administrator', 'cybozu') }
|
8
|
+
|
9
|
+
describe '#update' do
|
10
|
+
before(:each) do
|
11
|
+
stub_request(
|
12
|
+
:put,
|
13
|
+
'https://example.cybozu.com/k/v1/app/acl.json'
|
14
|
+
)
|
15
|
+
.with(body: { 'app' => 1, 'rights' => { 'p1' => 'abc', 'p2' => 'def' } }.to_json)
|
16
|
+
.to_return(body: '{}', status: 200, headers: { 'Content-type' => 'application/json' })
|
17
|
+
end
|
18
|
+
|
19
|
+
subject { target.update(app, rights) }
|
20
|
+
|
21
|
+
let(:app) { 1 }
|
22
|
+
let(:rights) { { 'p1' => 'abc', 'p2' => 'def' } }
|
23
|
+
|
24
|
+
it { expect(subject).to eq({}) }
|
25
|
+
|
26
|
+
context 'fail to request' do
|
27
|
+
before(:each) do
|
28
|
+
stub_request(
|
29
|
+
:put,
|
30
|
+
'https://example.cybozu.com/k/v1/app/acl.json'
|
31
|
+
)
|
32
|
+
.with(body: { 'app' => 1, 'rights' => { 'p1' => 'abc', 'p2' => 'def' } }.to_json)
|
33
|
+
.to_return(
|
34
|
+
body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
|
35
|
+
status: 500,
|
36
|
+
headers: { 'Content-Type' => 'application/json' }
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
it { expect { subject }.to raise_error Kintone::KintoneError }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'kintone/command/app'
|
3
|
+
|
4
|
+
describe Kintone::Command::App do
|
5
|
+
let(:target) { Kintone::Command::App.new(api) }
|
6
|
+
let(:api) { Kintone::Api.new('example.cybozu.com', 'Administrator', 'cybozu') }
|
7
|
+
|
8
|
+
describe '#get' do
|
9
|
+
before(:each) do
|
10
|
+
stub_request(
|
11
|
+
:get,
|
12
|
+
'https://example.cybozu.com/k/v1/app.json'
|
13
|
+
)
|
14
|
+
.with(body: { id: id })
|
15
|
+
.to_return(
|
16
|
+
body: response_data.to_json,
|
17
|
+
status: 200,
|
18
|
+
headers: { 'Content-type' => 'application/json' }
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
subject { target.get(id) }
|
23
|
+
|
24
|
+
let(:id) { 4 }
|
25
|
+
|
26
|
+
def response_data
|
27
|
+
{
|
28
|
+
appId: '4',
|
29
|
+
code: '',
|
30
|
+
name: 'アプリ',
|
31
|
+
description: 'よいアプリです'
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
it { is_expected.to be_kind_of(Hash) }
|
36
|
+
|
37
|
+
context 'fail to request' do
|
38
|
+
before(:each) do
|
39
|
+
stub_request(
|
40
|
+
:get,
|
41
|
+
'https://example.cybozu.com/k/v1/app.json'
|
42
|
+
)
|
43
|
+
.with(body: { id: id })
|
44
|
+
.to_return(
|
45
|
+
body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
|
46
|
+
status: 500,
|
47
|
+
headers: { 'Content-Type' => 'application/json' }
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
51
|
+
it { expect { subject }.to raise_error Kintone::KintoneError }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'kintone/command/apps'
|
3
|
+
|
4
|
+
describe Kintone::Command::Apps do
|
5
|
+
let(:target) { Kintone::Command::Apps.new(api) }
|
6
|
+
let(:api) { Kintone::Api.new('example.cybozu.com', 'Administrator', 'cybozu') }
|
7
|
+
|
8
|
+
describe '#get' do
|
9
|
+
subject { target.get(params) }
|
10
|
+
|
11
|
+
context '引数にHashのデータを指定した場合' do
|
12
|
+
before(:each) do
|
13
|
+
stub_request(
|
14
|
+
:get,
|
15
|
+
'https://example.cybozu.com/k/v1/apps.json'
|
16
|
+
)
|
17
|
+
.with(body: params.to_json)
|
18
|
+
.to_return(
|
19
|
+
body: { apps: [] }.to_json,
|
20
|
+
status: 200,
|
21
|
+
headers: { 'Content-type' => 'application/json' }
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
where(:params) do
|
26
|
+
[
|
27
|
+
[{ ids: [100, 200] }],
|
28
|
+
[{ ids: [] }],
|
29
|
+
[{ ids: nil }],
|
30
|
+
[{ codes: ['AAA', 'BBB'] }],
|
31
|
+
[{ codes: [] }],
|
32
|
+
[{ codes: nil }],
|
33
|
+
[{ name: '名前' }],
|
34
|
+
[{ name: '' }],
|
35
|
+
[{ name: nil }],
|
36
|
+
[{ spaceIds: [100, 200] }],
|
37
|
+
[{ spaceIds: [] }],
|
38
|
+
[{ spaceIds: nil }],
|
39
|
+
[{ limit: 100 }],
|
40
|
+
[{ limit: nil }],
|
41
|
+
[{ offset: 100 }],
|
42
|
+
[{ offset: nil }],
|
43
|
+
[{}]
|
44
|
+
]
|
45
|
+
end
|
46
|
+
|
47
|
+
with_them do
|
48
|
+
it { is_expected.to be_a_kind_of(Array) }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context '引数にnilを指定した場合' do
|
53
|
+
let(:params) { nil }
|
54
|
+
|
55
|
+
before(:each) do
|
56
|
+
stub_request(
|
57
|
+
:get,
|
58
|
+
'https://example.cybozu.com/k/v1/apps.json'
|
59
|
+
)
|
60
|
+
.with(body: params.to_h.to_json)
|
61
|
+
.to_return(
|
62
|
+
body: { apps: [] }.to_json,
|
63
|
+
status: 200,
|
64
|
+
headers: { 'Content-type' => 'application/json' }
|
65
|
+
)
|
66
|
+
end
|
67
|
+
|
68
|
+
it { is_expected.to be_a_kind_of(Array) }
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'fail to request' do
|
72
|
+
before(:each) do
|
73
|
+
stub_request(
|
74
|
+
:get,
|
75
|
+
'https://example.cybozu.com/k/v1/apps.json'
|
76
|
+
)
|
77
|
+
.with(body: params.to_json)
|
78
|
+
.to_return(
|
79
|
+
body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
|
80
|
+
status: 500,
|
81
|
+
headers: { 'Content-Type' => 'application/json' }
|
82
|
+
)
|
83
|
+
end
|
84
|
+
|
85
|
+
let(:params) { { ids: [100, 200] } }
|
86
|
+
|
87
|
+
it { expect { subject }.to raise_error Kintone::KintoneError }
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'kintone/command/bulk_request'
|
3
|
+
require 'kintone/api'
|
4
|
+
|
5
|
+
describe Kintone::Command::BulkRequest do
|
6
|
+
let(:target) { Kintone::Command::BulkRequest.new(api) }
|
7
|
+
let(:api) { Kintone::Api.new('example.cybozu.com', 'Administrator', 'cybozu') }
|
8
|
+
|
9
|
+
describe '#request' do
|
10
|
+
before(:each) do
|
11
|
+
stub_request(
|
12
|
+
:post,
|
13
|
+
'https://example.cybozu.com/k/v1/bulkRequest.json'
|
14
|
+
)
|
15
|
+
.with(body: { requests: requests }.to_json)
|
16
|
+
.to_return(
|
17
|
+
body: { 'results' => results }.to_json,
|
18
|
+
status: 200,
|
19
|
+
headers: { 'Content-type' => 'application/json' }
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
subject { target.request(requests) }
|
24
|
+
|
25
|
+
let(:requests) do
|
26
|
+
[
|
27
|
+
{
|
28
|
+
method: 'POST',
|
29
|
+
api: '/k/v1/record.json',
|
30
|
+
payload: {
|
31
|
+
app: 1972,
|
32
|
+
record: {
|
33
|
+
'文字列__1行' => {
|
34
|
+
value: '文字列__1行を追加します。'
|
35
|
+
}
|
36
|
+
}
|
37
|
+
}
|
38
|
+
},
|
39
|
+
{
|
40
|
+
method: 'PUT',
|
41
|
+
api: '/k/v1/record.json',
|
42
|
+
payload: {
|
43
|
+
app: 1973,
|
44
|
+
id: 33,
|
45
|
+
revision: 2,
|
46
|
+
record: {
|
47
|
+
'文字列__1行' => {
|
48
|
+
value: '文字列__1行を更新します。'
|
49
|
+
}
|
50
|
+
}
|
51
|
+
}
|
52
|
+
},
|
53
|
+
{
|
54
|
+
method: 'DELETE',
|
55
|
+
api: '/k/v1/records.json',
|
56
|
+
payload: {
|
57
|
+
app: 1974,
|
58
|
+
ids: [10, 11],
|
59
|
+
revisions: [1, 1]
|
60
|
+
}
|
61
|
+
}
|
62
|
+
]
|
63
|
+
end
|
64
|
+
|
65
|
+
let(:results) do
|
66
|
+
[
|
67
|
+
{ 'id' => '39', 'revision' => '1' },
|
68
|
+
{ 'revision' => '34' },
|
69
|
+
{}
|
70
|
+
]
|
71
|
+
end
|
72
|
+
|
73
|
+
it { is_expected.to eq results }
|
74
|
+
|
75
|
+
context 'fail to request' do
|
76
|
+
before(:each) do
|
77
|
+
stub_request(
|
78
|
+
:post,
|
79
|
+
'https://example.cybozu.com/k/v1/bulkRequest.json'
|
80
|
+
)
|
81
|
+
.with(body: { requests: requests }.to_json)
|
82
|
+
.to_return(
|
83
|
+
body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
|
84
|
+
status: 500,
|
85
|
+
headers: { 'Content-Type' => 'application/json' }
|
86
|
+
)
|
87
|
+
end
|
88
|
+
|
89
|
+
it { expect { subject }.to raise_error Kintone::KintoneError }
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'kintone/command/field_acl'
|
3
|
+
require 'kintone/api'
|
4
|
+
|
5
|
+
describe Kintone::Command::FieldAcl do
|
6
|
+
let(:target) { Kintone::Command::FieldAcl.new(api) }
|
7
|
+
let(:api) { Kintone::Api.new('example.cybozu.com', 'Administrator', 'cybozu') }
|
8
|
+
|
9
|
+
describe '#update' do
|
10
|
+
before(:each) do
|
11
|
+
stub_request(
|
12
|
+
:put,
|
13
|
+
'https://example.cybozu.com/k/v1/field/acl.json'
|
14
|
+
)
|
15
|
+
.with(body: { 'id' => 1, 'rights' => { 'p1' => 'abc', 'p2' => 'def' } }.to_json)
|
16
|
+
.to_return(
|
17
|
+
body: '{}',
|
18
|
+
status: 200,
|
19
|
+
headers: { 'Content-type' => 'application/json' }
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
let(:id) { 1 }
|
24
|
+
let(:rights) { { 'p1' => 'abc', 'p2' => 'def' } }
|
25
|
+
|
26
|
+
subject { target.update(id, rights) }
|
27
|
+
|
28
|
+
it { expect(subject).to eq({}) }
|
29
|
+
|
30
|
+
context 'fail to request' do
|
31
|
+
before(:each) do
|
32
|
+
stub_request(
|
33
|
+
:put,
|
34
|
+
'https://example.cybozu.com/k/v1/field/acl.json'
|
35
|
+
)
|
36
|
+
.with(body: { 'id' => 1, 'rights' => { 'p1' => 'abc', 'p2' => 'def' } }.to_json)
|
37
|
+
.to_return(
|
38
|
+
body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
|
39
|
+
status: 500,
|
40
|
+
headers: { 'Content-Type' => 'application/json' }
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
it { expect { subject }.to raise_error Kintone::KintoneError }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'kintone/command/file'
|
3
|
+
require 'kintone/api'
|
4
|
+
|
5
|
+
describe Kintone::Command::File do
|
6
|
+
let(:target) { Kintone::Command::File.new(api) }
|
7
|
+
let(:api) { Kintone::Api.new('example.cybozu.com', 'Administrator', 'cybozu') }
|
8
|
+
|
9
|
+
describe '#get' do
|
10
|
+
before(:each) do
|
11
|
+
stub_request(
|
12
|
+
:get,
|
13
|
+
'https://example.cybozu.com/k/v1/file.json'
|
14
|
+
)
|
15
|
+
.with(body: request_body.to_json)
|
16
|
+
.to_return(body: attachment, status: 200, headers: { 'Content-type' => 'image/gif' })
|
17
|
+
end
|
18
|
+
|
19
|
+
subject { target.get(fileKey) }
|
20
|
+
|
21
|
+
let(:attachment) { Base64.decode64('data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==') } # rubocop:disable Metrics/LineLength
|
22
|
+
let(:fileKey) { 'file-key-string' }
|
23
|
+
let(:request_body) { { fileKey: fileKey } }
|
24
|
+
|
25
|
+
it { expect(subject).to eq attachment }
|
26
|
+
|
27
|
+
context 'fail to request' do
|
28
|
+
before(:each) do
|
29
|
+
stub_request(
|
30
|
+
:get,
|
31
|
+
'https://example.cybozu.com/k/v1/file.json'
|
32
|
+
)
|
33
|
+
.with(body: request_body.to_json)
|
34
|
+
.to_return(
|
35
|
+
body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
|
36
|
+
status: 500,
|
37
|
+
headers: { 'Content-Type' => 'application/json' }
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
it { expect { subject }.to raise_error Kintone::KintoneError }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#register' do
|
46
|
+
before(:each) do
|
47
|
+
expect(api)
|
48
|
+
.to receive(:post_file)
|
49
|
+
.with(target.instance_variable_get('@url'), path, content_type, original_filename)
|
50
|
+
.and_return('c15b3870-7505-4ab6-9d8d-b9bdbc74f5d6')
|
51
|
+
end
|
52
|
+
|
53
|
+
subject { target.register(path, content_type, original_filename) }
|
54
|
+
|
55
|
+
let(:path) { '/path/to/file.txt' }
|
56
|
+
let(:content_type) { 'text/plain' }
|
57
|
+
let(:original_filename) { 'fileName.txt' }
|
58
|
+
|
59
|
+
it { is_expected.to eq 'c15b3870-7505-4ab6-9d8d-b9bdbc74f5d6' }
|
60
|
+
|
61
|
+
xcontext 'fail to request' do
|
62
|
+
# Should consider how to test
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'kintone/command/form'
|
3
|
+
require 'kintone/api'
|
4
|
+
|
5
|
+
describe Kintone::Command::Form do
|
6
|
+
let(:target) { Kintone::Command::Form.new(api) }
|
7
|
+
let(:api) { Kintone::Api.new('example.cybozu.com', 'Administrator', 'cybozu') }
|
8
|
+
|
9
|
+
describe '#get' do
|
10
|
+
before(:each) do
|
11
|
+
stub_request(
|
12
|
+
:get,
|
13
|
+
'https://example.cybozu.com/k/v1/form.json'
|
14
|
+
)
|
15
|
+
.with(body: request_body.to_json)
|
16
|
+
.to_return(
|
17
|
+
body: '{"result":"ok"}',
|
18
|
+
status: 200,
|
19
|
+
headers: { 'Content-type' => 'application/json' }
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
subject { target.get(app) }
|
24
|
+
|
25
|
+
let(:app) { 4 }
|
26
|
+
let(:request_body) { { app: app } }
|
27
|
+
|
28
|
+
it { expect(subject).to eq 'result' => 'ok' }
|
29
|
+
|
30
|
+
context 'fail to request' do
|
31
|
+
before(:each) do
|
32
|
+
stub_request(
|
33
|
+
:get,
|
34
|
+
'https://example.cybozu.com/k/v1/form.json'
|
35
|
+
)
|
36
|
+
.with(body: request_body.to_json)
|
37
|
+
.to_return(
|
38
|
+
body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
|
39
|
+
status: 500,
|
40
|
+
headers: { 'Content-type' => 'application/json' }
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
it { expect { subject }.to raise_error Kintone::KintoneError }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|