From a566c734fc6b225a19826b1bfe02cf885ec2da18 Mon Sep 17 00:00:00 2001 From: Thomas De Leon <3507743+tdeleon@users.noreply.github.com> Date: Mon, 29 Jan 2024 16:26:57 -0800 Subject: [PATCH] #52: Enhance validation methods for query items & headers (#53) --- Sources/URLMock/URLRequestValidation.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/URLMock/URLRequestValidation.swift b/Sources/URLMock/URLRequestValidation.swift index 5382a7a..d95c987 100644 --- a/Sources/URLMock/URLRequestValidation.swift +++ b/Sources/URLMock/URLRequestValidation.swift @@ -44,17 +44,17 @@ extension URLRequest { /// Validates the request query items match the provided query items /// - Parameter match: The expected query items /// - /// This method validates that the query items match the expected using `XCTAssertEqual()` + /// This method validates that the query items match the expected using `XCTAssertEqual()`. Sets are used so order is not required to match. public func validateQueryItems(match expected: [URLQueryItem]) throws { let query = try XCTUnwrap(queryItems) - XCTAssertEqual(query, expected) + XCTAssertEqual(Set(query), Set(expected)) } /// Validates the request query items contain and/or do not contain the provided query item names /// - Parameters: /// - contain: The names that the query items *must* include /// - doNotContain: The names that the query items *must not* include - public func validateQueryItemNames(contain: [String], doNotContain: [String] = []) throws { + public func validateQueryItemNames(contain: [String] = [], doNotContain: [String] = []) throws { let query = try XCTUnwrap(queryItems) let names = Set(query.map(\.name)) XCTAssertTrue(names.isSuperset(of: contain)) @@ -134,7 +134,7 @@ extension URLRequest { /// - Parameters: /// - contain: Header names that `allHTTPHeaderFields` *must* contain /// - doNotContain: Header names that `allHTTPHeaderFields` *must not* contain - public func validateHeaderNames(contain: [String], doNotContain: [String] = []) { + public func validateHeaderNames(contain: [String] = [], doNotContain: [String] = []) { let names = Set(allHTTPHeaderFields?.map(\.key) ?? []) XCTAssertTrue(names.isSuperset(of: contain)) XCTAssertTrue(names.intersection(doNotContain).isEmpty)