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

AFE integration: Derive new-code-account from account age #35559

Merged
merged 2 commits into from
Jun 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def submit
csta
awsEducate
consentAFE
newCodeAccount
)

PERMITTED_PARAMETERS = [
Expand Down Expand Up @@ -69,7 +68,7 @@ def afe_params
'csta-plus' => filtered_params['csta'],
'aws-educate' => filtered_params['awsEducate'],
'amazon-terms' => filtered_params['consentAFE'],
'new-code-account' => filtered_params['newCodeAccount'],
'new-code-account' => current_user.created_at > 5.minutes.ago ? '1' : '0',
'registration-date-time' => Time.now.iso8601
}
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ class Api::V1::AmazonFutureEngineerControllerTest < ActionDispatch::IntegrationT
'csta-plus' => '0',
'aws-educate' => '0',
'amazon-terms' => '1',
'new-code-account' => '0',
'new-code-account' => '1',
'registration-date-time' => Time.now.iso8601
}
end
expected_call.returns FakeResponse.new
expected_call.returns fake_response

sign_in create :teacher
post '/dashboardapi/v1/amazon_future_engineer_submit',
Expand All @@ -69,6 +69,46 @@ class Api::V1::AmazonFutureEngineerControllerTest < ActionDispatch::IntegrationT
end
end

test 'new-code-account is 0 if the user was created five minutes ago or more' do
# Expect the post to Pardot with the appropriate new-code-account value
expected_call = Net::HTTP.expects(:post_form).with do |url, params|
url.to_s == CDO.afe_pardot_form_handler_url &&
params['new-code-account'] == '0'
end
expected_call.returns fake_response

Timecop.freeze do
# Create the teacher more than five minutes before we submit
teacher = create :teacher
Timecop.travel(5.minutes)

sign_in teacher
post '/dashboardapi/v1/amazon_future_engineer_submit',
params: valid_params, as: :json
assert_response :success, "Failed response: #{response.body}"
end
end

test 'new-code-account is 1 if the user was created less than five minutes ago' do
# Expect the post to Pardot with the appropriate new-code-account value
expected_call = Net::HTTP.expects(:post_form).with do |url, params|
url.to_s == CDO.afe_pardot_form_handler_url &&
params['new-code-account'] == '1'
end
expected_call.returns fake_response

Timecop.freeze do
# Create the teacher less than five minutes before we submit
teacher = create :teacher
Timecop.travel(5.minutes - 1.second)

sign_in teacher
post '/dashboardapi/v1/amazon_future_engineer_submit',
params: valid_params, as: :json
assert_response :success, "Failed response: #{response.body}"
end
end

private

def valid_params
Expand All @@ -87,18 +127,15 @@ def valid_params
'csta' => '0',
'consentCSTA' => '0',
'awsEducate' => '0',
'consentAFE' => '1',
'newCodeAccount' => '0'
'consentAFE' => '1'
}
end

class FakeResponse
def code
'200'
end

def body
''
def fake_response
mock.tap do |fake|
fake.stubs(:status).returns(200)
fake.stubs(:code).returns('200')
fake.stubs(:body).returns('')
end
end
end