Add age verification on sign-up (#34150)

This commit is contained in:
Eugen Rochko 2025-03-14 15:07:29 +01:00 committed by GitHub
parent 4a6cf67c46
commit d213c585ff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 268 additions and 38 deletions

View file

@ -74,12 +74,45 @@ RSpec.describe '/api/v1/accounts' do
describe 'POST /api/v1/accounts' do
subject do
post '/api/v1/accounts', headers: headers, params: { username: 'test', password: '12345678', email: 'hello@world.tld', agreement: agreement }
post '/api/v1/accounts', headers: headers, params: { username: 'test', password: '12345678', email: 'hello@world.tld', agreement: agreement, date_of_birth: date_of_birth }
end
let(:client_app) { Fabricate(:application) }
let(:token) { Doorkeeper::AccessToken.find_or_create_for(application: client_app, resource_owner: nil, scopes: 'read write', use_refresh_token: false) }
let(:agreement) { nil }
let(:date_of_birth) { nil }
context 'when age verification is enabled' do
before do
Setting.min_age = 16
end
let(:agreement) { 'true' }
context 'when date of birth is below age limit' do
let(:date_of_birth) { 13.years.ago.strftime('%d.%m.%Y') }
it 'returns http unprocessable entity' do
subject
expect(response).to have_http_status(422)
expect(response.content_type)
.to start_with('application/json')
end
end
context 'when date of birth is over age limit' do
let(:date_of_birth) { 17.years.ago.strftime('%d.%m.%Y') }
it 'creates a user', :aggregate_failures do
subject
expect(response).to have_http_status(200)
expect(response.content_type)
.to start_with('application/json')
end
end
end
context 'when given truthy agreement' do
let(:agreement) { 'true' }