Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Api
- module V1Test
- class BeneficiaryUsersController < TestApiController
- def index
- if token == 'email_updated@example.com'
- return render json: { error_code: :email_updated }, status: 403
- else
- data = {"data": [],"meta":{"has_maxed_beneficiaries":false}}
- data[:data] << mock_data_user_json(
- email: 'beneficiary_user1@example.com', is_destroyable: true
- )
- data[:data] << mock_data_user_json(email: 'beneficiary_user1@example.com', id: 2)
- data[:data] << mock_data_user_json(
- is_inactive_beneficiary: true,
- email: 'beneficiary_user4@example.com', id: 4,
- has_no_account_access_and_is_managed_by_parent: false
- )
- data[:data] << mock_data_user_json(
- is_inactive_beneficiary: true,
- email: 'beneficiary_user5@example.com', id: 5,
- has_no_account_access_and_is_managed_by_parent: true
- )
- data[:data] << mock_data_user_json(email: 'beneficiary_user2@example.com', id: 3)
- response_success(data)
- end
- end
- def update
- data = {
- "data": {
- "id": "1",
- "type": "beneficiary_user",
- "attributes": current_user.as_json.merge(params[:beneficiary_user].as_json)
- },
- "meta": { "notice": I18n.t("controllers.action_messages.update") }
- }
- response_success(data)
- end
- def sign_up
- if valid_email?
- data = {
- id: 1, type: :beneficiary_user,
- attributes: current_user.as_json
- }
- response_success(data: data)
- end
- end
- def search_by_government_id
- if params[:government_id] == '811111112'
- data = {
- "status":true,
- "data":{
- "id":95137, "first_name": "MARIA","second_first_name": nil,"last_name": "SALAS",
- "second_last_name": "CHAVARRIA","gender": "female","government_id": "811111112"
- }
- }
- response_success data
- elsif params[:government_id] == '811111111' # unactive user
- data = {
- "status": true,
- "beneficiary_id": 15,
- "title": "¿Querés activar nuevamente tu cuenta?",
- "body": "Enviaremos un mensaje a tu correo para que activés tu cuenta",
- "button": "Activar Cuenta"
- }
- response_success data
- elsif params[:government_id] == '111111111' # registered
- data = {
- "status": true,
- "errors": I18n.t('activerecord.errors.messages.government_id_user_exists'),
- "user_id": 107
- }
- response_success data
- else
- response_error('errors')
- end
- end
- def validate_email
- status = false
- status = true if valid_email?
- response_success(status: status, errors: I18n.t('activerecord.errors.messages.taken'))
- end
- def find_by_email
- if valid_email?
- # confirmed
- data = user_data.as_json
- else
- # not confirmed yet
- data = user_data.as_json.merge(authentication_token: nil)
- end
- data = {id: 1, type: :beneficiary_user, attributes: data}
- response_success(data: data)
- end
- def destroy
- if params[:id].to_i == 1
- render_nothing
- else
- response_error(I18n.t('controllers.beneficiary_users.error_destroy'))
- end
- end
- def find_blocked_beneficiary
- if params[:government_id] == '811111111'
- response_success(data: mock_data_user_json)
- else
- response_error(I18n.t('activerecord.errors.messages.user_not_found'))
- end
- end
- def create
- if ['811111111', '811111112', '811111114'].include?(params[:beneficiary_user][:government_id])
- render json: {
- data: user_data.as_json, meta: { notice: 'success' }
- }, status: 200
- elsif ['811111113'].include?(params[:government_id])
- response_error('payment_errors')
- else
- response_error('errors')
- end
- end
- def confirm
- if params[:confirmation_token] == 'token_ok_1234'
- response_success(data: mock_data_user_json(subscription_setting: nil))
- elsif params[:confirmation_token] == 'token_ok_1111'
- response_success(data: mock_data_sponsored_membership_json())
- else
- response_error(I18n.t('errors.messages.not_found_token'))
- end
- end
- def transform_inactive_beneficiary_into_affiliate
- data = {
- "status": true,
- "email": "1.evan_schamberger@hahnfarrell.co"
- }
- response_success data
- end
- def confirm_user
- if params[:government_id] == '811111111'
- response_success(data: user_data.as_json)
- else
- response_error(I18n.t('errors.messages.not_found_token'))
- end
- end
- def update_password
- if params[:beneficiary_user][:current_password] == 'A12345678'
- render_nothing
- else
- response_error('errors')
- end
- end
- def update_email
- if params[:current_email] == 'beneficiary@example.com'
- data = {
- affiliate: {
- "email": "test@test.cr"
- },
- status: 200
- }
- response_success data
- else
- response_error('errors')
- end
- end
- def update_beneficiary_email
- if params[:email] == 'error@example.com'
- return render json: {
- errors: I18n.t('activerecord.errors.messages.taken')
- }, status: 422
- else
- render json: { beneficiary: { email: params[:email] }, status: 200 }
- end
- end
- def profile
- data = {
- id: 1, type: :beneficiary_user,
- attributes: user_data
- }
- response_success(data: data)
- end
- def subscribe_receive_information
- data = {
- id: 1, type: :beneficiary_user,
- attributes: user_data
- }
- response_success(data: data)
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement