 # ------------------------------------------------------------------------
 # Utilities
 
+fillSignupForm = (user) ->
+  # Prepare user data.
+  data = {}
+  data[FIELD_MAIL]       = user.email
+  data[FIELD_PASS]       = user.password
+  data[FIELD_PASS_2]     = user.password
+  data[FIELD_FIRST_NAME] = user.first_name
+  data[FIELD_BIRTHDATE]  = user.dob.format "MM/DD/YYYY"
+
+  # Fill in the registration form.
+  casper.fill FORM, data
+  return
+
 # Finds user uid on the profile edit page ans saves it to global variable.
 saveUserUid = ->
   uid = casper.getCurrentUrl().match(/\/user\/([0-9]+)\/edit$/)[1]

# Sometimes SSO server response takes long.
casper.options.waitTimeout = 10000

# Generate user.
system = require 'system';
# Temporary. Will be replaced with generated user when SSO registration is ready.
user =
  email: system.env.DS_CA_USER
  password: system.env.DS_CA_PASS
uid = false

# ------------------------------------------------------------------------
# Test login form

  # Go to the edit profile page.
  # We don't know new uid yet, but user/register will redirect to the page.
  casper.thenOpen "#{url}/user/register"
  casper.then -> saveUserUid()

  # Test the nid is present
  test.assertTruthy uid, "User is found."

  # Cleanup after success.
  casper.then ->
