2021-04-20 19:58:19 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
describe CustomWizard::StepSerializer do
|
2024-10-16 13:52:03 +02:00
|
|
|
fab!(:user)
|
2021-09-07 14:06:13 +02:00
|
|
|
let(:wizard_template) { get_wizard_fixture("wizard") }
|
|
|
|
let(:required_data_json) { get_wizard_fixture("step/required_data") }
|
2021-04-20 19:58:19 +02:00
|
|
|
|
|
|
|
before do
|
|
|
|
CustomWizard::Template.save(wizard_template, skip_jobs: true)
|
|
|
|
@wizard = CustomWizard::Builder.new("super_mega_fun_wizard", user).build
|
|
|
|
end
|
|
|
|
|
2024-10-16 13:52:03 +02:00
|
|
|
it "should return basic step attributes" do
|
|
|
|
json_array =
|
|
|
|
ActiveModel::ArraySerializer.new(
|
|
|
|
@wizard.steps,
|
|
|
|
each_serializer: described_class,
|
|
|
|
scope: Guardian.new(user),
|
|
|
|
).as_json
|
2021-09-14 05:33:16 +02:00
|
|
|
expect(json_array[0][:title]).to eq("Text")
|
2021-04-20 19:58:19 +02:00
|
|
|
expect(json_array[0][:description]).to eq("<p>Text inputs!</p>")
|
|
|
|
expect(json_array[1][:index]).to eq(1)
|
|
|
|
end
|
|
|
|
|
2024-10-16 13:52:03 +02:00
|
|
|
it "should return fields" do
|
|
|
|
json_array =
|
|
|
|
ActiveModel::ArraySerializer.new(
|
|
|
|
@wizard.steps,
|
|
|
|
each_serializer: described_class,
|
|
|
|
scope: Guardian.new(user),
|
|
|
|
).as_json
|
2022-01-31 10:41:14 +01:00
|
|
|
|
|
|
|
expect(json_array[0][:fields].length).to eq(@wizard.steps[0].fields.length)
|
2021-04-20 19:58:19 +02:00
|
|
|
end
|
|
|
|
|
2024-10-16 13:52:03 +02:00
|
|
|
context "with required data" do
|
2021-04-20 19:58:19 +02:00
|
|
|
before do
|
2021-11-09 15:57:33 +01:00
|
|
|
enable_subscription("standard")
|
2024-10-16 13:52:03 +02:00
|
|
|
wizard_template["steps"][0]["required_data"] = required_data_json["required_data"]
|
|
|
|
wizard_template["steps"][0]["required_data_message"] = required_data_json[
|
|
|
|
"required_data_message"
|
|
|
|
]
|
2021-04-20 19:58:19 +02:00
|
|
|
CustomWizard::Template.save(wizard_template)
|
|
|
|
@wizard = CustomWizard::Builder.new("super_mega_fun_wizard", user).build
|
|
|
|
end
|
|
|
|
|
2024-10-16 13:52:03 +02:00
|
|
|
it "should return permitted attributes" do
|
|
|
|
json_array =
|
|
|
|
ActiveModel::ArraySerializer.new(
|
|
|
|
@wizard.steps,
|
|
|
|
each_serializer: described_class,
|
|
|
|
scope: Guardian.new(user),
|
|
|
|
).as_json
|
2021-04-20 19:58:19 +02:00
|
|
|
expect(json_array[0][:permitted]).to eq(false)
|
|
|
|
expect(json_array[0][:permitted_message]).to eq("Missing required data")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|