2022-01-14 13:43:02 -08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-06-26 08:33:32 -07:00
|
|
|
require "rails_helper"
|
|
|
|
require "exporter"
|
2022-01-14 13:43:02 -08:00
|
|
|
|
|
|
|
RSpec.describe Exporter do
|
2022-07-09 09:54:18 -07:00
|
|
|
let(:user_params) do
|
|
|
|
{
|
|
|
|
answered_count: 144,
|
|
|
|
asked_count: 72,
|
|
|
|
comment_smiled_count: 15,
|
|
|
|
commented_count: 12,
|
|
|
|
confirmation_sent_at: 2.weeks.ago.utc,
|
|
|
|
confirmed_at: 2.weeks.ago.utc + 1.hour,
|
|
|
|
created_at: 2.weeks.ago.utc,
|
|
|
|
current_sign_in_at: 8.hours.ago.utc,
|
|
|
|
current_sign_in_ip: "198.51.100.220",
|
|
|
|
last_sign_in_at: 1.hour.ago,
|
|
|
|
last_sign_in_ip: "192.0.2.14",
|
|
|
|
locale: "en",
|
|
|
|
privacy_allow_anonymous_questions: true,
|
|
|
|
privacy_allow_public_timeline: false,
|
|
|
|
privacy_allow_stranger_answers: false,
|
|
|
|
privacy_show_in_search: true,
|
|
|
|
screen_name: "fizzyraccoon",
|
|
|
|
show_foreign_themes: true,
|
|
|
|
sign_in_count: 10,
|
|
|
|
smiled_count: 28,
|
|
|
|
profile: {
|
|
|
|
display_name: "Fizzy Raccoon",
|
|
|
|
description: "A small raccoon",
|
|
|
|
location: "Binland",
|
|
|
|
motivation_header: "",
|
|
|
|
website: "https://retrospring.net"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
let(:user) { FactoryBot.create(:user, **user_params) }
|
2022-01-14 13:43:02 -08:00
|
|
|
let(:instance) { described_class.new(user) }
|
|
|
|
|
2022-07-09 09:54:18 -07:00
|
|
|
describe "#collect_user_info" do
|
2022-01-14 13:43:02 -08:00
|
|
|
subject { instance.send(:collect_user_info) }
|
|
|
|
|
2022-07-09 09:54:18 -07:00
|
|
|
context "exporting a user" do
|
2022-01-14 13:43:02 -08:00
|
|
|
it "collects user info" do
|
|
|
|
subject
|
2022-07-09 09:54:18 -07:00
|
|
|
expect(instance.instance_variable_get(:@obj)).to eq(user_params.merge({
|
|
|
|
administrator: false,
|
|
|
|
moderator: false,
|
|
|
|
id: user.id,
|
|
|
|
updated_at: user.updated_at,
|
|
|
|
profile_header: user.profile_header,
|
|
|
|
profile_header_file_name: nil,
|
|
|
|
profile_header_h: nil,
|
|
|
|
profile_header_w: nil,
|
|
|
|
profile_header_x: nil,
|
|
|
|
profile_header_y: nil,
|
|
|
|
profile_picture_file_name: nil,
|
|
|
|
profile_picture_h: nil,
|
|
|
|
profile_picture_w: nil,
|
|
|
|
profile_picture_x: nil,
|
|
|
|
profile_picture_y: nil
|
|
|
|
}))
|
2022-01-14 13:43:02 -08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2022-07-09 10:22:05 -07:00
|
|
|
|
|
|
|
describe "#collect_smiles" do
|
|
|
|
let!(:smiles) { FactoryBot.create_list(:smile, 25, user: user) }
|
|
|
|
|
|
|
|
subject { instance.send(:collect_smiles) }
|
|
|
|
|
|
|
|
context "exporting a user" do
|
|
|
|
it "collects reactions" do
|
|
|
|
subject
|
|
|
|
expect(instance.instance_variable_get(:@obj)[:smiles]).to eq(smiles.map do |s|
|
|
|
|
{
|
|
|
|
id: s.id,
|
2022-07-09 10:51:03 -07:00
|
|
|
created_at: s.reload.created_at,
|
2022-07-09 10:22:05 -07:00
|
|
|
answer: {
|
|
|
|
comment_count: s.parent.comment_count,
|
|
|
|
content: s.parent.content,
|
2022-07-09 10:51:03 -07:00
|
|
|
created_at: s.parent.reload.created_at,
|
2022-07-09 10:22:05 -07:00
|
|
|
id: s.parent.id,
|
|
|
|
question: {
|
|
|
|
answer_count: s.parent.question.answer_count,
|
|
|
|
author_is_anonymous: s.parent.question.author_is_anonymous,
|
|
|
|
content: s.parent.question.content,
|
2022-07-09 10:51:03 -07:00
|
|
|
created_at: s.parent.question.reload.created_at,
|
2022-07-09 10:22:05 -07:00
|
|
|
id: s.parent.question.id,
|
|
|
|
user: nil # we're not populating this in the factory
|
|
|
|
},
|
|
|
|
smile_count: s.parent.smile_count
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2022-01-14 13:43:02 -08:00
|
|
|
end
|