Commit df4261f8 authored by Cool Fire's avatar Cool Fire

Added some logic to entering invite code + related tests

parent 6065aa47
Pipeline #324 passed with stages
in 1 minute and 28 seconds
---
header: Welcome to the Insomnia 24/7 shells signup
header: Insomnia 24/7 shells signup
body: >
Please enter your invite code below.
---
header: Welcome to the Insomnia 24/7 shells signup
header: Insomnia 24/7 shells signup
blurb: |
<h3>Specifying your reasons</h3>
<p>If you have an invite code you need not enter any additional reasons, though you are free to add them if you so desire. For those of you who do not have an invite code, please be as detailed as possible. Describe what projects you have planned or are working on now, what role our shell server would play in the development process, and why you cannot use another free service such as a free web host or GitHub for example. Add anything else you feel is relevant or may help us decide to give you a shell account.</p>
......
......@@ -27,6 +27,21 @@ class SignupSite < Sinatra::Base
erb :index
end
post '/check-code' do
if (!params.key? :input_invite) ||
params[:input_invite].empty? ||
params[:input_invite] !~ /^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/
@header = 'Insomnia 24/7 shells signup'
@body = 'Invite code appears to be invalid. Please try again.'
@progress = 25
erb :index
else
session[:invite] = Rack::Utils.escape_html(params[:input_invite])
redirect '/enter-details', 302
end
end
get '/enter-details' do
ed = YAML.load_file('content/enter-details.yaml')
@header = ed['header']
......@@ -36,4 +51,8 @@ class SignupSite < Sinatra::Base
@progress = 50
erb :index
end
post '/check-details' do
# Some checking stuff
end
end
......@@ -8,7 +8,7 @@ def app
SignupSite
end
describe 'SignupSite' do
describe 'Landing page' do
it 'should return HTML' do
get '/'
last_response.body.must_include '<!DOCTYPE html>'
......@@ -19,34 +19,65 @@ describe 'SignupSite' do
last_response.body.must_include 'Welcome to the Insomnia 24/7 shells signup'
end
it 'should display info on the landing page' do
it 'should display info' do
get '/'
last_response.body.must_include 'About our shells'
end
it 'should display link to enter-code landing page' do
it 'should display link to enter-code' do
get '/'
last_response.body.must_include 'href="enter-code"'
end
it 'should display link to enter-details landing page' do
it 'should display link to enter-details' do
get '/'
last_response.body.must_include 'href="enter-details"'
end
end
describe 'Enter code page' do
it 'should return invite code form' do
get '/enter-code'
last_response.body.must_include 'Invite code'
end
end
describe 'Enter code page' do
it 'should return invite code form' do
get '/enter-code'
last_response.body.must_include 'Invite code'
end
it 'should reject empty invite codes' do
post '/check-code'
last_response.body.must_include 'Invite code appears to be invalid.'
end
it 'should display reasons info on details form page' do
it 'should reject improperly formatted invite codes' do
post '/check-code', input_invite: 'not an invite code'
last_response.body.must_include 'Invite code appears to be invalid.'
end
it 'should accept properly formatted invite codes' do
post '/check-code', input_invite: 'c65d8c31-482b-4329-b288-8b0959a43ea2'
assert_equal last_response.status, 302
end
it 'should redirect to details form for properly formatted invite codes' do
post '/check-code', input_invite: 'c65d8c31-482b-4329-b288-8b0959a43ea2'
follow_redirect!
last_request.url.must_include 'enter-details'
end
end
describe 'Enter details page' do
it 'should display reasons info' do
get '/enter-details'
last_response.body.must_include 'Specifying your reasons'
end
it 'should return details form' do
it 'should display details form' do
get '/enter-details'
last_response.body.must_include 'User name'
end
end
<form class="form-horizontal" method="post" action="check-code">
<form class="form-horizontal" method="POST" action="/check-code">
<fieldset>
<div class="form-group">
<label for="input_invite" class="col-lg-2 control-label">Invite code</label>
<div class="col-lg-10">
<input type="text" class="form-control" id="input_invite" placeholder="1234abcd-1234-5678-9abc-432abc987def">
<input type="text" class="form-control" id="input_invite" name="input_invite" placeholder="1234abcd-1234-5678-9abc-432abc987def">
</div>
</div>
<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
<button type="submit" class="btn btn-default">Submit</button>
<button type="submit" class="btn btn-info">Submit</button>
</div>
</div>
</fieldset>
......
......@@ -3,7 +3,7 @@
<div class="form-group">
<label for="input_username" class="col-lg-2 control-label">User name</label>
<div class="col-lg-10">
<input type="text" class="form-control" id="input_username" placeholder="User name">
<input type="text" class="form-control" id="input_username" name="input_username" placeholder="User name">
<span class="help-block">We strongly recommend a user name with only lowercase letters and numbers for compatibility reasons.</span>
</div>
</div>
......@@ -11,22 +11,22 @@
<div class="form-group">
<label for="input_email" class="col-lg-2 control-label">E-mail address</label>
<div class="col-lg-10">
<input type="text" class="form-control" id="input_email" placeholder="E-mail address">
<input type="text" class="form-control" id="input_email" name="input_email" placeholder="E-mail address">
</div>
</div>
<div class="form-group">
<label for="input_phone" class="col-lg-2 control-label">Phone number (Optional)</label>
<div class="col-lg-10">
<input type="text" class="form-control" id="input_phone" placeholder="+15415553421">
<span class="help-block">If you provide your phone number here we will use your phone number to send you a text message with your new password. Please enter your full phone number including the country code.</span>
<input type="text" class="form-control" id="input_phone" name="input_phone" placeholder="+15415553421">
<span class="help-block">If you provide your phone number here we will use it to send you an SMS message with your password. Please enter your full phone number including the country code.</span>
</div>
</div>
<div class="form-group">
<label for="input_reason" class="col-lg-2 control-label">Reasons</label>
<div class="col-lg-10">
<textarea class="form-control" rows="10" id="input_reason"></textarea>
<textarea class="form-control" rows="10" id="input_reason" name="input_reason"><% if session.has_key? :invite %>I have an invite!<% end %></textarea>
<span class="help-block">Please read "Specifying your reasons" above.</span>
</div>
</div>
......@@ -34,13 +34,17 @@
<div class="form-group">
<label for="input_invite" class="col-lg-2 control-label">Invite code</label>
<div class="col-lg-10">
<input type="text" class="form-control" id="input_invite" placeholder="No invite code" disabled>
<% if session.has_key? :invite %>
<input type="text" class="form-control" id="input_invite" name="input_invite" value="<%= session[:invite] %>" disabled>
<% else %>
<input type="text" class="form-control" id="input_invite" name="input_invite" placeholder="No invite code" disabled>
<% end %>
</div>
</div>
<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
<button type="submit" class="btn btn-default">Submit</button>
<button type="submit" class="btn btn-info">Submit</button>
</div>
</div>
</fieldset>
......
<a href="enter-code" class="btn btn-default">Yes</a>
<a href="enter-details" class="btn btn-default">No</a>
<a href="enter-code" class="btn btn-info">Yes</a>
<a href="enter-details" class="btn btn-info">No</a>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment