diff options
Diffstat (limited to 'spec/requests/api/users_spec.rb')
-rw-r--r-- | spec/requests/api/users_spec.rb | 44 |
1 files changed, 32 insertions, 12 deletions
diff --git a/spec/requests/api/users_spec.rb b/spec/requests/api/users_spec.rb index 7da44266064..76fe72efc64 100644 --- a/spec/requests/api/users_spec.rb +++ b/spec/requests/api/users_spec.rb @@ -5,6 +5,7 @@ require 'spec_helper' RSpec.describe API::Users, :aggregate_failures, feature_category: :user_profile do include WorkhorseHelpers include KeysetPaginationHelpers + include CryptoHelpers let_it_be(:admin) { create(:admin) } let_it_be(:user, reload: true) { create(:user, username: 'user.withdot') } @@ -226,6 +227,19 @@ RSpec.describe API::Users, :aggregate_failures, feature_category: :user_profile end end + context 'with search parameter' do + let_it_be(:first_user) { create(:user, username: 'a-user') } + let_it_be(:second_user) { create(:user, username: 'a-user2') } + + it 'prioritizes username match' do + get api(path, user, admin_mode: true), params: { search: first_user.username } + + expect(response).to have_gitlab_http_status(:ok) + expect(json_response.first['username']).to eq('a-user') + expect(json_response.second['username']).to eq('a-user2') + end + end + context 'N+1 queries' do before do create_list(:user, 2) @@ -1983,17 +1997,23 @@ RSpec.describe API::Users, :aggregate_failures, feature_category: :user_profile end describe "PUT /user/:id/credit_card_validation" do - let(:credit_card_validated_time) { Time.utc(2020, 1, 1) } + let(:network) { 'American Express' } + let(:holder_name) { 'John Smith' } + let(:last_digits) { '1111' } let(:expiration_year) { Date.today.year + 10 } + let(:expiration_month) { 1 } + let(:expiration_date) { Date.new(expiration_year, expiration_month, -1) } + let(:credit_card_validated_at) { Time.utc(2020, 1, 1) } + let(:path) { "/user/#{user.id}/credit_card_validation" } let(:params) do { - credit_card_validated_at: credit_card_validated_time, + credit_card_validated_at: credit_card_validated_at, credit_card_expiration_year: expiration_year, - credit_card_expiration_month: 1, - credit_card_holder_name: 'John Smith', - credit_card_type: 'AmericanExpress', - credit_card_mask_number: '1111' + credit_card_expiration_month: expiration_month, + credit_card_holder_name: holder_name, + credit_card_type: network, + credit_card_mask_number: last_digits } end @@ -2023,11 +2043,11 @@ RSpec.describe API::Users, :aggregate_failures, feature_category: :user_profile expect(response).to have_gitlab_http_status(:ok) expect(user.credit_card_validation).to have_attributes( - credit_card_validated_at: credit_card_validated_time, - expiration_date: Date.new(expiration_year, 1, 31), - last_digits: 1111, - network: 'AmericanExpress', - holder_name: 'John Smith' + credit_card_validated_at: credit_card_validated_at, + network_hash: sha256(network.downcase), + holder_name_hash: sha256(holder_name.downcase), + last_digits_hash: sha256(last_digits), + expiration_date_hash: sha256(expiration_date.to_s) ) end @@ -4519,7 +4539,7 @@ RSpec.describe API::Users, :aggregate_failures, feature_category: :user_profile describe 'POST /users/:user_id/personal_access_tokens' do let(:name) { 'new pat' } let(:expires_at) { 3.days.from_now.to_date.to_s } - let(:scopes) { %w(api read_user) } + let(:scopes) { %w[api read_user] } let(:path) { "/users/#{user.id}/personal_access_tokens" } let(:params) { { name: name, scopes: scopes, expires_at: expires_at } } |