Skip to content

Commit

Permalink
Add client specs for new actions
Browse files Browse the repository at this point in the history
  • Loading branch information
andymond committed Oct 30, 2024
1 parent 63a462b commit bfe622a
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 18 deletions.
24 changes: 14 additions & 10 deletions lib/castle/client_actions/list_items.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@
module Castle
module ClientActions
module ListItems
def create_list_item(options)
Castle::API::ListItems::Create.call(options)
def archive_list_item(options)
Castle::API::ListItems::Archive.call(options)
end

def update_list_item(options)
Castle::API::ListItems::Update.call(options)
def count_list_items(options)
Castle::API::ListItems::Count.call(options)
end

def delete_list_item(options)
Castle::API::ListItems::Delete.call(options)
end

def all_list_items(options)
Castle::API::ListItems::All.call(options)
def create_list_item(options)
Castle::API::ListItems::Create.call(options)
end

def get_list_item(options)
Expand All @@ -25,6 +21,14 @@ def get_list_item(options)
def query_list_items(options)
Castle::API::ListItems::Query.call(options)
end

def unarchive_list_item(options)
Castle::API::ListItems::Unarchive.call(options)
end

def update_list_item(options)
Castle::API::ListItems::Update.call(options)
end
end
end
end
16 changes: 8 additions & 8 deletions lib/castle/client_actions/lists.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@
module Castle
module ClientActions
module Lists
def create_list(options)
Castle::API::Lists::Create.call(options)
def all_lists
Castle::API::Lists::All.call
end

def update_list(options)
Castle::API::Lists::Update.call(options)
def create_list(options)
Castle::API::Lists::Create.call(options)
end

def delete_list(options)
Castle::API::Lists::Delete.call(options)
end

def all_lists(options)
Castle::API::Lists::All.call(options)
end

def get_list(options)
Castle::API::Lists::Get.call(options)
end

def query_lists(options)
Castle::API::Lists::Query.call(options)
end

def update_list(options)
Castle::API::Lists::Update.call(options)
end
end
end
end
5 changes: 5 additions & 0 deletions spec/lib/castle/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -334,4 +334,9 @@
describe 'log' do
it_behaves_like 'action request', :log
end

describe 'client action mixins' do
it_behaves_like 'it has list actions'
it_behaves_like 'it has list item actions'
end
end
51 changes: 51 additions & 0 deletions spec/support/shared_examples/list_items.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# frozen_string_literal: true
RSpec.shared_examples 'it has list item actions' do
describe 'archive_list_item' do
it do
client.archive_list_item(list_id: '1234', list_item_id: '5678')
assert_requested :delete, 'https://api.castle.io/v1/lists/1234/items/5678/archive', times: 1
end
end

describe 'count_list_items' do
it do
client.count_list_items(list_id: '1234', filters: [{ field: 'email', op: 'eq', value: 'test' }])
assert_requested :post, 'https://api.castle.io/v1/lists/1234/items/count', times: 1
end
end

describe 'create_list_item' do
it do
client.create_list_item(list_id: '1234', author: { type: 'other', identifier: '1234' }, primary_value: 'email')
assert_requested :post, 'https://api.castle.io/v1/lists/1234/items', times: 1
end
end

describe 'get_list_item' do
it do
client.get_list_item(list_id: '1234', list_item_id: '5678')
assert_requested :get, 'https://api.castle.io/v1/lists/1234/items/5678', times: 1
end
end

describe 'query_list_items' do
it do
client.query_list_items(list_id: '1234', filters: [{ field: 'email', op: 'eq', value: 'test' }])
assert_requested :post, 'https://api.castle.io/v1/lists/1234/items/query', times: 1
end
end

describe 'unarchive_list_item' do
it do
client.unarchive_list_item(list_id: '1234', list_item_id: '5678')
assert_requested :put, 'https://api.castle.io/v1/lists/1234/items/5678/unarchive', times: 1
end
end

describe 'update_list_item' do
it do
client.update_list_item(list_id: '1234', list_item_id: '5678', comment: 'updating comment')
assert_requested :put, 'https://api.castle.io/v1/lists/1234/items/5678', times: 1
end
end
end
44 changes: 44 additions & 0 deletions spec/support/shared_examples/lists.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# frozen_string_literal: true
RSpec.shared_examples 'it has list actions' do
describe 'all_lists' do
it do
client.all_lists
assert_requested :get, 'https://api.castle.io/v1/lists', times: 1
end
end

describe 'create_list' do
it do
client.create_list(name: 'list name', color: '$green', primary_field: 'user.email')
assert_requested :post, 'https://api.castle.io/v1/lists', times: 1
end
end

describe 'delete_list' do
it do
client.delete_list(list_id: 'list_id')
assert_requested :delete, 'https://api.castle.io/v1/lists/list_id', times: 1
end
end

describe 'get_list' do
it do
client.get_list(list_id: 'list_id')
assert_requested :get, 'https://api.castle.io/v1/lists/list_id', times: 1
end
end

describe 'query_lists' do
it do
client.query_lists(filters: [{ field: 'user.email', op: 'eq', value: 'test' }])
assert_requested :post, 'https://api.castle.io/v1/lists/query', times: 1
end
end

describe 'update_list' do
it do
client.update_list(list_id: 'list_id', name: 'list name', color: '$green', primary_field: 'user.email')
assert_requested :put, 'https://api.castle.io/v1/lists/list_id', times: 1
end
end
end

0 comments on commit bfe622a

Please sign in to comment.