diff options
Diffstat (limited to 'SoraTests')
| -rw-r--r-- | SoraTests/ViewDerivedDataTests.swift | 43 |
1 files changed, 43 insertions, 0 deletions
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]=<term>*`." + ) + // 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( |