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