make the export worker create a *real* notification and add specs for it
This commit is contained in:
parent
17783fbf38
commit
e1bdb1324f
|
@ -0,0 +1,5 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
# NOTE: `target` is not really used for this notification, but it should be of type `User::DataExport`
|
||||||
|
class Notification::DataExported < Notification
|
||||||
|
end
|
|
@ -0,0 +1,5 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
# stub model to nicely allow for data export notifications, do NOT use this directly!
|
||||||
|
class User::DataExport < User
|
||||||
|
end
|
|
@ -0,0 +1,8 @@
|
||||||
|
.media.notification
|
||||||
|
.notification__icon
|
||||||
|
%i.fa.fa-2x.fa-fw.fa-download
|
||||||
|
.media-body
|
||||||
|
%h6.media-heading.notification__user
|
||||||
|
= t(".heading")
|
||||||
|
.notification__text
|
||||||
|
= t(".text_html", settings_export: link_to(t(".settings_export"), settings_export_path))
|
|
@ -1,4 +1,7 @@
|
||||||
require 'exporter'
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "exporter"
|
||||||
|
|
||||||
class ExportWorker
|
class ExportWorker
|
||||||
include Sidekiq::Worker
|
include Sidekiq::Worker
|
||||||
|
|
||||||
|
@ -6,11 +9,16 @@ class ExportWorker
|
||||||
|
|
||||||
# @param user_id [Integer] the user id
|
# @param user_id [Integer] the user id
|
||||||
def perform(user_id)
|
def perform(user_id)
|
||||||
exporter = Exporter.new User.find(user_id)
|
user = User.find(user_id)
|
||||||
|
|
||||||
|
exporter = Exporter.new(user)
|
||||||
exporter.export
|
exporter.export
|
||||||
question = Question.create(content: "Your #{APP_CONFIG['site_name']} data export is ready! You can download it " +
|
|
||||||
"from the settings page under the \"Export\" tab.", author_is_anonymous: true,
|
Notification::DataExported.create(
|
||||||
author_identifier: "retrospring_exporter")
|
target_id: user.id,
|
||||||
Inbox.create(user_id: user_id, question_id: question.id, new: true)
|
target_type: "User::DataExport",
|
||||||
|
recipient: user,
|
||||||
|
new: true
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -327,6 +327,10 @@ en:
|
||||||
link_text: "their answer"
|
link_text: "their answer"
|
||||||
other:
|
other:
|
||||||
link_text_html: "%{user}'s answer"
|
link_text_html: "%{user}'s answer"
|
||||||
|
dataexport:
|
||||||
|
heading: "Your data export is ready"
|
||||||
|
text_html: "Head over to %{settings_export} to download it."
|
||||||
|
settings_export: "the settings page"
|
||||||
reaction:
|
reaction:
|
||||||
heading_html: "%{user} smiled %{type} %{time} ago"
|
heading_html: "%{user} smiled %{type} %{time} ago"
|
||||||
answer:
|
answer:
|
||||||
|
@ -396,7 +400,7 @@ en:
|
||||||
<p>The data is inside a <code>.zip</code> archive that contains some JSON files.
|
<p>The data is inside a <code>.zip</code> archive that contains some JSON files.
|
||||||
The archive also contains a copy of your profile picture and header picture in all sizes.</p>
|
The archive also contains a copy of your profile picture and header picture in all sizes.</p>
|
||||||
<p>Please note that you can only export your data once a week. Exporting your data
|
<p>Please note that you can only export your data once a week. Exporting your data
|
||||||
will take a while, so please be patient. You will receive a question once exporting
|
will take a while, so please be patient. You will receive a notification once exporting
|
||||||
is done.</p>
|
is done.</p>
|
||||||
export: "Export"
|
export: "Export"
|
||||||
export_url:
|
export_url:
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "rails_helper"
|
||||||
|
|
||||||
|
describe ExportWorker do
|
||||||
|
let(:user) { FactoryBot.create(:user) }
|
||||||
|
|
||||||
|
describe "#perform" do
|
||||||
|
let(:exporter_double) { double("Exporter") }
|
||||||
|
|
||||||
|
before do
|
||||||
|
# stub away the testing of the exporter itself since it is done in lib/exporter_spec
|
||||||
|
allow(exporter_double).to receive(:export)
|
||||||
|
allow(Exporter).to receive(:new).and_return(exporter_double)
|
||||||
|
end
|
||||||
|
|
||||||
|
subject { described_class.new.perform(user.id) }
|
||||||
|
|
||||||
|
it "creates an exported notification" do
|
||||||
|
expect { subject }.to change { Notification::DataExported.count }.by(1)
|
||||||
|
|
||||||
|
notification = Notification::DataExported.last
|
||||||
|
expect(notification.target_id).to eq(user.id)
|
||||||
|
expect(notification.target_type).to eq("User::DataExport")
|
||||||
|
expect(notification.recipient).to eq(user)
|
||||||
|
expect(notification.new).to be true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue