castle-rb 8.0.0 → 8.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/castle/api/list_items/archive.rb +23 -0
- data/lib/castle/api/list_items/count.rb +22 -0
- data/lib/castle/api/list_items/create.rb +22 -0
- data/lib/castle/api/list_items/get.rb +22 -0
- data/lib/castle/api/list_items/query.rb +22 -0
- data/lib/castle/api/list_items/unarchive.rb +22 -0
- data/lib/castle/api/list_items/update.rb +22 -0
- data/lib/castle/api/lists/create.rb +23 -0
- data/lib/castle/api/lists/delete.rb +22 -0
- data/lib/castle/api/lists/get.rb +22 -0
- data/lib/castle/api/lists/get_all.rb +22 -0
- data/lib/castle/api/lists/query.rb +22 -0
- data/lib/castle/api/lists/update.rb +22 -0
- data/lib/castle/client.rb +3 -0
- data/lib/castle/client_actions/list_items.rb +44 -0
- data/lib/castle/client_actions/lists.rb +39 -0
- data/lib/castle/commands/list_items/archive.rb +24 -0
- data/lib/castle/commands/list_items/count.rb +23 -0
- data/lib/castle/commands/list_items/create.rb +22 -0
- data/lib/castle/commands/list_items/get.rb +23 -0
- data/lib/castle/commands/list_items/query.rb +24 -0
- data/lib/castle/commands/list_items/unarchive.rb +23 -0
- data/lib/castle/commands/list_items/update.rb +22 -0
- data/lib/castle/commands/lists/create.rb +21 -0
- data/lib/castle/commands/lists/delete.rb +20 -0
- data/lib/castle/commands/lists/get.rb +20 -0
- data/lib/castle/commands/lists/get_all.rb +17 -0
- data/lib/castle/commands/lists/query.rb +21 -0
- data/lib/castle/commands/lists/update.rb +22 -0
- data/lib/castle/version.rb +1 -1
- data/lib/castle.rb +28 -0
- data/spec/lib/castle/api/approve_device_spec.rb +1 -1
- data/spec/lib/castle/api/authenticate_spec.rb +1 -1
- data/spec/lib/castle/api/end_impersonation_spec.rb +1 -1
- data/spec/lib/castle/api/filter_spec.rb +1 -1
- data/spec/lib/castle/api/get_device_spec.rb +1 -1
- data/spec/lib/castle/api/get_devices_for_user_spec.rb +1 -1
- data/spec/lib/castle/api/list_items/archive_spec.rb +18 -0
- data/spec/lib/castle/api/list_items/count_spec.rb +21 -0
- data/spec/lib/castle/api/list_items/create_spec.rb +22 -0
- data/spec/lib/castle/api/list_items/get_spec.rb +18 -0
- data/spec/lib/castle/api/list_items/query_spec.rb +21 -0
- data/spec/lib/castle/api/list_items/unarchive_spec.rb +18 -0
- data/spec/lib/castle/api/list_items/update_spec.rb +22 -0
- data/spec/lib/castle/api/lists/create_spec.rb +21 -0
- data/spec/lib/castle/api/lists/delete_spec.rb +17 -0
- data/spec/lib/castle/api/lists/get_all_spec.rb +17 -0
- data/spec/lib/castle/api/lists/get_spec.rb +17 -0
- data/spec/lib/castle/api/lists/query_spec.rb +21 -0
- data/spec/lib/castle/api/lists/update_spec.rb +21 -0
- data/spec/lib/castle/api/log_spec.rb +1 -1
- data/spec/lib/castle/api/report_device_spec.rb +1 -1
- data/spec/lib/castle/api/risk_spec.rb +1 -1
- data/spec/lib/castle/api/start_impersonation_spec.rb +1 -1
- data/spec/lib/castle/api/track_spec.rb +1 -1
- data/spec/lib/castle/api_spec.rb +1 -1
- data/spec/lib/castle/client_id/extract_spec.rb +1 -1
- data/spec/lib/castle/client_spec.rb +6 -1
- data/spec/lib/castle/command_spec.rb +1 -1
- data/spec/lib/castle/commands/approve_device_spec.rb +1 -1
- data/spec/lib/castle/commands/authenticate_spec.rb +1 -1
- data/spec/lib/castle/commands/end_impersonation_spec.rb +1 -1
- data/spec/lib/castle/commands/filter_spec.rb +1 -1
- data/spec/lib/castle/commands/get_device_spec.rb +1 -1
- data/spec/lib/castle/commands/get_devices_for_user_spec.rb +1 -1
- data/spec/lib/castle/commands/list_items/archive_spec.rb +21 -0
- data/spec/lib/castle/commands/list_items/count_spec.rb +21 -0
- data/spec/lib/castle/commands/list_items/create_spec.rb +22 -0
- data/spec/lib/castle/commands/list_items/get_spec.rb +21 -0
- data/spec/lib/castle/commands/list_items/query_spec.rb +27 -0
- data/spec/lib/castle/commands/list_items/unarchive_spec.rb +21 -0
- data/spec/lib/castle/commands/list_items/update_spec.rb +21 -0
- data/spec/lib/castle/commands/lists/create_spec.rb +33 -0
- data/spec/lib/castle/commands/lists/delete_spec.rb +21 -0
- data/spec/lib/castle/commands/lists/get_all_spec.rb +11 -0
- data/spec/lib/castle/commands/lists/get_spec.rb +21 -0
- data/spec/lib/castle/commands/lists/query_spec.rb +27 -0
- data/spec/lib/castle/commands/lists/update_spec.rb +29 -0
- data/spec/lib/castle/commands/log_spec.rb +1 -1
- data/spec/lib/castle/commands/report_device_spec.rb +1 -1
- data/spec/lib/castle/commands/risk_spec.rb +1 -1
- data/spec/lib/castle/commands/start_impersonation_spec.rb +1 -1
- data/spec/lib/castle/commands/track_spec.rb +1 -1
- data/spec/lib/castle/configuration_spec.rb +1 -1
- data/spec/lib/castle/context/get_default_spec.rb +1 -1
- data/spec/lib/castle/context/merge_spec.rb +1 -1
- data/spec/lib/castle/context/prepare_spec.rb +1 -1
- data/spec/lib/castle/context/sanitize_spec.rb +1 -1
- data/spec/lib/castle/core/get_connection_spec.rb +1 -1
- data/spec/lib/castle/core/process_response_spec.rb +1 -1
- data/spec/lib/castle/core/process_webhook_spec.rb +1 -1
- data/spec/lib/castle/core/send_request_spec.rb +1 -1
- data/spec/lib/castle/failover/strategy_spec.rb +1 -1
- data/spec/lib/castle/headers/extract_spec.rb +1 -1
- data/spec/lib/castle/headers/filter_spec.rb +1 -1
- data/spec/lib/castle/headers/format_spec.rb +1 -1
- data/spec/lib/castle/ips/extract_spec.rb +1 -1
- data/spec/lib/castle/logger_spec.rb +1 -1
- data/spec/lib/castle/payload/prepare_spec.rb +1 -1
- data/spec/lib/castle/secure_mode_spec.rb +1 -1
- data/spec/lib/castle/session_spec.rb +1 -1
- data/spec/lib/castle/singleton_configuration_spec.rb +1 -1
- data/spec/lib/castle/utils/clean_invalid_chars_spec.rb +1 -1
- data/spec/lib/castle/utils/clone_spec.rb +1 -1
- data/spec/lib/castle/utils/deep_symbolize_keys_spec.rb +1 -1
- data/spec/lib/castle/utils/get_timestamp_spec.rb +1 -1
- data/spec/lib/castle/utils/merge_spec.rb +1 -1
- data/spec/lib/castle/validators/not_supported_spec.rb +1 -1
- data/spec/lib/castle/validators/present_spec.rb +1 -1
- data/spec/lib/castle/verdict_spec.rb +1 -1
- data/spec/lib/castle/version_spec.rb +1 -1
- data/spec/lib/castle/webhooks/verify_spec.rb +1 -1
- data/spec/lib/castle_spec.rb +1 -1
- data/spec/spec_helper.rb +2 -0
- data/spec/support/shared_examples/list_items.rb +52 -0
- data/spec/support/shared_examples/lists.rb +45 -0
- metadata +87 -3
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Castle
|
4
|
+
module Commands
|
5
|
+
module Lists
|
6
|
+
# Builds the command to query lists
|
7
|
+
class Query
|
8
|
+
class << self
|
9
|
+
# @param options [Hash]
|
10
|
+
# @return [Castle::Command]
|
11
|
+
def build(options = {})
|
12
|
+
options[:filters]&.each { |f| Castle::Validators::Present.call(f, %i[field op value]) }
|
13
|
+
Castle::Validators::Present.call(options[:sort], %i[field order]) if options[:sort]
|
14
|
+
|
15
|
+
Castle::Command.new('lists/query', options, :post)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Castle
|
4
|
+
module Commands
|
5
|
+
module Lists
|
6
|
+
# Builds the command to update a list
|
7
|
+
class Update
|
8
|
+
class << self
|
9
|
+
# @param options [Hash]
|
10
|
+
# @return [Castle::Command]
|
11
|
+
def build(options = {})
|
12
|
+
Castle::Validators::Present.call(options, %i[list_id])
|
13
|
+
|
14
|
+
list_id = options.delete(:list_id)
|
15
|
+
|
16
|
+
Castle::Command.new("lists/#{list_id}", options, :put)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/castle/version.rb
CHANGED
data/lib/castle.rb
CHANGED
@@ -31,6 +31,19 @@
|
|
31
31
|
castle/commands/risk
|
32
32
|
castle/commands/start_impersonation
|
33
33
|
castle/commands/track
|
34
|
+
castle/commands/lists/get_all
|
35
|
+
castle/commands/lists/create
|
36
|
+
castle/commands/lists/delete
|
37
|
+
castle/commands/lists/get
|
38
|
+
castle/commands/lists/query
|
39
|
+
castle/commands/lists/update
|
40
|
+
castle/commands/list_items/archive
|
41
|
+
castle/commands/list_items/create
|
42
|
+
castle/commands/list_items/count
|
43
|
+
castle/commands/list_items/get
|
44
|
+
castle/commands/list_items/query
|
45
|
+
castle/commands/list_items/unarchive
|
46
|
+
castle/commands/list_items/update
|
34
47
|
castle/api/approve_device
|
35
48
|
castle/api/authenticate
|
36
49
|
castle/api/end_impersonation
|
@@ -42,12 +55,27 @@
|
|
42
55
|
castle/api/risk
|
43
56
|
castle/api/start_impersonation
|
44
57
|
castle/api/track
|
58
|
+
castle/api/lists/get_all
|
59
|
+
castle/api/lists/create
|
60
|
+
castle/api/lists/delete
|
61
|
+
castle/api/lists/get
|
62
|
+
castle/api/lists/query
|
63
|
+
castle/api/lists/update
|
64
|
+
castle/api/list_items/archive
|
65
|
+
castle/api/list_items/create
|
66
|
+
castle/api/list_items/count
|
67
|
+
castle/api/list_items/get
|
68
|
+
castle/api/list_items/query
|
69
|
+
castle/api/list_items/unarchive
|
70
|
+
castle/api/list_items/update
|
45
71
|
castle/payload/prepare
|
46
72
|
castle/configuration
|
47
73
|
castle/singleton_configuration
|
48
74
|
castle/logger
|
49
75
|
castle/failover/prepare_response
|
50
76
|
castle/failover/strategy
|
77
|
+
castle/client_actions/lists
|
78
|
+
castle/client_actions/list_items
|
51
79
|
castle/client
|
52
80
|
castle/headers/filter
|
53
81
|
castle/headers/format
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Castle::API::ListItems::Archive do
|
4
|
+
before do
|
5
|
+
stub_request(:any, /api.castle.io/).with(basic_auth: ['', 'secret']).to_return(status: 200, body: '{}', headers: {})
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '.call' do
|
9
|
+
subject(:all) { described_class.call(options) }
|
10
|
+
|
11
|
+
let(:url) { "https://api.castle.io/v1/lists/#{options[:list_id]}/items/#{options[:list_item_id]}/archive" }
|
12
|
+
let(:options) { { list_id: '123', list_item_id: '456' } }
|
13
|
+
|
14
|
+
before { all }
|
15
|
+
|
16
|
+
it { assert_requested :delete, url, times: 1 }
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Castle::API::ListItems::Count do
|
4
|
+
before do
|
5
|
+
stub_request(:any, /api.castle.io/).with(basic_auth: ['', 'secret']).to_return(status: 200, body: '{}', headers: {})
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '.call' do
|
9
|
+
subject(:all) { described_class.call(options) }
|
10
|
+
|
11
|
+
let(:options) { { list_id: '123', filters: [{ field: 'test', op: '$eq', value: 'test' }] } }
|
12
|
+
|
13
|
+
before { all }
|
14
|
+
|
15
|
+
it do
|
16
|
+
assert_requested :post, "https://api.castle.io/v1/lists/#{options[:list_id]}/items/count", times: 1 do |req|
|
17
|
+
expect(JSON.parse(req.body, symbolize_names: true)).to eq(options.except(:list_id))
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Castle::API::ListItems::Create do
|
4
|
+
before do
|
5
|
+
stub_request(:any, /api.castle.io/).with(basic_auth: ['', 'secret']).to_return(status: 200, body: '{}', headers: {})
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '.call' do
|
9
|
+
subject(:all) { described_class.call(options) }
|
10
|
+
|
11
|
+
let(:author) { { type: '$other', identifier: 'test identifier' } }
|
12
|
+
let(:options) { { list_id: '123', primary_value: 'test value', author: author, } }
|
13
|
+
|
14
|
+
before { all }
|
15
|
+
|
16
|
+
it do
|
17
|
+
assert_requested :post, "https://api.castle.io/v1/lists/#{options[:list_id]}/items", times: 1 do |req|
|
18
|
+
expect(JSON.parse(req.body, symbolize_names: true)).to eq(options.except(:list_id))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Castle::API::ListItems::Get do
|
4
|
+
before do
|
5
|
+
stub_request(:any, /api.castle.io/).with(basic_auth: ['', 'secret']).to_return(status: 200, body: '{}', headers: {})
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '.call' do
|
9
|
+
subject(:all) { described_class.call(options) }
|
10
|
+
|
11
|
+
let(:options) { { list_id: '123', list_item_id: '456' } }
|
12
|
+
let(:url) { "https://api.castle.io/v1/lists/#{options[:list_id]}/items/#{options[:list_item_id]}" }
|
13
|
+
|
14
|
+
before { all }
|
15
|
+
|
16
|
+
it { assert_requested :get, url, times: 1 }
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Castle::API::ListItems::Query do
|
4
|
+
before do
|
5
|
+
stub_request(:any, /api.castle.io/).with(basic_auth: ['', 'secret']).to_return(status: 200, body: '{}', headers: {})
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '.call' do
|
9
|
+
subject(:all) { described_class.call(options) }
|
10
|
+
|
11
|
+
let(:options) { { list_id: '123', filters: [{ field: 'test', op: '$eq', value: 'test' }] } }
|
12
|
+
|
13
|
+
before { all }
|
14
|
+
|
15
|
+
it do
|
16
|
+
assert_requested :post, "https://api.castle.io/v1/lists/#{options[:list_id]}/items/query", times: 1 do |req|
|
17
|
+
expect(JSON.parse(req.body, symbolize_names: true)).to eq(options.except(:list_id))
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Castle::API::ListItems::Unarchive do
|
4
|
+
before do
|
5
|
+
stub_request(:any, /api.castle.io/).with(basic_auth: ['', 'secret']).to_return(status: 200, body: '{}', headers: {})
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '.call' do
|
9
|
+
subject(:all) { described_class.call(options) }
|
10
|
+
|
11
|
+
let(:url) { "https://api.castle.io/v1/lists/#{options[:list_id]}/items/#{options[:list_item_id]}/unarchive" }
|
12
|
+
let(:options) { { list_id: '123', list_item_id: '456' } }
|
13
|
+
|
14
|
+
before { all }
|
15
|
+
|
16
|
+
it { assert_requested :put, url, times: 1 }
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Castle::API::ListItems::Update do
|
4
|
+
before do
|
5
|
+
stub_request(:any, /api.castle.io/).with(basic_auth: ['', 'secret']).to_return(status: 200, body: '{}', headers: {})
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '.call' do
|
9
|
+
subject(:all) { described_class.call(options) }
|
10
|
+
|
11
|
+
let(:url) { "https://api.castle.io/v1/lists/#{options[:list_id]}/items/#{options[:list_item_id]}" }
|
12
|
+
let(:options) { { list_id: '123', list_item_id: '456', comment: 'updating comment!' } }
|
13
|
+
|
14
|
+
before { all }
|
15
|
+
|
16
|
+
it do
|
17
|
+
assert_requested :put, url, times: 1 do |req|
|
18
|
+
expect(JSON.parse(req.body, symbolize_names: true)).to eq(options.except(:list_id, :list_item_id))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Castle::API::Lists::Create do
|
4
|
+
before do
|
5
|
+
stub_request(:any, /api.castle.io/).with(basic_auth: ['', 'secret']).to_return(status: 200, body: '{}', headers: {})
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '.call' do
|
9
|
+
subject(:all) { described_class.call(options) }
|
10
|
+
|
11
|
+
let(:options) { { name: 'name', color: '$red', primary_field: 'user.email' } }
|
12
|
+
|
13
|
+
before { all }
|
14
|
+
|
15
|
+
it do
|
16
|
+
assert_requested :post, 'https://api.castle.io/v1/lists', times: 1 do |req|
|
17
|
+
expect(JSON.parse(req.body, symbolize_names: true)).to eq(options)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Castle::API::Lists::Delete do
|
4
|
+
before do
|
5
|
+
stub_request(:any, /api.castle.io/).with(basic_auth: ['', 'secret']).to_return(status: 200, body: '{}', headers: {})
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '.call' do
|
9
|
+
subject(:all) { described_class.call(options) }
|
10
|
+
|
11
|
+
let(:options) { { list_id: '123' } }
|
12
|
+
|
13
|
+
before { all }
|
14
|
+
|
15
|
+
it { assert_requested :delete, "https://api.castle.io/v1/lists/#{options[:list_id]}", times: 1 }
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Castle::API::Lists::GetAll do
|
4
|
+
before do
|
5
|
+
stub_request(:any, /api.castle.io/).with(basic_auth: ['', 'secret']).to_return(status: 200, body: '{}', headers: {})
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '.call' do
|
9
|
+
subject(:all) { described_class.call(options) }
|
10
|
+
|
11
|
+
let(:options) { { } }
|
12
|
+
|
13
|
+
before { all }
|
14
|
+
|
15
|
+
it { assert_requested :get, "https://api.castle.io/v1/lists", times: 1 }
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Castle::API::Lists::Get do
|
4
|
+
before do
|
5
|
+
stub_request(:any, /api.castle.io/).with(basic_auth: ['', 'secret']).to_return(status: 200, body: '{}', headers: {})
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '.call' do
|
9
|
+
subject(:all) { described_class.call(options) }
|
10
|
+
|
11
|
+
let(:options) { { list_id: '123' } }
|
12
|
+
|
13
|
+
before { all }
|
14
|
+
|
15
|
+
it { assert_requested :get, "https://api.castle.io/v1/lists/#{options[:list_id]}", times: 1 }
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Castle::API::Lists::Query do
|
4
|
+
before do
|
5
|
+
stub_request(:any, /api.castle.io/).with(basic_auth: ['', 'secret']).to_return(status: 200, body: '{}', headers: {})
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '.call' do
|
9
|
+
subject(:all) { described_class.call(options) }
|
10
|
+
|
11
|
+
let(:options) { { filters: [{ field: 'test', op: '$eq', value: 'test' }] } }
|
12
|
+
|
13
|
+
before { all }
|
14
|
+
|
15
|
+
it do
|
16
|
+
assert_requested :post, "https://api.castle.io/v1/lists/query", times: 1 do |req|
|
17
|
+
expect(JSON.parse(req.body, symbolize_names: true)).to eq(options)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Castle::API::Lists::Update do
|
4
|
+
before do
|
5
|
+
stub_request(:any, /api.castle.io/).with(basic_auth: ['', 'secret']).to_return(status: 200, body: '{}', headers: {})
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '.call' do
|
9
|
+
subject(:all) { described_class.call(options) }
|
10
|
+
|
11
|
+
let(:options) { { list_id: '123', name: 'name', color: '$red' } }
|
12
|
+
|
13
|
+
before { all }
|
14
|
+
|
15
|
+
it do
|
16
|
+
assert_requested :put, "https://api.castle.io/v1/lists/#{options[:list_id]}", times: 1 do |req|
|
17
|
+
expect(JSON.parse(req.body, symbolize_names: true)).to eq(options.except(:list_id))
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/spec/lib/castle/api_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
describe Castle::Client do
|
3
|
+
RSpec.describe Castle::Client do
|
4
4
|
let(:ip) { '1.2.3.4' }
|
5
5
|
let(:cookie_id) { 'abcd' }
|
6
6
|
let(:ua) { 'Chrome' }
|
@@ -334,4 +334,9 @@ describe Castle::Client do
|
|
334
334
|
describe 'log' do
|
335
335
|
it_behaves_like 'action request', :log
|
336
336
|
end
|
337
|
+
|
338
|
+
describe 'client action mixins' do
|
339
|
+
it_behaves_like 'it has list actions'
|
340
|
+
it_behaves_like 'it has list item actions'
|
341
|
+
end
|
337
342
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Castle::Commands::ListItems::Archive do
|
4
|
+
describe '.build' do
|
5
|
+
subject(:command) { described_class.build(options) }
|
6
|
+
|
7
|
+
context 'with valid options' do
|
8
|
+
let(:options) { { list_id: 'list_id', list_item_id: 'list_item_id'} }
|
9
|
+
|
10
|
+
it { expect(command.method).to be(:delete) }
|
11
|
+
it { expect(command.path).to eql('lists/list_id/items/list_item_id/archive') }
|
12
|
+
it { expect(command.data).to be_nil }
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'with invalid options' do
|
16
|
+
let(:options) { { list_id: 'list_id' } }
|
17
|
+
|
18
|
+
it { expect { command }.to raise_error(Castle::InvalidParametersError) }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Castle::Commands::ListItems::Count do
|
4
|
+
describe '.build' do
|
5
|
+
subject(:command) { described_class.build(options) }
|
6
|
+
|
7
|
+
context 'with valid options' do
|
8
|
+
let(:options) { { list_id: 'list_id', filters: [{ field: 'primary_value', op: '$eq', value: 'test'}]} }
|
9
|
+
|
10
|
+
it { expect(command.method).to be(:post) }
|
11
|
+
it { expect(command.path).to eql('lists/list_id/items/count') }
|
12
|
+
it { expect(command.data).to eql(options.except(:list_id)) }
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'with invalid filters' do
|
16
|
+
let(:options) { { list_id: 'list_id', filters: [{ field: 'primary_field', op: '$eq' }]} }
|
17
|
+
|
18
|
+
it { expect { command }.to raise_error(Castle::InvalidParametersError) }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Castle::Commands::ListItems::Create do
|
4
|
+
describe '.build' do
|
5
|
+
subject(:command) { described_class.build(options) }
|
6
|
+
|
7
|
+
context 'with valid options' do
|
8
|
+
let(:author) { { type: '$other', identifier: 'some value' } }
|
9
|
+
let(:options) { { list_id: 'list_id', author: author, primary_value: 'some value' } }
|
10
|
+
|
11
|
+
it { expect(command.method).to be(:post) }
|
12
|
+
it { expect(command.path).to eql('lists/list_id/items') }
|
13
|
+
it { expect(command.data).to eql(options.except(:list_id)) }
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'with invalid options' do
|
17
|
+
let(:options) { { list_id: 'list_id' } }
|
18
|
+
|
19
|
+
it { expect { command }.to raise_error(Castle::InvalidParametersError) }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|