Finish the test cases for MangaDex::Queue

This commit is contained in:
Alex Ling 2020-03-04 01:52:17 +00:00
parent 1abdac2fdd
commit 54206bc6ac

View File

@ -9,16 +9,24 @@ describe Queue do
end end
end end
it "pops nil when empty" do
with_queue do |queue|
queue.pop.should be_nil
end
end
it "inserts multiple jobs" do it "inserts multiple jobs" do
with_queue do |queue| with_queue do |queue|
j1 = Job.new "1", "1", "title", "manga_title", JobStatus::Error, j1 = Job.new "1", "1", "title", "manga_title", JobStatus::Error,
Time.utc Time.utc
j2 = Job.new "2", "2", "title", "manga_title", JobStatus::Completed, j2 = Job.new "2", "2", "title", "manga_title", JobStatus::Completed,
Time.utc Time.utc
j3 = Job.new "0", "0", "title", "manga_title", JobStatus::Pending, j3 = Job.new "3", "3", "title", "manga_title", JobStatus::Pending,
Time.utc Time.utc
count = queue.push [j1, j2, j3] j4 = Job.new "4", "4", "title", "manga_title",
count.should eq 3 JobStatus::Downloading, Time.utc
count = queue.push [j1, j2, j3, j4]
count.should eq 4
end end
end end
@ -26,7 +34,64 @@ describe Queue do
with_queue do |queue| with_queue do |queue|
job = queue.pop job = queue.pop
job.should_not be_nil job.should_not be_nil
job.not_nil!.id.should eq "0" job.not_nil!.id.should eq "3"
end
end
it "correctly counts jobs" do
with_queue do |queue|
queue.count.should eq 4
end
end
it "deletes job" do
with_queue do |queue|
queue.delete "4"
queue.count.should eq 3
end
end
it "sets status" do
with_queue do |queue|
job = queue.pop.not_nil!
queue.set_status JobStatus::Downloading, job
job = queue.pop
job.should_not be_nil
job.not_nil!.status.should eq JobStatus::Downloading
end
end
it "sets number of pages" do
with_queue do |queue|
job = queue.pop.not_nil!
queue.set_pages 100, job
job = queue.pop
job.should_not be_nil
job.not_nil!.pages.should eq 100
end
end
it "adds fail/success counts" do
with_queue do |queue|
job = queue.pop.not_nil!
queue.add_success job
queue.add_success job
queue.add_fail job
job = queue.pop
job.should_not be_nil
job.not_nil!.success_count.should eq 2
job.not_nil!.fail_count.should eq 1
end
end
it "appends status message" do
with_queue do |queue|
job = queue.pop.not_nil!
queue.add_message "hello", job
queue.add_message "world", job
job = queue.pop
job.should_not be_nil
job.not_nil!.status_message.should eq "\nhello\nworld"
end end
end end