@ -850,6 +850,7 @@ RSpec.describe UsersController, type: :request do
name : " new user " ,
email : " new_user@example.com " ,
role : " data_coordinator " ,
phone : " 12345678910 " ,
} ,
}
end
@ -938,6 +939,54 @@ RSpec.describe UsersController, type: :request do
expect ( page ) . to have_content ( I18n . t ( " activerecord.errors.models.user.attributes.email.blank " ) )
end
end
context " when validating telephone numbers " do
let ( :params ) do
{
" user " : {
phone : ,
} ,
}
end
context " when telephone number is not numeric " do
let ( :phone ) { " randomstring " }
it " validates telephone number " do
request
expect ( response ) . to have_http_status ( :unprocessable_entity )
expect ( page ) . to have_content ( I18n . t ( " activerecord.errors.models.user.attributes.phone.invalid " ) )
end
end
context " when telephone number is shorter than 11 digits " do
let ( :phone ) { " 123 " }
it " validates telephone number " do
request
expect ( response ) . to have_http_status ( :unprocessable_entity )
expect ( page ) . to have_content ( I18n . t ( " activerecord.errors.models.user.attributes.phone.invalid " ) )
end
end
context " when telephone number is in correct format " do
let ( :phone ) { " 012345678919 " }
it " validates telephone number " do
request
expect ( page ) . not_to have_content ( I18n . t ( " activerecord.errors.models.user.attributes.phone.invalid " ) )
end
end
context " when telephone number is in correct format and includes + " do
let ( :phone ) { " +12345678919 " }
it " validates telephone number " do
request
expect ( page ) . not_to have_content ( I18n . t ( " activerecord.errors.models.user.attributes.phone.invalid " ) )
end
end
end
end
describe " # new " do
@ -1273,6 +1322,7 @@ RSpec.describe UsersController, type: :request do
expect ( page ) . to have_field ( " user[name] " )
expect ( page ) . to have_field ( " user[email] " )
expect ( page ) . to have_field ( " user[role] " )
expect ( page ) . to have_field ( " user[phone] " )
end
it " allows setting the role to `support` " do
@ -1571,6 +1621,7 @@ RSpec.describe UsersController, type: :request do
name : " new user " ,
email : ,
role : " data_coordinator " ,
phone : " 12345612456 " ,
organisation_id : organisation . id ,
} ,
}
@ -1602,6 +1653,7 @@ RSpec.describe UsersController, type: :request do
name : " " ,
email : " " ,
role : " " ,
phone : " " ,
organisation_id : nil ,
} ,
}
@ -1617,6 +1669,7 @@ RSpec.describe UsersController, type: :request do
expect ( page ) . to have_content ( I18n . t ( " activerecord.errors.models.user.attributes.name.blank " ) )
expect ( page ) . to have_content ( I18n . t ( " activerecord.errors.models.user.attributes.email.blank " ) )
expect ( page ) . to have_content ( I18n . t ( " activerecord.errors.models.user.attributes.organisation_id.blank " ) )
expect ( page ) . to have_content ( I18n . t ( " activerecord.errors.models.user.attributes.phone.blank " ) )
end
end