|
233 | 233 | expect { sync_command.all }.to output(String).to_stdout |
234 | 234 | end |
235 | 235 | end |
| 236 | + |
| 237 | + describe "#cleanup" do |
| 238 | + let(:options) { { verbose: [true], dry_run: false } } |
| 239 | + let(:mod1) { Icarus::Mod::Tools::Modinfo.new({ name: "DupeMod", author: "Author1", description: "Test" }, id: "mod1", updated: Time.now - 3600) } |
| 240 | + let(:mod2) { Icarus::Mod::Tools::Modinfo.new({ name: "DupeMod", author: "Author1", description: "Test" }, id: "mod2", updated: Time.now) } |
| 241 | + let(:mod3) { Icarus::Mod::Tools::Modinfo.new({ name: "UniqueMod", author: "Author2", description: "Test" }, id: "mod3", updated: Time.now) } |
| 242 | + let(:tool1) { Icarus::Mod::Tools::Toolinfo.new({ name: "DupeTool", author: "Author1", description: "Test" }, id: "tool1", updated: Time.now - 3600) } |
| 243 | + let(:tool2) { Icarus::Mod::Tools::Toolinfo.new({ name: "DupeTool", author: "Author1", description: "Test" }, id: "tool2", updated: Time.now) } |
| 244 | + |
| 245 | + before do |
| 246 | + allow(firestore_double).to receive(:mods).and_return([mod1, mod2, mod3]) |
| 247 | + allow(firestore_double).to receive(:tools).and_return([tool1, tool2]) |
| 248 | + allow(firestore_double).to receive(:delete).and_return(true) |
| 249 | + end |
| 250 | + |
| 251 | + it "identifies duplicate mods by name and author" do |
| 252 | + expect { sync_command.cleanup }.to output(/Found 1 duplicate mod/).to_stdout |
| 253 | + end |
| 254 | + |
| 255 | + it "identifies duplicate tools by name and author" do |
| 256 | + expect { sync_command.cleanup }.to output(/Found 1 duplicate tool/).to_stdout |
| 257 | + end |
| 258 | + |
| 259 | + it "keeps the most recently updated entry" do |
| 260 | + expect { sync_command.cleanup }.to output(/Keeping.*mod2/).to_stdout |
| 261 | + end |
| 262 | + |
| 263 | + it "deletes older duplicate entries" do |
| 264 | + sync_command.cleanup |
| 265 | + expect(firestore_double).to have_received(:delete).with(:mod, mod1) |
| 266 | + expect(firestore_double).to have_received(:delete).with(:tool, tool1) |
| 267 | + end |
| 268 | + |
| 269 | + it "does not delete unique entries" do |
| 270 | + sync_command.cleanup |
| 271 | + expect(firestore_double).not_to have_received(:delete).with(:mod, mod3) |
| 272 | + end |
| 273 | + |
| 274 | + context "when no duplicates exist" do |
| 275 | + before do |
| 276 | + allow(firestore_double).to receive(:mods).and_return([mod3]) |
| 277 | + allow(firestore_double).to receive(:tools).and_return([]) |
| 278 | + end |
| 279 | + |
| 280 | + it "reports no duplicates found" do |
| 281 | + expect { sync_command.cleanup }.to output(/No duplicate mods found/).to_stdout |
| 282 | + end |
| 283 | + end |
| 284 | + |
| 285 | + context "with dry_run enabled" do |
| 286 | + let(:options) { { verbose: [true], dry_run: true } } |
| 287 | + |
| 288 | + it "does not delete any entries" do |
| 289 | + expect { sync_command.cleanup }.to output(/Dry run/).to_stdout |
| 290 | + expect(firestore_double).not_to have_received(:delete) |
| 291 | + end |
| 292 | + |
| 293 | + it "shows what would be deleted" do |
| 294 | + expect { sync_command.cleanup }.to output(/Would delete.*mod1/).to_stdout |
| 295 | + end |
| 296 | + end |
| 297 | + end |
236 | 298 | end |
0 commit comments