2014-09-23 07:06:19 +08:00
|
|
|
# encoding: UTF-8
|
2019-04-30 08:27:42 +08:00
|
|
|
# frozen_string_literal: true
|
2014-09-23 07:06:19 +08:00
|
|
|
|
2015-10-11 17:41:23 +08:00
|
|
|
require 'rails_helper'
|
2014-09-23 07:06:19 +08:00
|
|
|
|
|
|
|
describe 'invite only' do
|
|
|
|
|
|
|
|
describe '#create invite only' do
|
|
|
|
it 'can create user via API' do
|
|
|
|
|
|
|
|
SiteSetting.invite_only = true
|
2019-04-04 00:04:05 +08:00
|
|
|
Jobs.run_immediately!
|
2014-09-23 07:06:19 +08:00
|
|
|
|
|
|
|
admin = Fabricate(:admin)
|
|
|
|
api_key = Fabricate(:api_key, user: admin)
|
|
|
|
|
2017-08-31 12:06:56 +08:00
|
|
|
post '/users.json', params: {
|
2014-09-23 07:06:19 +08:00
|
|
|
name: 'bob',
|
|
|
|
username: 'bob',
|
|
|
|
password: 'strongpassword',
|
|
|
|
email: 'bob@bob.com',
|
2020-04-07 06:55:44 +08:00
|
|
|
}, headers: {
|
|
|
|
HTTP_API_KEY: api_key.key,
|
|
|
|
HTTP_API_USERNAME: admin.username
|
2017-08-31 12:06:56 +08:00
|
|
|
}
|
2014-09-23 07:06:19 +08:00
|
|
|
|
2020-05-07 23:04:12 +08:00
|
|
|
user_id = response.parsed_body["user_id"]
|
2015-04-25 23:18:35 +08:00
|
|
|
expect(user_id).to be > 0
|
2014-09-23 07:06:19 +08:00
|
|
|
|
|
|
|
# activate and approve
|
2020-04-07 06:55:44 +08:00
|
|
|
put "/admin/users/#{user_id}/activate.json", headers: {
|
|
|
|
HTTP_API_KEY: api_key.key,
|
|
|
|
HTTP_API_USERNAME: admin.username
|
2017-08-31 12:06:56 +08:00
|
|
|
}
|
2014-09-23 07:06:19 +08:00
|
|
|
|
2020-04-07 06:55:44 +08:00
|
|
|
put "/admin/users/#{user_id}/approve.json", headers: {
|
|
|
|
HTTP_API_KEY: api_key.key,
|
|
|
|
HTTP_API_USERNAME: admin.username
|
2017-08-31 12:06:56 +08:00
|
|
|
}
|
2014-09-23 07:06:19 +08:00
|
|
|
|
|
|
|
u = User.find(user_id)
|
2015-04-25 23:18:35 +08:00
|
|
|
expect(u.active).to eq(true)
|
|
|
|
expect(u.approved).to eq(true)
|
2014-09-23 07:06:19 +08:00
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|