From 9a19ff4b3caa8d650a009636e4234f5c677b1438 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Sun, 22 Mar 2026 13:55:55 +0000 Subject: fix: restore danbooru tag suggestions --- SoraTests/ViewDerivedDataTests.swift | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'SoraTests') diff --git a/SoraTests/ViewDerivedDataTests.swift b/SoraTests/ViewDerivedDataTests.swift index ba02145..fd3f1da 100644 --- a/SoraTests/ViewDerivedDataTests.swift +++ b/SoraTests/ViewDerivedDataTests.swift @@ -1112,6 +1112,49 @@ final class ViewDerivedDataTests: XCTestCase { // swiftlint:disable:this type_b ) } + func testBooruManagerDanbooruTagSuggestionsUseJSONSearchEndpoint() throws { + let source = try loadSource(at: "Sora/Data/Booru/BooruManager.swift") + let searchTagsSection = try extractFunction( + named: "func searchTags(name: String) async -> [BooruTag]", + from: source + ) + let tagSearchSection = try extractFunction( + named: "private func url(forTagsSearch name: String) -> URL?", + from: source + ) + let danbooruJSONPathCount = tokenCount( + matching: #"case\s+\.danbooru:\s*[\s\S]*?components\.path\s*=\s*"/tags\.json""#, + in: tagSearchSection + ) + let danbooruWildcardQueryCount = tokenCount( + matching: #"URLQueryItem\(name:\s*"search\[name_matches\]""#, + in: tagSearchSection + ) + let danbooruParserSelectionCount = tokenCount( + matching: #"flavor\s*==\s*\.danbooru\s*\?\s*DanbooruTagParser\(data:\s*data\)\.parse\(\)"#, + in: searchTagsSection + ) + + // swiftlint:disable:next prefer_nimble + XCTAssertGreaterThan( + danbooruJSONPathCount, + 0, + "Danbooru tag suggestions should use the JSON `/tags.json` endpoint." + ) + // swiftlint:disable:next prefer_nimble + XCTAssertGreaterThan( + danbooruWildcardQueryCount, + 0, + "Danbooru tag suggestions should search with `search[name_matches]=*`." + ) + // swiftlint:disable:next prefer_nimble + XCTAssertGreaterThan( + danbooruParserSelectionCount, + 0, + "Danbooru tag suggestions should decode JSON through DanbooruTagParser." + ) + } + func testBooruRequestConfigurationSupportsOptionalAndCustomUserAgentHeaders() throws { let source = try loadSource(at: "Sora/Data/Booru/BooruRequestConfiguration.swift") let userAgentResolverSection = try extractFunction( -- cgit v1.2.3