2021-03-11 07:30:15 +01:00
|
|
|
# frozen_string_literal: true
|
2020-11-08 04:24:20 +01:00
|
|
|
|
|
|
|
describe CustomWizard::AdminCustomFieldsController do
|
|
|
|
fab!(:admin_user) { Fabricate(:user, admin: true) }
|
2021-09-07 14:06:13 +02:00
|
|
|
let(:custom_field_json) { get_wizard_fixture("custom_field/custom_fields") }
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2020-11-08 04:24:20 +01:00
|
|
|
before do
|
2023-09-28 14:47:22 +02:00
|
|
|
define_client_classes
|
2020-11-08 04:24:20 +01:00
|
|
|
custom_field_json['custom_fields'].each do |field_json|
|
|
|
|
CustomWizard::CustomField.new(nil, field_json).save
|
|
|
|
end
|
|
|
|
sign_in(admin_user)
|
|
|
|
end
|
|
|
|
|
2021-06-08 13:39:49 +02:00
|
|
|
it "returns the full list of custom fields" do
|
2020-11-08 04:24:20 +01:00
|
|
|
get "/admin/wizards/custom-fields.json"
|
2022-05-31 13:16:28 +02:00
|
|
|
expect(response.parsed_body["custom_fields"].length).to be > 2
|
2020-11-08 04:24:20 +01:00
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2020-11-10 01:56:11 +01:00
|
|
|
it "saves custom fields" do
|
|
|
|
topic_field = CustomWizard::CustomField.find_by_name('topic_field_1')
|
|
|
|
topic_field_json = topic_field.as_json
|
|
|
|
topic_field_json['type'] = 'string'
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2020-11-10 01:56:11 +01:00
|
|
|
put "/admin/wizards/custom-fields.json", params: {
|
|
|
|
custom_field: topic_field_json
|
|
|
|
}
|
2020-11-08 04:24:20 +01:00
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(
|
2020-11-10 01:56:11 +01:00
|
|
|
CustomWizard::CustomField.find_by_name('topic_field_1').type
|
2020-11-08 04:24:20 +01:00
|
|
|
).to eq('string')
|
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2020-11-10 01:56:11 +01:00
|
|
|
it "destroys custom fields" do
|
|
|
|
topic_field = custom_field_json['custom_fields'][0]
|
|
|
|
delete "/admin/wizards/custom-fields/#{topic_field["name"]}.json"
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(
|
|
|
|
CustomWizard::CustomField.exists?('topic_field_1')
|
|
|
|
).to eq(false)
|
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
end
|