Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter user donations by email #21

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/actionkit_connector/rest/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ module User
def update_user(id, data)
self.class.put("/user/#{id}/", prep_options(data))
end

def filter_user_orders_by(field: 'user__email', value: '')
return [] if field.to_s.empty? || value.to_s.empty?
self.class.get("/order/?#{field}=#{value}", prep_options({}))
end
end
end
end
200 changes: 200 additions & 0 deletions spec/fixtures/cassettes/rest_user_filter_user_orders_by_email.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions spec/lib/rest/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,49 @@
end
end
end

describe "#filter_user_orders_by" do
context 'with an email that already exists' do
it 'gets back all the orders associated with the user email' do
VCR.use_cassette('rest_user_filter_user_orders_by_email') do
resp = client.filter_user_orders_by(field: "user__email", value: '[email protected]')
expect(resp.response.code.to_i).to eq 200
expect(resp.parsed_response["objects"].size).to eql 20
expect(resp.parsed_response["meta"]["total_count"]).to eql 35
end
end

it 'should return 0 records' do
VCR.use_cassette('rest_user_filter_user_orders_by_email_with_0_donations') do
resp = client.filter_user_orders_by(field: "user__email", value: '[email protected]')
expect(resp.response.code.to_i).to eq 200
expect(resp.parsed_response["objects"].size).to eql 0
expect(resp.parsed_response["meta"]["total_count"]).to eql 0
end
end
end

context 'with non existing user' do
it 'gets back all the orders associated with the user email' do
VCR.use_cassette('rest_user_filter_user_orders_by_email') do
resp = client.filter_user_orders_by(field: "user__email", value: '[email protected]')
expect(resp.response.code.to_i).to eq 200
expect(resp.parsed_response["objects"].size).to eql 20
expect(resp.parsed_response["meta"]["total_count"]).to eql 35
end
end

it 'should return 0 records' do
VCR.use_cassette('rest_user_filter_user_orders_by_email_with_0_donations') do
resp = client.filter_user_orders_by(field: "user__email", value: '[email protected]')
expect(resp.response.code.to_i).to eq 200
expect(resp.parsed_response["objects"].size).to eql 0
expect(resp.parsed_response["meta"]["total_count"]).to eql 0
end
end
end
end
end