0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-14 05:52:52 +01:00
discourse-custom-wizard/spec/serializers/custom_wizard/wizard_field_serializer_spec.rb

34 Zeilen
1,1 KiB
Ruby

2020-11-03 01:24:20 +01:00
# frozen_string_literal: true
describe CustomWizard::FieldSerializer do
fab!(:user) { Fabricate(:user) }
2021-09-07 14:06:13 +02:00
let(:template) { get_wizard_fixture("wizard") }
2020-11-03 01:24:20 +01:00
before do
2021-09-07 14:06:13 +02:00
CustomWizard::Template.save(template, skip_jobs: true)
2020-11-03 01:24:20 +01:00
@wizard = CustomWizard::Builder.new("super_mega_fun_wizard", user).build
end
2021-03-11 07:30:15 +01:00
2020-11-03 01:24:20 +01:00
it "should return basic field attributes" do
json_array = ActiveModel::ArraySerializer.new(
@wizard.steps.first.fields,
each_serializer: CustomWizard::FieldSerializer,
scope: Guardian.new(user)
).as_json
expect(json_array.size).to eq(@wizard.steps.first.fields.size)
2020-11-03 01:24:20 +01:00
expect(json_array[0][:label]).to eq("<p>Text</p>")
expect(json_array[0][:description]).to eq("Text field description.")
2022-03-25 17:08:24 +01:00
expect(json_array[2][:index]).to eq(2)
2020-11-03 01:24:20 +01:00
end
2021-03-11 07:30:15 +01:00
2020-11-03 01:24:20 +01:00
it "should return optional field attributes" do
json_array = ActiveModel::ArraySerializer.new(
@wizard.steps.second.fields,
each_serializer: CustomWizard::FieldSerializer,
scope: Guardian.new(user)
).as_json
expect(json_array[0][:format]).to eq("YYYY-MM-DD")
end
2021-03-11 07:30:15 +01:00
end