Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Added missing Platform API Users endpoint spec

Damian Legawiec5a639443fec9
diff --git a/api/spec/requests/spree/api/v2/platform/users_spec.rb b/api/spec/requests/spree/api/v2/platform/users_spec.rb
new file mode 100644
index 0000000000..e5a7c3e88b
--- /dev/null
+++ b/api/spec/requests/spree/api/v2/platform/users_spec.rb
@@ -0,0 +1,58 @@
+require 'spec_helper'
+
+describe 'Platform API v2 Users API' do
+ include_context 'Platform API v2'
+
+ let(:bearer_token) { { 'Authorization' => valid_authorization } }
+
+ describe 'users#index' do
+ let!(:user) { create(:user, email: '[email protected]') }
+ let!(:user_2) { create(:user, email: '[email protected]') }
+
+ context 'filtering' do
+ context 'by email' do
+ before { get '/api/v2/platform/users?filter[email_eq][email protected]', headers: bearer_token }
+
+ it 'returns users with matching email' do
+ expect(json_response['data'].count).to eq 1
+ expect(json_response['data'].first).to have_id(user.id.to_s)
+ end
+ end
+
+ context 'by address firstname' do
+ let!(:address) { create(:address, firstname: 'Daenerys', user: user_2) }
+
+ before { get '/api/v2/platform/users?filter[addresses_firstname_eq]=Daenerys', headers: bearer_token }
+
+ it 'returns users with matching address firstname' do
+ expect(json_response['data'].count).to eq 1
+ expect(json_response['data'].first).to have_id(user_2.id.to_s)
+ end
+ end
+
+ context 'by address lastname' do
+ let!(:address) { create(:address, lastname: 'Targaryen', user: user_2) }
+
+ before { get '/api/v2/platform/users?filter[addresses_lastname_eq]=Targaryen', headers: bearer_token }
+
+ it 'returns users with matching address lastname' do
+ expect(json_response['data'].count).to eq 1
+ expect(json_response['data'].first).to have_id(user_2.id.to_s)
+ end
+ end
+
+ context 'by address firstname, lastname and email combined' do
+ let!(:address) { create(:address, firstname: 'John', user: user) }
+ let!(:address_2) { create(:address, lastname: 'Targaryen', user: user_2) }
+
+ before do
+ get '/api/v2/platform/users?filter[m]=or&filter[addresses_lastname_eq]=targaryen&filter[addresses_firstname_eq]=John', headers: bearer_token
+ end
+
+ it 'returns users with matching address lastname' do
+ expect(json_response['data'].count).to eq 2
+ end
+ end
+ end
+ end
+end