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

HTTP Paginated Response #783

Merged
merged 10 commits into from
Sep 21, 2018
Merged

HTTP Paginated Response #783

merged 10 commits into from
Sep 21, 2018

Conversation

ricardopereira
Copy link
Contributor

No description provided.

@ricardopereira ricardopereira mentioned this pull request Aug 23, 2018
Copy link
Contributor

@funkyboy funkyboy left a comment

Choose a reason for hiding this comment

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

I left some observations. Nothing major, but I think it's worth making those clear before merging.

Source/ARTConstants.m Show resolved Hide resolved
userCallback(result, error);
});
};
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This if looks the same as implemented in first:. Worth extracting it in separate method?


ARTHTTPPaginatedResponse *result = [[ARTHTTPPaginatedResponse alloc] initWithResponse:response items:items rest:rest relFirst:firstRel relCurrent:currentRel relNext:nextRel responseProcessor:responseProcessor];

callback(result, [ARTErrorInfo createFromNSError:error]);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand why the error is passed along here. Shouldn't it be nil?

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 changed it 861f32b. Thanks

Source/ARTStatus.m Show resolved Hide resolved
Source/Ably.modulemap Show resolved Hide resolved
Spec/RestPaginated.swift Show resolved Hide resolved
fail("First link isn't a valid URL"); return
}

expect(firstRequest.url?.absoluteString).to(equal("https://sandbox-rest.ably.io:443/channels/foo/messages?start=0&end=1535035746063&limit=100&direction=backwards&format=msgpack&firstEnd=1535035746063&fromDate=1535035746063&mode=all"))
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here.

}
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we have also tests for next and last?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, that's a good point but we need something to respond with the ref next and last links.

Copy link
Contributor

@funkyboy funkyboy left a comment

Choose a reason for hiding this comment

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

The major one is likely the direct reference to "sandbox"

Copy link
Member

@paddybyers paddybyers left a comment

Choose a reason for hiding this comment

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

See comment

guard let error = error else {
fail("Error is nil"); done(); return
fail("Error is empty"); done(); return
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand why you expect there to be an error in this case. The semantics of this method is that the request was made, and there was a response, and that's that. There was no error.

The response includes a statusCode that is an "error" result, but the request itself didn't fail. It succeeded, and returned a result.

Also, pls can we have tests for requests that do indeed fail - for example it times out, fails to resolve the host, returns a response body that cannot be parsed, etc.

Copy link
Contributor

Choose a reason for hiding this comment

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

@paddybyers this is making a GET /feature which doesn't exist, so the request fails and the error should not be nil. This guard simply makes the test fail if the error is nil.

Copy link
Member

Choose a reason for hiding this comment

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

No, that's not right. If the server responds to the request, and that response is well-formed (even though it is a 404), then that counts as success in this API. There is no error, but the response, encapsulated in the HttpPaginatedResponse, will indicate that the content of the response was an error, appropriately populating success, statusCode, errorCode and errorMessage.

RSC19e states that this method does result in an error if the server did not respond, or its response was not well-formed in some way, so it was not possible to return a HttpPaginatedResponse.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I see now. So the error in nested in the pagination block of the response, not on the first level of the returned object.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, that's not right. If the server responds to the request, and that response is well-formed (even though it is a 404), then that counts as success in this API. There is no error, but the response, encapsulated in the HttpPaginatedResponse, will indicate that the content of the response was an error, appropriately populating success, statusCode, errorCode and errorMessage.

That makes it clear, yes. Thanks. I'll fix it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed 63ebbf5.

guard let paginatedResponse = paginatedResponse else {
fail("PaginatedResult is empty"); done(); return
}
expect(error.statusCode) == 404
Copy link
Member

Choose a reason for hiding this comment

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

Why are there no corresponding assertions for the properties of paginatedResponse ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Yes :(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@paddybyers 😄 So we're good?

Copy link
Member

@paddybyers paddybyers left a comment

Choose a reason for hiding this comment

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

LGTM, thanks

@ricardopereira ricardopereira merged commit d57d60f into rsc19a Sep 21, 2018
@ricardopereira ricardopereira deleted the http-paginated-response branch September 21, 2018 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants