Fix user gallery job pagination logic and add test for empty submission pages

- Updated pagination condition in `user_gallery_job.rb` to break when the number of pages is less than or equal to the current page.
- Added a new test case in `user_gallery_job_spec.rb` to handle scenarios with empty submission pages, ensuring no new records are created.
- Introduced a fixture file `api_search_empty_submissions.json` to simulate API responses with no submissions.
This commit is contained in:
Dylan Knutson
2025-01-20 16:25:26 +00:00
parent b1cdca1513
commit d8ffd9bde1
3 changed files with 40 additions and 1 deletions

View File

@@ -62,7 +62,7 @@ module Domain::Inkbunny::Job
break
end
rid = result[:rid] || raise("no rid")
break if result[:num_pages] == page
break if result[:num_pages] <= page
page += 1
end

View File

@@ -17,6 +17,33 @@ RSpec.describe Domain::Inkbunny::Job::UserGalleryJob do
expect(user.reload.scanned_gallery_at).to be_within(1.second).of(at)
end
it "works with empty submission pages" do
HttpClientMockHelpers.init_http_client_mock(
http_client_mock,
[
{
uri:
"https://inkbunny.net/api_search.php?submissions_per_page=100&page=1&get_rid=yes&orderby=create_datetime&user_id=26540&keywords=no",
status_code: 200,
method: :post,
content_type: "application/json",
contents:
SpecUtil.read_fixture_file(
"domain/inkbunny/job/api_search_empty_submissions.json",
),
caused_by_entry: nil,
},
],
)
expect { perform_now(args) }.to(
change(Domain::Inkbunny::Post, :count)
.by(0)
.and(change(Domain::Inkbunny::File, :count).by(0))
.and(change(Domain::Inkbunny::User, :count).by(0)),
)
end
context "when fetching posts" do
let!(:log_entries) do
HttpClientMockHelpers.init_http_client_mock(

View File

@@ -0,0 +1,12 @@
{
"sid": "9B5BPQqTZ,Mj-nYbL2tuIPoO,b",
"results_count_all": "0",
"results_count_thispage": 0,
"pages_count": 0,
"page": 0,
"user_location": "",
"rid": "520e18fe15",
"rid_ttl": "15 minutes",
"search_params": [],
"submissions": []
}