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
+ 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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Castle
4
- VERSION = '8.0.0'
4
+ VERSION = '8.1.0'
5
5
  end
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
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::API::ApproveDevice do
3
+ RSpec.describe Castle::API::ApproveDevice do
4
4
  before do
5
5
  stub_request(:any, /api.castle.io/).with(basic_auth: ['', 'secret']).to_return(status: 200, body: '{}', headers: {})
6
6
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::API::Authenticate do
3
+ RSpec.describe Castle::API::Authenticate do
4
4
  subject(:call_subject) { described_class.call(options) }
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::API::EndImpersonation do
3
+ RSpec.describe Castle::API::EndImpersonation do
4
4
  subject(:call) { described_class.call(options) }
5
5
 
6
6
  let(:ip) { '1.2.3.4' }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::API::Filter do
3
+ RSpec.describe Castle::API::Filter do
4
4
  pending
5
5
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::API::GetDevice do
3
+ RSpec.describe Castle::API::GetDevice do
4
4
  before do
5
5
  stub_request(:any, /api.castle.io/).with(basic_auth: ['', 'secret']).to_return(status: 200, body: '{}', headers: {})
6
6
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::API::GetDevicesForUser do
3
+ RSpec.describe Castle::API::GetDevicesForUser do
4
4
  before do
5
5
  stub_request(:any, /api.castle.io/).with(basic_auth: ['', 'secret']).to_return(status: 200, body: '{}', headers: {})
6
6
  end
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::API::Log do
3
+ RSpec.describe Castle::API::Log do
4
4
  pending
5
5
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::API::ReportDevice do
3
+ RSpec.describe Castle::API::ReportDevice do
4
4
  before do
5
5
  stub_request(:any, /api.castle.io/).with(basic_auth: ['', 'secret']).to_return(status: 200, body: '{}', headers: {})
6
6
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::API::Risk do
3
+ RSpec.describe Castle::API::Risk do
4
4
  pending
5
5
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::API::StartImpersonation do
3
+ RSpec.describe Castle::API::StartImpersonation do
4
4
  subject(:call) { described_class.call(options) }
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::API::Track do
3
+ RSpec.describe Castle::API::Track do
4
4
  subject(:call) { described_class.call(options) }
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::API do
3
+ RSpec.describe Castle::API do
4
4
  subject(:call) { described_class.call(command) }
5
5
 
6
6
  let(:command) { Castle::Commands::Track.build(event: '$login.succeeded') }
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::ClientId::Extract do
3
+ RSpec.describe Castle::ClientId::Extract do
4
4
  subject(:extractor) { described_class.new(formatted_headers, cookies) }
5
5
 
6
6
  let(:formatted_headers) { Castle::Headers::Filter.new(request).call }
@@ -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
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::Command do
3
+ RSpec.describe Castle::Command do
4
4
  subject(:command) { described_class.new('go', { id: '1' }, :post) }
5
5
 
6
6
  it { expect(command.path).to eql('go') }
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe Castle::Commands::ApproveDevice do
3
+ RSpec.describe Castle::Commands::ApproveDevice 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::Authenticate do
3
+ RSpec.describe Castle::Commands::Authenticate 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::EndImpersonation do
3
+ RSpec.describe Castle::Commands::EndImpersonation 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::Filter do
3
+ RSpec.describe Castle::Commands::Filter 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::GetDevice do
3
+ RSpec.describe Castle::Commands::GetDevice 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::GetDevicesForUser do
3
+ RSpec.describe Castle::Commands::GetDevicesForUser do
4
4
  subject(:instance) { described_class }
5
5
 
6
6
  let(:context) { {} }
@@ -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