FIX: User export category preferences on a deleted category. (#10573)

Tests from a1dd761bd9 were incomplete and did not test a deleted category's category_users record.
This commit is contained in:
Kane York 2020-09-01 13:22:59 -07:00 committed by GitHub
parent 899b841554
commit 26ec4fd25b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 4 deletions

View File

@ -162,7 +162,7 @@ module Jobs
.each do |cu| .each do |cu|
yield [ yield [
cu.category_id, cu.category_id,
piped_category_name(cu.category.id), piped_category_name(cu.category_id),
NotificationLevels.all[cu.notification_level], NotificationLevels.all[cu.notification_level],
cu.last_seen_at cu.last_seen_at
] ]

View File

@ -140,7 +140,6 @@ describe Jobs::ExportUserArchive do
_, csv_out = make_component_csv _, csv_out = make_component_csv
expect(csv_out).to match cat2_id.to_s expect(csv_out).to match cat2_id.to_s
puts csv_out
end end
end end
@ -200,6 +199,8 @@ describe Jobs::ExportUserArchive do
let(:subsubcategory) { Fabricate(:category_with_definition, parent_category_id: subcategory.id) } let(:subsubcategory) { Fabricate(:category_with_definition, parent_category_id: subcategory.id) }
let(:announcements) { Fabricate(:category_with_definition) } let(:announcements) { Fabricate(:category_with_definition) }
let(:deleted_category) { Fabricate(:category) }
let(:reset_at) { DateTime.parse('2017-03-01 12:00') } let(:reset_at) { DateTime.parse('2017-03-01 12:00') }
before do before do
@ -216,16 +217,19 @@ describe Jobs::ExportUserArchive do
#TopicTrackingState.publish_dismiss_new(user.id, category_id) #TopicTrackingState.publish_dismiss_new(user.id, category_id)
end end
# Set Watching First Post on announcements, Tracking on subcategory, nothing on subsubcategory # Set Watching First Post on announcements, Tracking on subcategory, Muted on deleted, nothing on subsubcategory
CategoryUser.set_notification_level_for_category(user, NotificationLevels.all[:watching_first_post], announcements.id) CategoryUser.set_notification_level_for_category(user, NotificationLevels.all[:watching_first_post], announcements.id)
CategoryUser.set_notification_level_for_category(user, NotificationLevels.all[:tracking], subcategory.id) CategoryUser.set_notification_level_for_category(user, NotificationLevels.all[:tracking], subcategory.id)
CategoryUser.set_notification_level_for_category(user, NotificationLevels.all[:muted], deleted_category.id)
deleted_category.destroy!
end end
it 'correctly exports the CategoryUser table' do it 'correctly exports the CategoryUser table' do
data, csv_out = make_component_csv data, csv_out = make_component_csv
expect(data.find { |r| r['category_id'] == category.id }).to be_nil expect(data.find { |r| r['category_id'] == category.id }).to be_nil
expect(data.length).to eq(4)
data.sort { |a, b| a['category_id'] <=> b['category_id'] } data.sort { |a, b| a['category_id'] <=> b['category_id'] }
expect(data[0][:category_id]).to eq(subcategory.id.to_s) expect(data[0][:category_id]).to eq(subcategory.id.to_s)
@ -241,6 +245,8 @@ describe Jobs::ExportUserArchive do
expect(data[2][:category_names]).to eq(announcements.name) expect(data[2][:category_names]).to eq(announcements.name)
expect(data[2][:notification_level]).to eq('watching_first_post') expect(data[2][:notification_level]).to eq('watching_first_post')
expect(data[2][:dismiss_new_timestamp]).to eq('') expect(data[2][:dismiss_new_timestamp]).to eq('')
expect(data[3][:category_names]).to eq(data[3][:category_id])
end end
end end