castle-rb 8.1.0 → 9.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +317 -0
- data/LICENSE +21 -0
- data/README.md +290 -112
- data/lib/castle/api/filter.rb +3 -1
- data/lib/castle/api/list_items/create_batch.rb +22 -0
- data/lib/castle/api/lists/create.rb +1 -1
- data/lib/castle/api/log.rb +2 -1
- data/lib/castle/api/privacy/delete_data.rb +23 -0
- data/lib/castle/api/privacy/request_data.rb +23 -0
- data/lib/castle/api/risk.rb +2 -1
- data/lib/castle/client.rb +12 -52
- data/lib/castle/client_actions/list_items.rb +7 -2
- data/lib/castle/client_actions/privacy.rb +20 -0
- data/lib/castle/commands/list_items/create_batch.rb +22 -0
- data/lib/castle/commands/privacy/delete_data.rb +20 -0
- data/lib/castle/commands/privacy/request_data.rb +20 -0
- data/lib/castle/core/get_connection.rb +5 -1
- data/lib/castle/core/process_response.rb +1 -0
- data/lib/castle/core/process_webhook.rb +1 -1
- data/lib/castle/core/send_request.rb +2 -1
- data/lib/castle/errors.rb +1 -5
- data/lib/castle/headers/filter.rb +1 -1
- data/lib/castle/version.rb +1 -1
- data/lib/castle.rb +8 -17
- metadata +34 -218
- data/lib/castle/api/approve_device.rb +0 -20
- data/lib/castle/api/authenticate.rb +0 -28
- data/lib/castle/api/end_impersonation.rb +0 -22
- data/lib/castle/api/get_device.rb +0 -20
- data/lib/castle/api/get_devices_for_user.rb +0 -20
- data/lib/castle/api/report_device.rb +0 -20
- data/lib/castle/api/start_impersonation.rb +0 -22
- data/lib/castle/api/track.rb +0 -19
- data/lib/castle/commands/approve_device.rb +0 -17
- data/lib/castle/commands/authenticate.rb +0 -23
- data/lib/castle/commands/end_impersonation.rb +0 -25
- data/lib/castle/commands/get_device.rb +0 -17
- data/lib/castle/commands/get_devices_for_user.rb +0 -17
- data/lib/castle/commands/report_device.rb +0 -17
- data/lib/castle/commands/start_impersonation.rb +0 -25
- data/lib/castle/commands/track.rb +0 -22
- data/lib/castle/support/hanami.rb +0 -15
- data/lib/castle/support/padrino.rb +0 -19
- data/spec/integration/rails/rails_spec.rb +0 -95
- data/spec/integration/rails/support/all.rb +0 -6
- data/spec/integration/rails/support/application.rb +0 -17
- data/spec/integration/rails/support/home_controller.rb +0 -39
- data/spec/lib/castle/api/approve_device_spec.rb +0 -17
- data/spec/lib/castle/api/authenticate_spec.rb +0 -133
- data/spec/lib/castle/api/end_impersonation_spec.rb +0 -59
- data/spec/lib/castle/api/filter_spec.rb +0 -5
- data/spec/lib/castle/api/get_device_spec.rb +0 -17
- data/spec/lib/castle/api/get_devices_for_user_spec.rb +0 -17
- data/spec/lib/castle/api/list_items/archive_spec.rb +0 -18
- data/spec/lib/castle/api/list_items/count_spec.rb +0 -21
- data/spec/lib/castle/api/list_items/create_spec.rb +0 -22
- data/spec/lib/castle/api/list_items/get_spec.rb +0 -18
- data/spec/lib/castle/api/list_items/query_spec.rb +0 -21
- data/spec/lib/castle/api/list_items/unarchive_spec.rb +0 -18
- data/spec/lib/castle/api/list_items/update_spec.rb +0 -22
- data/spec/lib/castle/api/lists/create_spec.rb +0 -21
- data/spec/lib/castle/api/lists/delete_spec.rb +0 -17
- data/spec/lib/castle/api/lists/get_all_spec.rb +0 -17
- data/spec/lib/castle/api/lists/get_spec.rb +0 -17
- data/spec/lib/castle/api/lists/query_spec.rb +0 -21
- data/spec/lib/castle/api/lists/update_spec.rb +0 -21
- data/spec/lib/castle/api/log_spec.rb +0 -5
- data/spec/lib/castle/api/report_device_spec.rb +0 -17
- data/spec/lib/castle/api/risk_spec.rb +0 -5
- data/spec/lib/castle/api/start_impersonation_spec.rb +0 -59
- data/spec/lib/castle/api/track_spec.rb +0 -65
- data/spec/lib/castle/api_spec.rb +0 -36
- data/spec/lib/castle/client_id/extract_spec.rb +0 -47
- data/spec/lib/castle/client_spec.rb +0 -342
- data/spec/lib/castle/command_spec.rb +0 -9
- data/spec/lib/castle/commands/approve_device_spec.rb +0 -24
- data/spec/lib/castle/commands/authenticate_spec.rb +0 -86
- data/spec/lib/castle/commands/end_impersonation_spec.rb +0 -72
- data/spec/lib/castle/commands/filter_spec.rb +0 -72
- data/spec/lib/castle/commands/get_device_spec.rb +0 -24
- data/spec/lib/castle/commands/get_devices_for_user_spec.rb +0 -24
- data/spec/lib/castle/commands/list_items/archive_spec.rb +0 -21
- data/spec/lib/castle/commands/list_items/count_spec.rb +0 -21
- data/spec/lib/castle/commands/list_items/create_spec.rb +0 -22
- data/spec/lib/castle/commands/list_items/get_spec.rb +0 -21
- data/spec/lib/castle/commands/list_items/query_spec.rb +0 -27
- data/spec/lib/castle/commands/list_items/unarchive_spec.rb +0 -21
- data/spec/lib/castle/commands/list_items/update_spec.rb +0 -21
- data/spec/lib/castle/commands/lists/create_spec.rb +0 -33
- data/spec/lib/castle/commands/lists/delete_spec.rb +0 -21
- data/spec/lib/castle/commands/lists/get_all_spec.rb +0 -11
- data/spec/lib/castle/commands/lists/get_spec.rb +0 -21
- data/spec/lib/castle/commands/lists/query_spec.rb +0 -27
- data/spec/lib/castle/commands/lists/update_spec.rb +0 -29
- data/spec/lib/castle/commands/log_spec.rb +0 -73
- data/spec/lib/castle/commands/report_device_spec.rb +0 -24
- data/spec/lib/castle/commands/risk_spec.rb +0 -73
- data/spec/lib/castle/commands/start_impersonation_spec.rb +0 -72
- data/spec/lib/castle/commands/track_spec.rb +0 -89
- data/spec/lib/castle/configuration_spec.rb +0 -14
- data/spec/lib/castle/context/get_default_spec.rb +0 -41
- data/spec/lib/castle/context/merge_spec.rb +0 -23
- data/spec/lib/castle/context/prepare_spec.rb +0 -42
- data/spec/lib/castle/context/sanitize_spec.rb +0 -27
- data/spec/lib/castle/core/get_connection_spec.rb +0 -43
- data/spec/lib/castle/core/process_response_spec.rb +0 -103
- data/spec/lib/castle/core/process_webhook_spec.rb +0 -52
- data/spec/lib/castle/core/send_request_spec.rb +0 -97
- data/spec/lib/castle/failover/strategy_spec.rb +0 -12
- data/spec/lib/castle/headers/extract_spec.rb +0 -103
- data/spec/lib/castle/headers/filter_spec.rb +0 -42
- data/spec/lib/castle/headers/format_spec.rb +0 -25
- data/spec/lib/castle/ips/extract_spec.rb +0 -91
- data/spec/lib/castle/logger_spec.rb +0 -39
- data/spec/lib/castle/payload/prepare_spec.rb +0 -52
- data/spec/lib/castle/secure_mode_spec.rb +0 -7
- data/spec/lib/castle/session_spec.rb +0 -61
- data/spec/lib/castle/singleton_configuration_spec.rb +0 -14
- data/spec/lib/castle/utils/clean_invalid_chars_spec.rb +0 -69
- data/spec/lib/castle/utils/clone_spec.rb +0 -19
- data/spec/lib/castle/utils/deep_symbolize_keys_spec.rb +0 -50
- data/spec/lib/castle/utils/get_timestamp_spec.rb +0 -16
- data/spec/lib/castle/utils/merge_spec.rb +0 -13
- data/spec/lib/castle/validators/not_supported_spec.rb +0 -19
- data/spec/lib/castle/validators/present_spec.rb +0 -25
- data/spec/lib/castle/verdict_spec.rb +0 -9
- data/spec/lib/castle/version_spec.rb +0 -5
- data/spec/lib/castle/webhooks/verify_spec.rb +0 -59
- data/spec/lib/castle_spec.rb +0 -58
- data/spec/spec_helper.rb +0 -26
- data/spec/support/shared_examples/action_request.rb +0 -167
- data/spec/support/shared_examples/configuration.rb +0 -99
- data/spec/support/shared_examples/list_items.rb +0 -52
- data/spec/support/shared_examples/lists.rb +0 -45
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe Castle::Commands::ApproveDevice do
|
|
4
|
-
subject(:instance) { described_class }
|
|
5
|
-
|
|
6
|
-
let(:context) { {} }
|
|
7
|
-
let(:device_token) { '1234' }
|
|
8
|
-
|
|
9
|
-
describe '.build' do
|
|
10
|
-
subject(:command) { instance.build(device_token: device_token) }
|
|
11
|
-
|
|
12
|
-
context 'without device_token' do
|
|
13
|
-
let(:device_token) { '' }
|
|
14
|
-
|
|
15
|
-
it { expect { command }.to raise_error(Castle::InvalidParametersError) }
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
context 'with device_token' do
|
|
19
|
-
it { expect(command.method).to be(:put) }
|
|
20
|
-
it { expect(command.path).to eql("devices/#{device_token}/approve") }
|
|
21
|
-
it { expect(command.data).to be_nil }
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe Castle::Commands::Authenticate do
|
|
4
|
-
subject(:instance) { described_class }
|
|
5
|
-
|
|
6
|
-
let(:context) { { test: { test1: '1' } } }
|
|
7
|
-
let(:default_payload) { { event: '$login.authenticate', user_id: '1234', sent_at: time_auto, context: context } }
|
|
8
|
-
|
|
9
|
-
let(:time_now) { Time.now }
|
|
10
|
-
let(:time_auto) { time_now.utc.iso8601(3) }
|
|
11
|
-
|
|
12
|
-
before { Timecop.freeze(time_now) }
|
|
13
|
-
|
|
14
|
-
after { Timecop.return }
|
|
15
|
-
|
|
16
|
-
describe '.build' do
|
|
17
|
-
subject(:command) { instance.build(payload) }
|
|
18
|
-
|
|
19
|
-
context 'with properties' do
|
|
20
|
-
let(:payload) { default_payload.merge(properties: { test: '1' }) }
|
|
21
|
-
let(:command_data) { default_payload.merge(properties: { test: '1' }, context: context) }
|
|
22
|
-
|
|
23
|
-
it { expect(command.method).to be(:post) }
|
|
24
|
-
it { expect(command.path).to eql('authenticate') }
|
|
25
|
-
it { expect(command.data).to eql(command_data) }
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
context 'with user_traits' do
|
|
29
|
-
let(:payload) { default_payload.merge(user_traits: { test: '1' }) }
|
|
30
|
-
let(:command_data) { default_payload.merge(user_traits: { test: '1' }, context: context) }
|
|
31
|
-
|
|
32
|
-
it { expect(command.method).to be(:post) }
|
|
33
|
-
it { expect(command.path).to eql('authenticate') }
|
|
34
|
-
it { expect(command.data).to eql(command_data) }
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
context 'when active true' do
|
|
38
|
-
let(:payload) { default_payload.merge(context: context.merge(active: true)) }
|
|
39
|
-
let(:command_data) { default_payload.merge(context: context.merge(active: true)) }
|
|
40
|
-
|
|
41
|
-
it { expect(command.method).to be(:post) }
|
|
42
|
-
it { expect(command.path).to eql('authenticate') }
|
|
43
|
-
it { expect(command.data).to eql(command_data) }
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
context 'when active false' do
|
|
47
|
-
let(:payload) { default_payload.merge(context: context.merge(active: false)) }
|
|
48
|
-
let(:command_data) { default_payload.merge(context: context.merge(active: false)) }
|
|
49
|
-
|
|
50
|
-
it { expect(command.method).to be(:post) }
|
|
51
|
-
it { expect(command.path).to eql('authenticate') }
|
|
52
|
-
it { expect(command.data).to eql(command_data) }
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
context 'when active string' do
|
|
56
|
-
let(:payload) { default_payload.merge(context: context.merge(active: 'string')) }
|
|
57
|
-
let(:command_data) { default_payload.merge(context: context) }
|
|
58
|
-
|
|
59
|
-
it { expect(command.method).to be(:post) }
|
|
60
|
-
it { expect(command.path).to eql('authenticate') }
|
|
61
|
-
it { expect(command.data).to eql(command_data) }
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
describe '#validate!' do
|
|
66
|
-
subject(:validate!) { instance.build(payload) }
|
|
67
|
-
|
|
68
|
-
context 'with event not present' do
|
|
69
|
-
let(:payload) { {} }
|
|
70
|
-
|
|
71
|
-
it { expect { validate! }.to raise_error(Castle::InvalidParametersError, 'event is missing or empty') }
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
context 'with user_id not present' do
|
|
75
|
-
let(:payload) { { event: '$login.track' } }
|
|
76
|
-
|
|
77
|
-
it { expect { validate! }.not_to raise_error }
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
context 'with event and user_id present' do
|
|
81
|
-
let(:payload) { { event: '$login.track', user_id: '1234' } }
|
|
82
|
-
|
|
83
|
-
it { expect { validate! }.not_to raise_error }
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
end
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe Castle::Commands::EndImpersonation do
|
|
4
|
-
subject(:instance) { described_class }
|
|
5
|
-
|
|
6
|
-
let(:context) { { user_agent: 'test', ip: '127.0.0.1', client_id: 'test' } }
|
|
7
|
-
let(:impersonator) { 'test@castle.io' }
|
|
8
|
-
let(:default_payload) { { user_id: '1234', sent_at: time_auto, context: context } }
|
|
9
|
-
|
|
10
|
-
let(:time_now) { Time.now }
|
|
11
|
-
let(:time_auto) { time_now.utc.iso8601(3) }
|
|
12
|
-
|
|
13
|
-
before { Timecop.freeze(time_now) }
|
|
14
|
-
|
|
15
|
-
after { Timecop.return }
|
|
16
|
-
|
|
17
|
-
describe '.build' do
|
|
18
|
-
subject(:command) { instance.build(payload) }
|
|
19
|
-
|
|
20
|
-
context 'with impersonator' do
|
|
21
|
-
let(:payload) { default_payload.merge(properties: { impersonator: impersonator }) }
|
|
22
|
-
let(:command_data) { default_payload.merge(properties: { impersonator: impersonator }, context: context) }
|
|
23
|
-
|
|
24
|
-
it { expect(command.method).to be(:delete) }
|
|
25
|
-
it { expect(command.path).to eql('impersonate') }
|
|
26
|
-
it { expect(command.data).to eql(command_data) }
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
context 'when active true' do
|
|
30
|
-
let(:payload) { default_payload.merge(context: context.merge(active: true)) }
|
|
31
|
-
let(:command_data) { default_payload.merge(context: context.merge(active: true)) }
|
|
32
|
-
|
|
33
|
-
it { expect(command.method).to be(:delete) }
|
|
34
|
-
it { expect(command.path).to eql('impersonate') }
|
|
35
|
-
it { expect(command.data).to eql(command_data) }
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
context 'when active false' do
|
|
39
|
-
let(:payload) { default_payload.merge(context: context.merge(active: false)) }
|
|
40
|
-
let(:command_data) { default_payload.merge(context: context.merge(active: false)) }
|
|
41
|
-
|
|
42
|
-
it { expect(command.method).to be(:delete) }
|
|
43
|
-
it { expect(command.path).to eql('impersonate') }
|
|
44
|
-
it { expect(command.data).to eql(command_data) }
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
context 'when active string' do
|
|
48
|
-
let(:payload) { default_payload.merge(context: context.merge(active: 'string')) }
|
|
49
|
-
let(:command_data) { default_payload.merge(context: context) }
|
|
50
|
-
|
|
51
|
-
it { expect(command.method).to be(:delete) }
|
|
52
|
-
it { expect(command.path).to eql('impersonate') }
|
|
53
|
-
it { expect(command.data).to eql(command_data) }
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
describe '#validate!' do
|
|
58
|
-
subject(:validate!) { instance.build(payload) }
|
|
59
|
-
|
|
60
|
-
context 'when user_id not present' do
|
|
61
|
-
let(:payload) { {} }
|
|
62
|
-
|
|
63
|
-
it { expect { validate! }.to raise_error(Castle::InvalidParametersError, 'user_id is missing or empty') }
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
context 'when user_id present' do
|
|
67
|
-
let(:payload) { { user_id: '1234', context: context } }
|
|
68
|
-
|
|
69
|
-
it { expect { validate! }.not_to raise_error }
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
end
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe Castle::Commands::Filter do
|
|
4
|
-
subject(:instance) { described_class }
|
|
5
|
-
|
|
6
|
-
let(:context) { { test: { test1: '1' } } }
|
|
7
|
-
let(:user) { { id: '1234', email: 'foobar@mail.com' } }
|
|
8
|
-
let(:default_payload) do
|
|
9
|
-
{
|
|
10
|
-
request_token: '7e51335b-f4bc-4bc7-875d-b713fb61eb23-bf021a3022a1a302',
|
|
11
|
-
event: '$registration',
|
|
12
|
-
user: user,
|
|
13
|
-
sent_at: time_auto,
|
|
14
|
-
context: context
|
|
15
|
-
}
|
|
16
|
-
end
|
|
17
|
-
let(:time_now) { Time.now }
|
|
18
|
-
let(:time_auto) { time_now.utc.iso8601(3) }
|
|
19
|
-
|
|
20
|
-
before { Timecop.freeze(time_now) }
|
|
21
|
-
|
|
22
|
-
after { Timecop.return }
|
|
23
|
-
|
|
24
|
-
describe '.build' do
|
|
25
|
-
subject(:command) { instance.build(payload) }
|
|
26
|
-
|
|
27
|
-
context 'with properties' do
|
|
28
|
-
let(:payload) { default_payload.merge(properties: { test: '1' }) }
|
|
29
|
-
let(:command_data) { default_payload.merge(properties: { test: '1' }, context: context) }
|
|
30
|
-
|
|
31
|
-
it { expect(command.method).to be(:post) }
|
|
32
|
-
it { expect(command.path).to eql('filter') }
|
|
33
|
-
it { expect(command.data).to eql(command_data) }
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
context 'with user_traits' do
|
|
37
|
-
let(:payload) { default_payload.merge(user_traits: { test: '1' }) }
|
|
38
|
-
let(:command_data) { default_payload.merge(user_traits: { test: '1' }, context: context) }
|
|
39
|
-
|
|
40
|
-
it { expect(command.method).to be(:post) }
|
|
41
|
-
it { expect(command.path).to eql('filter') }
|
|
42
|
-
it { expect(command.data).to eql(command_data) }
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
context 'when active true' do
|
|
46
|
-
let(:payload) { default_payload.merge(context: context.merge(active: true)) }
|
|
47
|
-
let(:command_data) { default_payload.merge(context: context.merge(active: true)) }
|
|
48
|
-
|
|
49
|
-
it { expect(command.method).to be(:post) }
|
|
50
|
-
it { expect(command.path).to eql('filter') }
|
|
51
|
-
it { expect(command.data).to eql(command_data) }
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
context 'when active false' do
|
|
55
|
-
let(:payload) { default_payload.merge(context: context.merge(active: false)) }
|
|
56
|
-
let(:command_data) { default_payload.merge(context: context.merge(active: false)) }
|
|
57
|
-
|
|
58
|
-
it { expect(command.method).to be(:post) }
|
|
59
|
-
it { expect(command.path).to eql('filter') }
|
|
60
|
-
it { expect(command.data).to eql(command_data) }
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
context 'when active string' do
|
|
64
|
-
let(:payload) { default_payload.merge(context: context.merge(active: 'string')) }
|
|
65
|
-
let(:command_data) { default_payload.merge(context: context) }
|
|
66
|
-
|
|
67
|
-
it { expect(command.method).to be(:post) }
|
|
68
|
-
it { expect(command.path).to eql('filter') }
|
|
69
|
-
it { expect(command.data).to eql(command_data) }
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
end
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe Castle::Commands::GetDevice do
|
|
4
|
-
subject(:instance) { described_class }
|
|
5
|
-
|
|
6
|
-
let(:context) { {} }
|
|
7
|
-
let(:device_token) { '1234' }
|
|
8
|
-
|
|
9
|
-
describe '.build' do
|
|
10
|
-
subject(:command) { instance.build(device_token: device_token) }
|
|
11
|
-
|
|
12
|
-
context 'without device_token' do
|
|
13
|
-
let(:device_token) { '' }
|
|
14
|
-
|
|
15
|
-
it { expect { command }.to raise_error(Castle::InvalidParametersError) }
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
context 'with device_token' do
|
|
19
|
-
it { expect(command.method).to be(:get) }
|
|
20
|
-
it { expect(command.path).to eql("devices/#{device_token}") }
|
|
21
|
-
it { expect(command.data).to be_nil }
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe Castle::Commands::GetDevicesForUser do
|
|
4
|
-
subject(:instance) { described_class }
|
|
5
|
-
|
|
6
|
-
let(:context) { {} }
|
|
7
|
-
let(:user_id) { '1234' }
|
|
8
|
-
|
|
9
|
-
describe '.build' do
|
|
10
|
-
subject(:command) { instance.build(user_id: user_id) }
|
|
11
|
-
|
|
12
|
-
context 'without user_id' do
|
|
13
|
-
let(:user_id) { '' }
|
|
14
|
-
|
|
15
|
-
it { expect { command }.to raise_error(Castle::InvalidParametersError) }
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
context 'with user_id' do
|
|
19
|
-
it { expect(command.method).to be(:get) }
|
|
20
|
-
it { expect(command.path).to eql("users/#{user_id}/devices") }
|
|
21
|
-
it { expect(command.data).to be_nil }
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
@@ -1,21 +0,0 @@
|
|
|
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
|
|
@@ -1,21 +0,0 @@
|
|
|
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
|
|
@@ -1,22 +0,0 @@
|
|
|
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
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe Castle::Commands::ListItems::Get 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(:get) }
|
|
11
|
-
it { expect(command.path).to eql('lists/list_id/items/list_item_id') }
|
|
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
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe Castle::Commands::ListItems::Query 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/query') }
|
|
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
|
-
|
|
21
|
-
context 'with no list_id' do
|
|
22
|
-
let(:options) { { filters: [{ field: 'primary_field', op: '$eq', value: 'test' }]} }
|
|
23
|
-
|
|
24
|
-
it { expect { command }.to raise_error(Castle::InvalidParametersError) }
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe Castle::Commands::ListItems::Unarchive 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(:put) }
|
|
11
|
-
it { expect(command.path).to eql('lists/list_id/items/list_item_id/unarchive') }
|
|
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
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe Castle::Commands::ListItems::Update 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', comment: 'updating item' } }
|
|
9
|
-
|
|
10
|
-
it { expect(command.method).to be(:put) }
|
|
11
|
-
it { expect(command.path).to eql('lists/list_id/items/list_item_id') }
|
|
12
|
-
it { expect(command.data).to eql(options.except(:list_id, :list_item_id)) }
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
context 'with invalid options' do
|
|
16
|
-
let(:options) { { list_id: 'list_id', list_item_id: 'list_item_id' } }
|
|
17
|
-
|
|
18
|
-
it { expect { command }.to raise_error(Castle::InvalidParametersError) }
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe Castle::Commands::Lists::Create do
|
|
4
|
-
describe '.build' do
|
|
5
|
-
subject(:command) { described_class.build(options) }
|
|
6
|
-
|
|
7
|
-
let(:options) { { name: 'list_name', color: '$green', primary_field: 'user.email' } }
|
|
8
|
-
|
|
9
|
-
context 'with valid options' do
|
|
10
|
-
it { expect(command.method).to be(:post) }
|
|
11
|
-
it { expect(command.path).to eql('lists') }
|
|
12
|
-
it { expect(command.data).to eql(options) }
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
context 'without name' do
|
|
16
|
-
let(:options) { { color: '$green', primary_field: 'user.email' } }
|
|
17
|
-
|
|
18
|
-
it { expect { command }.to raise_error(Castle::InvalidParametersError) }
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
context 'without color' do
|
|
22
|
-
let(:options) { { name: 'list_name', primary_field: 'user.email' } }
|
|
23
|
-
|
|
24
|
-
it { expect { command }.to raise_error(Castle::InvalidParametersError) }
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
context 'without primary_field' do
|
|
28
|
-
let(:options) { { name: 'list_name', color: '$green' } }
|
|
29
|
-
|
|
30
|
-
it { expect { command }.to raise_error(Castle::InvalidParametersError) }
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe Castle::Commands::Lists::Delete do
|
|
4
|
-
describe '.build' do
|
|
5
|
-
subject(:command) { described_class.build(options) }
|
|
6
|
-
|
|
7
|
-
let(:options) { { list_id: 'list_id' } }
|
|
8
|
-
|
|
9
|
-
context 'with valid options' do
|
|
10
|
-
it { expect(command.method).to be(:delete) }
|
|
11
|
-
it { expect(command.path).to eql('lists/list_id') }
|
|
12
|
-
it { expect(command.data).to be_nil }
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
context 'without list_id' do
|
|
16
|
-
let(:options) { {} }
|
|
17
|
-
|
|
18
|
-
it { expect { command }.to raise_error(Castle::InvalidParametersError) }
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe Castle::Commands::Lists::GetAll do
|
|
4
|
-
describe '.build' do
|
|
5
|
-
subject(:command) { described_class.build }
|
|
6
|
-
|
|
7
|
-
it { expect(command.method).to be(:get) }
|
|
8
|
-
it { expect(command.path).to eql('lists') }
|
|
9
|
-
it { expect(command.data).to be_nil }
|
|
10
|
-
end
|
|
11
|
-
end
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe Castle::Commands::Lists::Get do
|
|
4
|
-
describe '.build' do
|
|
5
|
-
subject(:command) { described_class.build(options) }
|
|
6
|
-
|
|
7
|
-
let(:options) { { list_id: 'list_id' } }
|
|
8
|
-
|
|
9
|
-
context 'with valid options' do
|
|
10
|
-
it { expect(command.method).to be(:get) }
|
|
11
|
-
it { expect(command.path).to eql('lists/list_id') }
|
|
12
|
-
it { expect(command.data).to be_nil }
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
context 'without list_id' do
|
|
16
|
-
let(:options) { {} }
|
|
17
|
-
|
|
18
|
-
it { expect { command }.to raise_error(Castle::InvalidParametersError) }
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe Castle::Commands::Lists::Query do
|
|
4
|
-
describe '.build' do
|
|
5
|
-
subject(:command) { described_class.build(options) }
|
|
6
|
-
|
|
7
|
-
context 'with valid options' do
|
|
8
|
-
let(:options) { { filters: [{ field: 'primary_field', op: '$eq', value: 'test' }]} }
|
|
9
|
-
|
|
10
|
-
it { expect(command.method).to be(:post) }
|
|
11
|
-
it { expect(command.path).to eql('lists/query') }
|
|
12
|
-
it { expect(command.data).to eq(options.except(:list_id)) }
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
context 'with invalid filters' do
|
|
16
|
-
let(:options) { { filters: [{ field: 'primary_field', op: '$eq' }]} }
|
|
17
|
-
|
|
18
|
-
it { expect { command }.to raise_error(Castle::InvalidParametersError) }
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
context 'with invalid sort' do
|
|
22
|
-
let(:options) { { sort: { field: 'primary_field' } } }
|
|
23
|
-
|
|
24
|
-
it { expect { command }.to raise_error(Castle::InvalidParametersError) }
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe Castle::Commands::Lists::Update do
|
|
4
|
-
describe '.build' do
|
|
5
|
-
subject(:command) { described_class.build(options) }
|
|
6
|
-
|
|
7
|
-
context 'with valid options' do
|
|
8
|
-
let(:options) do
|
|
9
|
-
{
|
|
10
|
-
list_id: 'list_id',
|
|
11
|
-
name: 'name',
|
|
12
|
-
description: 'description',
|
|
13
|
-
color: '$yellow',
|
|
14
|
-
default_item_archivation_time: 6000
|
|
15
|
-
}
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
it { expect(command.method).to be(:put) }
|
|
19
|
-
it { expect(command.path).to eql('lists/list_id') }
|
|
20
|
-
it { expect(command.data).to eql(options.except(:list_id)) }
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
context 'without list_id' do
|
|
24
|
-
let(:options) { { name: 'name' } }
|
|
25
|
-
|
|
26
|
-
it { expect { command }.to raise_error(Castle::InvalidParametersError) }
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|