2021-03-11 07:30:15 +01:00
|
|
|
# frozen_string_literal: true
|
2020-11-30 22:20:10 +01:00
|
|
|
require_relative '../../../plugin_helper'
|
2020-11-03 01:24:20 +01:00
|
|
|
|
|
|
|
describe CustomWizard::AdminSubmissionsController do
|
2021-03-11 07:30:15 +01:00
|
|
|
fab!(:admin_user) { Fabricate(:user, admin: true) }
|
|
|
|
fab!(:user1) { Fabricate(:user) }
|
|
|
|
fab!(:user2) { Fabricate(:user) }
|
2021-06-17 09:50:22 +02:00
|
|
|
fab!(:user3) { Fabricate(:user) }
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2021-09-07 14:06:13 +02:00
|
|
|
let(:template) { get_wizard_fixture("wizard") }
|
2021-06-23 08:13:58 +02:00
|
|
|
let(:template_2) {
|
|
|
|
temp = template.dup
|
|
|
|
temp["id"] = "super_mega_fun_wizard_2"
|
|
|
|
temp
|
|
|
|
}
|
|
|
|
|
2020-11-03 01:24:20 +01:00
|
|
|
before do
|
|
|
|
CustomWizard::Template.save(template, skip_jobs: true)
|
2021-06-17 09:50:22 +02:00
|
|
|
CustomWizard::Template.save(template_2, skip_jobs: true)
|
|
|
|
|
|
|
|
wizard1 = CustomWizard::Wizard.create(template["id"], user1)
|
|
|
|
wizard2 = CustomWizard::Wizard.create(template["id"], user2)
|
|
|
|
wizard3 = CustomWizard::Wizard.create(template_2["id"], user3)
|
|
|
|
|
|
|
|
CustomWizard::Submission.new(wizard1, step_1_field_1: "I am a user1's submission").save
|
|
|
|
CustomWizard::Submission.new(wizard2, step_1_field_1: "I am a user2's submission").save
|
|
|
|
CustomWizard::Submission.new(wizard3, step_1_field_1: "I am a user3's submission").save
|
|
|
|
|
2020-11-03 01:24:20 +01:00
|
|
|
sign_in(admin_user)
|
|
|
|
end
|
|
|
|
|
2021-06-17 09:50:22 +02:00
|
|
|
it "returns a list of wizards" do
|
2020-11-03 01:24:20 +01:00
|
|
|
get "/admin/wizards/submissions.json"
|
2021-06-23 08:13:58 +02:00
|
|
|
expect(response.parsed_body.length).to eq(2)
|
2020-11-03 01:24:20 +01:00
|
|
|
expect(response.parsed_body.first['id']).to eq(template['id'])
|
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2021-06-17 09:50:22 +02:00
|
|
|
it "returns users' submissions for a wizard" do
|
2020-11-03 01:24:20 +01:00
|
|
|
get "/admin/wizards/submissions/#{template['id']}.json"
|
|
|
|
expect(response.parsed_body['submissions'].length).to eq(2)
|
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2021-06-17 09:50:22 +02:00
|
|
|
it "downloads submissions" do
|
|
|
|
get "/admin/wizards/submissions/#{template_2['id']}/download"
|
|
|
|
expect(response.parsed_body.length).to eq(1)
|
2020-11-03 01:24:20 +01:00
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
end
|