diff options
Diffstat (limited to 'SoraTests')
| -rw-r--r-- | SoraTests/ViewDerivedDataTests.swift | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/SoraTests/ViewDerivedDataTests.swift b/SoraTests/ViewDerivedDataTests.swift index fd3f1da..7c6e379 100644 --- a/SoraTests/ViewDerivedDataTests.swift +++ b/SoraTests/ViewDerivedDataTests.swift @@ -1155,6 +1155,61 @@ final class ViewDerivedDataTests: XCTestCase { // swiftlint:disable:this type_b ) } + func testBooruManagerGelbooruTagSuggestionsUseAutocompleteEndpoint() 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 gelbooruAutocompletePageCount = tokenCount( + matching: #"URLQueryItem\(name:\s*"page",\s*value:\s*"autocomplete2"\)"#, + in: tagSearchSection + ) + let gelbooruAutocompleteTypeCount = tokenCount( + matching: #"URLQueryItem\(name:\s*"type",\s*value:\s*"tag_query"\)"#, + in: tagSearchSection + ) + let safebooruFallbackCount = tokenCount( + matching: #"if\s+provider\s*==\s*\.safebooru"#, + in: tagSearchSection + ) + let gelbooruParserSelectionCount = tokenCount( + matching: + #"flavor\s*==\s*\.gelbooru,\s*provider\s*!=\s*\.safebooru\s*\{\s*"# + + #"GelbooruAutocompleteTagParser\(data:\s*data\)\.parse\(\)"#, + in: searchTagsSection + ) + + // swiftlint:disable:next prefer_nimble + XCTAssertGreaterThan( + gelbooruAutocompletePageCount, + 0, + "Gelbooru tag suggestions should use the public `autocomplete2` endpoint." + ) + // swiftlint:disable:next prefer_nimble + XCTAssertGreaterThan( + gelbooruAutocompleteTypeCount, + 0, + "Gelbooru autocomplete requests should identify tag-query lookups explicitly." + ) + // swiftlint:disable:next prefer_nimble + XCTAssertGreaterThan( + safebooruFallbackCount, + 0, + "Safebooru should stay on the XML tag API because its autocomplete endpoint redirects away." + ) + // swiftlint:disable:next prefer_nimble + XCTAssertGreaterThan( + gelbooruParserSelectionCount, + 0, + "Gelbooru autocomplete responses should decode through GelbooruAutocompleteTagParser." + ) + } + func testBooruRequestConfigurationSupportsOptionalAndCustomUserAgentHeaders() throws { let source = try loadSource(at: "Sora/Data/Booru/BooruRequestConfiguration.swift") let userAgentResolverSection = try extractFunction( |