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.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/lib/castle/api/list_items/archive.rb +23 -0
  3. data/lib/castle/api/list_items/count.rb +22 -0
  4. data/lib/castle/api/list_items/create.rb +22 -0
  5. data/lib/castle/api/list_items/get.rb +22 -0
  6. data/lib/castle/api/list_items/query.rb +22 -0
  7. data/lib/castle/api/list_items/unarchive.rb +22 -0
  8. data/lib/castle/api/list_items/update.rb +22 -0
  9. data/lib/castle/api/lists/create.rb +23 -0
  10. data/lib/castle/api/lists/delete.rb +22 -0
  11. data/lib/castle/api/lists/get.rb +22 -0
  12. data/lib/castle/api/lists/get_all.rb +22 -0
  13. data/lib/castle/api/lists/query.rb +22 -0
  14. data/lib/castle/api/lists/update.rb +22 -0
  15. data/lib/castle/client.rb +3 -0
  16. data/lib/castle/client_actions/list_items.rb +44 -0
  17. data/lib/castle/client_actions/lists.rb +39 -0
  18. data/lib/castle/commands/list_items/archive.rb +24 -0
  19. data/lib/castle/commands/list_items/count.rb +23 -0
  20. data/lib/castle/commands/list_items/create.rb +22 -0
  21. data/lib/castle/commands/list_items/get.rb +23 -0
  22. data/lib/castle/commands/list_items/query.rb +24 -0
  23. data/lib/castle/commands/list_items/unarchive.rb +23 -0
  24. data/lib/castle/commands/list_items/update.rb +22 -0
  25. data/lib/castle/commands/lists/create.rb +21 -0
  26. data/lib/castle/commands/lists/delete.rb +20 -0
  27. data/lib/castle/commands/lists/get.rb +20 -0
  28. data/lib/castle/commands/lists/get_all.rb +17 -0
  29. data/lib/castle/commands/lists/query.rb +21 -0
  30. data/lib/castle/commands/lists/update.rb +22 -0
  31. data/lib/castle/version.rb +1 -1
  32. data/lib/castle.rb +28 -0
  33. data/spec/lib/castle/api/approve_device_spec.rb +1 -1
  34. data/spec/lib/castle/api/authenticate_spec.rb +1 -1
  35. data/spec/lib/castle/api/end_impersonation_spec.rb +1 -1
  36. data/spec/lib/castle/api/filter_spec.rb +1 -1
  37. data/spec/lib/castle/api/get_device_spec.rb +1 -1
  38. data/spec/lib/castle/api/get_devices_for_user_spec.rb +1 -1
  39. data/spec/lib/castle/api/list_items/archive_spec.rb +18 -0
  40. data/spec/lib/castle/api/list_items/count_spec.rb +21 -0
  41. data/spec/lib/castle/api/list_items/create_spec.rb +22 -0
  42. data/spec/lib/castle/api/list_items/get_spec.rb +18 -0
  43. data/spec/lib/castle/api/list_items/query_spec.rb +21 -0
  44. data/spec/lib/castle/api/list_items/unarchive_spec.rb +18 -0
  45. data/spec/lib/castle/api/list_items/update_spec.rb +22 -0
  46. data/spec/lib/castle/api/lists/create_spec.rb +21 -0
  47. data/spec/lib/castle/api/lists/delete_spec.rb +17 -0
  48. data/spec/lib/castle/api/lists/get_all_spec.rb +17 -0
  49. data/spec/lib/castle/api/lists/get_spec.rb +17 -0
  50. data/spec/lib/castle/api/lists/query_spec.rb +21 -0
  51. data/spec/lib/castle/api/lists/update_spec.rb +21 -0
  52. data/spec/lib/castle/api/log_spec.rb +1 -1
  53. data/spec/lib/castle/api/report_device_spec.rb +1 -1
  54. data/spec/lib/castle/api/risk_spec.rb +1 -1
  55. data/spec/lib/castle/api/start_impersonation_spec.rb +1 -1
  56. data/spec/lib/castle/api/track_spec.rb +1 -1
  57. data/spec/lib/castle/api_spec.rb +1 -1
  58. data/spec/lib/castle/client_id/extract_spec.rb +1 -1
  59. data/spec/lib/castle/client_spec.rb +6 -1
  60. data/spec/lib/castle/command_spec.rb +1 -1
  61. data/spec/lib/castle/commands/approve_device_spec.rb +1 -1
  62. data/spec/lib/castle/commands/authenticate_spec.rb +1 -1
  63. data/spec/lib/castle/commands/end_impersonation_spec.rb +1 -1
  64. data/spec/lib/castle/commands/filter_spec.rb +1 -1
  65. data/spec/lib/castle/commands/get_device_spec.rb +1 -1
  66. data/spec/lib/castle/commands/get_devices_for_user_spec.rb +1 -1
  67. data/spec/lib/castle/commands/list_items/archive_spec.rb +21 -0
  68. data/spec/lib/castle/commands/list_items/count_spec.rb +21 -0
  69. data/spec/lib/castle/commands/list_items/create_spec.rb +22 -0
  70. data/spec/lib/castle/commands/list_items/get_spec.rb +21 -0
  71. data/spec/lib/castle/commands/list_items/query_spec.rb +27 -0
  72. data/spec/lib/castle/commands/list_items/unarchive_spec.rb +21 -0
  73. data/spec/lib/castle/commands/list_items/update_spec.rb +21 -0
  74. data/spec/lib/castle/commands/lists/create_spec.rb +33 -0
  75. data/spec/lib/castle/commands/lists/delete_spec.rb +21 -0
  76. data/spec/lib/castle/commands/lists/get_all_spec.rb +11 -0
  77. data/spec/lib/castle/commands/lists/get_spec.rb +21 -0
  78. data/spec/lib/castle/commands/lists/query_spec.rb +27 -0
  79. data/spec/lib/castle/commands/lists/update_spec.rb +29 -0
  80. data/spec/lib/castle/commands/log_spec.rb +1 -1
  81. data/spec/lib/castle/commands/report_device_spec.rb +1 -1
  82. data/spec/lib/castle/commands/risk_spec.rb +1 -1
  83. data/spec/lib/castle/commands/start_impersonation_spec.rb +1 -1
  84. data/spec/lib/castle/commands/track_spec.rb +1 -1
  85. data/spec/lib/castle/configuration_spec.rb +1 -1
  86. data/spec/lib/castle/context/get_default_spec.rb +1 -1
  87. data/spec/lib/castle/context/merge_spec.rb +1 -1
  88. data/spec/lib/castle/context/prepare_spec.rb +1 -1
  89. data/spec/lib/castle/context/sanitize_spec.rb +1 -1
  90. data/spec/lib/castle/core/get_connection_spec.rb +1 -1
  91. data/spec/lib/castle/core/process_response_spec.rb +1 -1
  92. data/spec/lib/castle/core/process_webhook_spec.rb +1 -1
  93. data/spec/lib/castle/core/send_request_spec.rb +1 -1
  94. data/spec/lib/castle/failover/strategy_spec.rb +1 -1
  95. data/spec/lib/castle/headers/extract_spec.rb +1 -1
  96. data/spec/lib/castle/headers/filter_spec.rb +1 -1
  97. data/spec/lib/castle/headers/format_spec.rb +1 -1
  98. data/spec/lib/castle/ips/extract_spec.rb +1 -1
  99. data/spec/lib/castle/logger_spec.rb +1 -1
  100. data/spec/lib/castle/payload/prepare_spec.rb +1 -1
  101. data/spec/lib/castle/secure_mode_spec.rb +1 -1
  102. data/spec/lib/castle/session_spec.rb +1 -1
  103. data/spec/lib/castle/singleton_configuration_spec.rb +1 -1
  104. data/spec/lib/castle/utils/clean_invalid_chars_spec.rb +1 -1
  105. data/spec/lib/castle/utils/clone_spec.rb +1 -1
  106. data/spec/lib/castle/utils/deep_symbolize_keys_spec.rb +1 -1
  107. data/spec/lib/castle/utils/get_timestamp_spec.rb +1 -1
  108. data/spec/lib/castle/utils/merge_spec.rb +1 -1
  109. data/spec/lib/castle/validators/not_supported_spec.rb +1 -1
  110. data/spec/lib/castle/validators/present_spec.rb +1 -1
  111. data/spec/lib/castle/verdict_spec.rb +1 -1
  112. data/spec/lib/castle/version_spec.rb +1 -1
  113. data/spec/lib/castle/webhooks/verify_spec.rb +1 -1
  114. data/spec/lib/castle_spec.rb +1 -1
  115. data/spec/spec_helper.rb +2 -0
  116. data/spec/support/shared_examples/list_items.rb +52 -0
  117. data/spec/support/shared_examples/lists.rb +45 -0
  118. metadata +87 -3
@@ -0,0 +1,21 @@
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
@@ -0,0 +1,27 @@
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
@@ -0,0 +1,21 @@
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
@@ -0,0 +1,21 @@
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
@@ -0,0 +1,33 @@
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
@@ -0,0 +1,21 @@
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
@@ -0,0 +1,11 @@
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
@@ -0,0 +1,21 @@
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
@@ -0,0 +1,27 @@
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
@@ -0,0 +1,29 @@
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
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::Commands::Log do
3
+ RSpec.describe Castle::Commands::Log do
4
4
  subject(:instance) { described_class }
5
5
 
6
6
  let(:context) { { test: { test1: '1' } } }
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::Commands::ReportDevice do
3
+ RSpec.describe Castle::Commands::ReportDevice do
4
4
  subject(:instance) { described_class }
5
5
 
6
6
  let(:context) { {} }
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::Commands::Risk do
3
+ RSpec.describe Castle::Commands::Risk do
4
4
  subject(:instance) { described_class }
5
5
 
6
6
  let(:context) { { test: { test1: '1' } } }
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::Commands::StartImpersonation do
3
+ RSpec.describe Castle::Commands::StartImpersonation do
4
4
  subject(:instance) { described_class }
5
5
 
6
6
  let(:context) { { user_agent: 'test', ip: '127.0.0.1', client_id: 'test' } }
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::Commands::Track do
3
+ RSpec.describe Castle::Commands::Track do
4
4
  subject(:instance) { described_class }
5
5
 
6
6
  let(:context) { { test: { test1: '1' } } }
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::Configuration do
3
+ RSpec.describe Castle::Configuration do
4
4
  subject(:config) { described_class.new }
5
5
 
6
6
  it_behaves_like 'configuration_host'
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::Context::GetDefault do
3
+ RSpec.describe Castle::Context::GetDefault do
4
4
  subject { described_class.new(request, nil) }
5
5
 
6
6
  let(:ip) { '1.2.3.4' }
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::Context::Merge do
3
+ RSpec.describe Castle::Context::Merge do
4
4
  let(:first) { { test: { test1: { c: '4' } } } }
5
5
 
6
6
  describe '#call' do
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::Context::Prepare do
3
+ RSpec.describe Castle::Context::Prepare do
4
4
  let(:ip) { '1.2.3.4' }
5
5
  let(:cookie_id) { 'abcd' }
6
6
  let(:ua) { 'Chrome' }
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::Context::Sanitize do
3
+ RSpec.describe Castle::Context::Sanitize do
4
4
  let(:paylod) { { test: 'test' } }
5
5
 
6
6
  describe '#call' do
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::Core::GetConnection do
3
+ RSpec.describe Castle::Core::GetConnection do
4
4
  describe '.call' do
5
5
  subject(:class_call) { described_class.call }
6
6
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::Core::ProcessResponse do
3
+ RSpec.describe Castle::Core::ProcessResponse do
4
4
  describe '#call' do
5
5
  subject(:call) { described_class.call(response) }
6
6
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::Core::ProcessWebhook do
3
+ RSpec.describe Castle::Core::ProcessWebhook do
4
4
  describe '#call' do
5
5
  subject(:call) { described_class.call(webhook) }
6
6
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::Core::SendRequest do
3
+ RSpec.describe Castle::Core::SendRequest do
4
4
  let(:config) { Castle.config }
5
5
 
6
6
  describe '#call' do
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::Failover::Strategy do
3
+ RSpec.describe Castle::Failover::Strategy do
4
4
  subject(:strategy) { described_class }
5
5
 
6
6
  it { expect(strategy::ALLOW).to be(:allow) }
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::Headers::Extract do
3
+ RSpec.describe Castle::Headers::Extract do
4
4
  subject(:extract_call) { described_class.new(formatted_headers).call }
5
5
 
6
6
  let(:formatted_headers) do
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::Headers::Filter do
3
+ RSpec.describe Castle::Headers::Filter do
4
4
  subject(:filter_call) { described_class.new(request).call }
5
5
 
6
6
  let(:env) do
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::Headers::Format do
3
+ RSpec.describe Castle::Headers::Format do
4
4
  subject(:format) { described_class }
5
5
 
6
6
  it 'removes HTTP_' do
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::IPs::Extract do
3
+ RSpec.describe Castle::IPs::Extract do
4
4
  subject(:extractor) { described_class.new(headers) }
5
5
 
6
6
  describe 'ip' do
@@ -7,7 +7,7 @@ class TmpLogger
7
7
  end
8
8
  end
9
9
 
10
- describe Castle::Logger do
10
+ RSpec.describe Castle::Logger do
11
11
  subject(:log) { described_class.call(message, data) }
12
12
 
13
13
  let(:message) { 'https://localhost/test:' }
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::Payload::Prepare do
3
+ RSpec.describe Castle::Payload::Prepare do
4
4
  let(:ip) { '1.2.3.4' }
5
5
  let(:cookie_id) { 'abcd' }
6
6
  let(:ua) { 'Chrome' }
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::SecureMode do
3
+ RSpec.describe Castle::SecureMode do
4
4
  it 'has signature' do
5
5
  expect(described_class.signature('test')).to eql('0329a06b62cd16b33eb6792be8c60b158d89a2ee3a876fce9a881ebb488c0914')
6
6
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::Session do
3
+ RSpec.describe Castle::Session do
4
4
  describe '.call' do
5
5
  context 'when ssl false' do
6
6
  let(:localhost) { 'localhost' }
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::SingletonConfiguration do
3
+ RSpec.describe Castle::SingletonConfiguration do
4
4
  subject(:config) { described_class.instance }
5
5
 
6
6
  it_behaves_like 'configuration_host'
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::Utils::CleanInvalidChars do
3
+ RSpec.describe Castle::Utils::CleanInvalidChars do
4
4
  describe '::call' do
5
5
  subject { described_class.call(input) }
6
6
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::Utils::Clone do
3
+ RSpec.describe Castle::Utils::Clone do
4
4
  subject(:clone) { described_class }
5
5
 
6
6
  describe 'call' do
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::Utils::DeepSymbolizeKeys do
3
+ RSpec.describe Castle::Utils::DeepSymbolizeKeys do
4
4
  let(:nested_strings) { { 'a' => { 'b' => { 'c' => 3 } } } }
5
5
  let(:nested_symbols) { { a: { b: { c: 3 } } } }
6
6
  let(:nested_mixed) { { 'a' => { b: { 'c' => 3 } } } }
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::Utils::GetTimestamp do
3
+ RSpec.describe Castle::Utils::GetTimestamp do
4
4
  subject(:timestamp) { described_class.call }
5
5
 
6
6
  let(:time_string) { '2018-01-10T14:14:24.407Z' }
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::Utils::Merge do
3
+ RSpec.describe Castle::Utils::Merge do
4
4
  subject(:merge) { described_class }
5
5
 
6
6
  describe 'call' do
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::Validators::NotSupported do
3
+ RSpec.describe Castle::Validators::NotSupported do
4
4
  describe '#call' do
5
5
  subject(:call) { described_class.call({ first: 1 }, keys) }
6
6
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::Validators::Present do
3
+ RSpec.describe Castle::Validators::Present do
4
4
  describe '#call' do
5
5
  subject(:call) { described_class.call({ first: 1, second: '2', invalid: '' }, keys) }
6
6
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::Verdict do
3
+ RSpec.describe Castle::Verdict do
4
4
  subject(:verdict) { described_class }
5
5
 
6
6
  it { expect(verdict::ALLOW).to eql('allow') }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle do
3
+ RSpec.describe Castle do
4
4
  it { expect(described_class::VERSION).to match(/\d\.\d\.\d/) }
5
5
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::Webhooks::Verify do
3
+ RSpec.describe Castle::Webhooks::Verify do
4
4
  describe '#call' do
5
5
  subject(:call) { described_class.call(webhook) }
6
6
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle do
3
+ RSpec.describe Castle do
4
4
  subject(:castle) { described_class }
5
5
 
6
6
  describe 'config' do
data/spec/spec_helper.rb CHANGED
@@ -21,4 +21,6 @@ RSpec.configure do |config|
21
21
  Castle.config.reset
22
22
  Castle.configure { |cfg| cfg.api_secret = 'secret' }
23
23
  end
24
+
25
+ config.disable_monkey_patching!
24
26
  end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.shared_examples 'it has list item actions' do
4
+ describe 'archive_list_item' do
5
+ it do
6
+ client.archive_list_item(list_id: '1234', list_item_id: '5678')
7
+ assert_requested :delete, 'https://api.castle.io/v1/lists/1234/items/5678/archive', times: 1
8
+ end
9
+ end
10
+
11
+ describe 'count_list_items' do
12
+ it do
13
+ client.count_list_items(list_id: '1234', filters: [{ field: 'email', op: 'eq', value: 'test' }])
14
+ assert_requested :post, 'https://api.castle.io/v1/lists/1234/items/count', times: 1
15
+ end
16
+ end
17
+
18
+ describe 'create_list_item' do
19
+ it do
20
+ client.create_list_item(list_id: '1234', author: { type: 'other', identifier: '1234' }, primary_value: 'email')
21
+ assert_requested :post, 'https://api.castle.io/v1/lists/1234/items', times: 1
22
+ end
23
+ end
24
+
25
+ describe 'get_list_item' do
26
+ it do
27
+ client.get_list_item(list_id: '1234', list_item_id: '5678')
28
+ assert_requested :get, 'https://api.castle.io/v1/lists/1234/items/5678', times: 1
29
+ end
30
+ end
31
+
32
+ describe 'query_list_items' do
33
+ it do
34
+ client.query_list_items(list_id: '1234', filters: [{ field: 'email', op: 'eq', value: 'test' }])
35
+ assert_requested :post, 'https://api.castle.io/v1/lists/1234/items/query', times: 1
36
+ end
37
+ end
38
+
39
+ describe 'unarchive_list_item' do
40
+ it do
41
+ client.unarchive_list_item(list_id: '1234', list_item_id: '5678')
42
+ assert_requested :put, 'https://api.castle.io/v1/lists/1234/items/5678/unarchive', times: 1
43
+ end
44
+ end
45
+
46
+ describe 'update_list_item' do
47
+ it do
48
+ client.update_list_item(list_id: '1234', list_item_id: '5678', comment: 'updating comment')
49
+ assert_requested :put, 'https://api.castle.io/v1/lists/1234/items/5678', times: 1
50
+ end
51
+ end
52
+ end