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

Refactor SearchIssuesRequest to match the API #290

Merged
merged 16 commits into from
Jan 18, 2014

Conversation

hnrkndrssn
Copy link
Contributor

Fixes #274

@shiftkey shiftkey mentioned this pull request Jan 6, 2014
2 tasks
@hnrkndrssn
Copy link
Contributor Author

This is ready for review. Just waiting for #293 so I can remove Skip on a few tests.

cc @shiftkey

@shiftkey
Copy link
Member

shiftkey commented Jan 8, 2014

@alfhenrik oops, I meant to merge that in last night. Done!

@hnrkndrssn
Copy link
Contributor Author

Sweeet, I'll update the skipped tests tonight 😀

@hnrkndrssn
Copy link
Contributor Author

Dun, and ready for review ✨


client.SearchIssues(request);

connection.Received().GetAll<Issue>(Arg.Is<Uri>(u => u.ToString() == "search/issues"), Arg.Is<Dictionary<string, string>>(d => d["q"].StartsWith("pub")));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trim these lines at 80 char or thereabouts...

@hnrkndrssn
Copy link
Contributor Author

Didn't quite get all lines down to 80'ish...but should be better now.

...even an extra one in the Search Code tests...ooops..:grin:


connection.Received().GetAll<Issue>(
Arg.Is<Uri>(u => u.ToString() == "search/issues"),
Arg.Is<Dictionary<string, string>>(d => d["q"].StartsWith("pub")));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason why you chose to use StartsWith and Contains rather than just hard-coding the strings?

I think tests should be tolerable, but given the possible set of query terms is large, is it worth being more terse with these checks?

EDIT: terse, not succinct. So doing d["q"] == "pub" for example in the test above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sure there was a valid reason at the time why I went with StartsWith and Contains, but I'll take a look and see if we can be more terse as suggested.

@shiftkey
Copy link
Member

shiftkey commented Jan 9, 2014

Didn't quite get all lines down to 80'ish...but should be better now.

That's why I said "or thereabouts" 😀 - much more easier to read now.

The changes look great, just curious if we can make the tests a bit more robust...

@hnrkndrssn
Copy link
Contributor Author

While testing this, I found that the query should be formatted like q=searchterm+params but the code currently does q=searchterm params, I have updated the code to:

var mergedParameters = MergeParameters();
d.Add("q", Term + (mergedParameters.IsNotBlank() ? "+" + mergedParameters : ""));

I just want to check if that is an acceptable solution.

@shiftkey
Copy link
Member

shiftkey commented Jan 9, 2014

94

cc @hahmed

@hahmed
Copy link
Contributor

hahmed commented Jan 9, 2014

👍 with that suggestion

@hnrkndrssn
Copy link
Contributor Author

Alright. I'll admit it, there was probably no good reason for using StartsWith and Contains instead of hard coded strings 😞 ...have refactored to use hard coded strings instead.

@shiftkey
Copy link
Member

shiftkey commented Jan 9, 2014

Alright. I'll admit it, there was probably no good reason for using StartsWith and Contains instead of hard coded strings

Don't sweat it. We're only human.

@@ -25,14 +27,13 @@ public SearchIssuesRequest(string term)
/// The search terms. This can be any combination of the supported repository search parameters:
/// http://developer.github.com/v3/search/#search-code
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hahmed
Copy link
Contributor

hahmed commented Jan 9, 2014

The changes look great, just curious if we can make the tests a bit more robust...

Why not test out each search request? Every qualifier too? e.g. In, Author etc.

            [Fact]
            public void TestingQualifiers()
            {
                var request = new SearchIssuesRequest("something");
                Assert.Equal("something", request.Term);
            }

That way we can assert each property does what it should? Quite a lot of tests to add mind you...

@hnrkndrssn
Copy link
Contributor Author

That's what d["q"] does, as it checks each property on the request and creates the query string from that.

@shiftkey
Copy link
Member

shiftkey commented Jan 9, 2014

@hahmed I'd prefer to test that we're sending the correct query format to the GitHub API (harder), rather than that the parameters are populated as expected (easier).

@hahmed
Copy link
Contributor

hahmed commented Jan 9, 2014

Just a suggestion:

One thing that I was thinking about whilst I was implementing the search api was ensure everything get's appending correctly to the term.

I wanted to expose a TermAndQualifiers property so we can better test the output

public
{
   get { return Term + (mergedParameters.IsNotBlank() ? "+" + mergedParameters : ""); }
}

Then we can test what the final string should actually look like, for example github search for a user called mike:

Assert.Equals("mike+type:user", request.TermAndQualifiers);

@shiftkey
Copy link
Member

shiftkey commented Jan 9, 2014

I'm really interested in the external behaviour of these actions - i.e. what the client sends to the server.

Testing properties in this fashion is just testing a layer away from the important bits.

Arg.Is<Uri>(u => u.ToString() == "search/issues"),
Arg.Is<Dictionary<string, string>>(d =>
d["sort"] == "Updated" &&
d["order"] == "Descending"));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something I found last night redoing these tests is that the order parameter is coming back as Descending, but after having a look at the API docs here http://developer.github.com/v3/search/#parameters-2 I realised the order parameter is either asc or desc.

The SortDirection enum (https://github.com/octokit/octokit.net/blob/master/Octokit/Models/Request/IssueRequest.cs#L91) values has a Parameter(Value="") attribute applied to it, so should that automagically ✨ convert Descending to desc or is there something that needs to be done.

Or, will the API accept Descending as the value of the order parameter?

cc @shiftkey

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling .ToString() on an enum will ignore whatever [Parameter] you have set, so this definitely feels like a bug.

Or, will the API accept Descending as the value of the order parameter?

No, it doesn't even return valid search results

@shiftkey
Copy link
Member

#301 was merged in, so you should be unblocked now

@hnrkndrssn
Copy link
Contributor Author

👍

@hnrkndrssn
Copy link
Contributor Author

Ready for another round of review now after move to use BaseSearchRequest

cc @shiftkey

@shiftkey
Copy link
Member

Fix them projects! :)

}

/// <summary>
/// https://help.github.com/articles/searching-issues#language
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we move the URLs into a <remarks> element and instead make a friendly sentence for each of these?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yessir!

@shiftkey
Copy link
Member

yes

Really like how this turned out - thanks for all the hard work on this!

shiftkey added a commit that referenced this pull request Jan 18, 2014
Refactor SearchIssuesRequest to match the API
@shiftkey shiftkey merged commit ad987cd into octokit:master Jan 18, 2014
@hnrkndrssn
Copy link
Contributor Author

Awesome, we got there in the end :) Thanks for all the feedback!

@hnrkndrssn hnrkndrssn deleted the search-issues-req branch January 18, 2014 19:38
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

Successfully merging this pull request may close these issues.

Completing "Search Issues" API
3 participants