0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-25 02:30:28 +01:00
discourse-custom-wizard/spec/serializers/custom_wizard/submission_serializer_spec.rb
Angus McLeod 35021eb176 DEV: Integrate subscription gem classes in rspec suite
I've tweaked the subscription client gem so we can just use the gem's models and tables in this plugin's rspec, which makes duplicating and stubbing them unnecessary.

See further https://github.com/paviliondev/discourse_subscription_client
2023-11-25 13:16:55 +01:00

59 Zeilen
2 KiB
Ruby

# frozen_string_literal: true
require_relative '../../plugin_helper'
describe CustomWizard::SubmissionSerializer do
fab!(:user1) { Fabricate(:user) }
fab!(:user2) { Fabricate(:user) }
let(:template_json) {
JSON.parse(File.open(
"#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/wizard.json"
).read)
}
before do
CustomWizard::Template.save(template_json, skip_jobs: true)
wizard = CustomWizard::Wizard.create(template_json["id"], user1)
CustomWizard::Submission.new(wizard, step_1_field_1: "I am user1 submission", submitted_at: Time.now.iso8601).save
wizard = CustomWizard::Wizard.create(template_json["id"], user2)
CustomWizard::Submission.new(wizard, step_1_field_1: "I am user2 submission", submitted_at: Time.now.iso8601).save
end
it 'should return submission attributes' do
wizard = CustomWizard::Wizard.create(template_json["id"])
list = CustomWizard::Submission.list(wizard, page: 0, order_by: 'id')
json_array = ActiveModel::ArraySerializer.new(
list.submissions,
each_serializer: described_class
).as_json
expect(json_array.length).to eq(2)
expect(json_array[0][:id].present?).to eq(true)
expect(json_array[0][:submitted_at].present?).to eq(true)
expect(json_array[0][:user]).to eq(BasicUserSerializer.new(user2, root: false).as_json)
expect(json_array[1][:user]).to eq(BasicUserSerializer.new(user1, root: false).as_json)
end
it "should return field values, types and labels" do
wizard = CustomWizard::Wizard.create(template_json["id"])
list = CustomWizard::Submission.list(wizard, page: 0, order_by: 'id')
json_array = ActiveModel::ArraySerializer.new(
list.submissions,
each_serializer: described_class
).as_json
expect(json_array.length).to eq(2)
expect(json_array[0][:fields].as_json).to eq({
"step_1_field_1": {
"value": "I am user2 submission",
"type": "text",
"label": "Text"
}
}.as_json)
end
end