 
 
 # overwrites given options in the default params
-generateCreateTeamRequestParams = (opts = {}) ->
+generateCreateTeamRequestParams = (opts = {}, callback) ->
 
   url  = generateUrl
     route : '-/teams/create'

querystring = require 'querystring'

{ generateUrl
  deepObjectExtend
  generateRandomEmail
  generateRandomString

  params               = { url, body }
  defaultRequestParams = generateDefaultRequestParams params
  requestParams        = deepObjectExtend defaultRequestParams, opts

  # return without creating a team invitation
  if opts.createTeamInvitation is no
    # after deep extending object, encodes body param to a query string
    requestParams.body = querystring.stringify requestParams.body
    return callback requestParams

  slug  = opts.body ? body.slug
  email = opts.email ? body.email

  JTeamInvitation.create { groupName : slug, email }, (err, teamInvitation) ->
    expect(err).to.not.exist
    requestParams.body.teamAccessCode = teamInvitation.code
    requestParams.body                = querystring.stringify requestParams.body
    return callback requestParams


module.exports = {
