Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compare query parameters (ignoring order) #61

Open
marcelofabri opened this issue Sep 6, 2016 · 0 comments
Open

Compare query parameters (ignoring order) #61

marcelofabri opened this issue Sep 6, 2016 · 0 comments

Comments

@marcelofabri
Copy link

I think it'd be useful to have a matcher (or change uri) to compare query parameters ignoring their order. I was able to implement that with a custom matcher:

func uriWithQuery(uriString:String) -> (request:NSURLRequest) -> Bool {
    return { (request:NSURLRequest) in
        if uri(uriString)(request: request) {
            return true
        }

        if let components = NSURLComponents(string: uriString),
            requestComponents = request.URL.flatMap({ NSURLComponents.init(URL: $0, resolvingAgainstBaseURL: false)}) {
            let componentsWithoutParams = components.copy() as! NSURLComponents
            componentsWithoutParams.query = nil

            let requestComponentsWithoutParams = requestComponents.copy() as! NSURLComponents
            requestComponentsWithoutParams.query = nil

            if requestComponentsWithoutParams.URL == componentsWithoutParams.URL {
                return requestComponents.queryItems.flatMap(Set.init) == components.queryItems.flatMap(Set.init)
            }
        }

        return false
    }
}

Note that this probably doesn't support path templates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant