Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.

Conversation

@danielebogo
Copy link
Contributor

Description

Refs. #10277

This PR introduces the new API used to download/install/activate the Jetpack plugin in a self-hosted site.

I created a new BlogServiceRemoteREST extension adding the new API and the errors enum JetpackInstallError.
The expected API success response is:

{
    "status": true
}

The expected failure response is:

{
    "error": "ERROR_NAME",
    "message": "MESSAGE"
}

Testing Details

The new API is fully covered by Unit Tests. Simply run BlogServiceRemoteRESTTests+Jetpack. It contains the Unit Tests to cover all these cases:

  • Success -> status: true

  • Failure -> status: false

  • Error -> Every JetpackInstallError has been covered

  • Unknown Error -> If an error is not a JetpackInstallError case.

  • Please check here if your pull request includes additional test coverage.

@danielebogo danielebogo self-assigned this Mar 18, 2019
@danielebogo danielebogo requested a review from aerych March 18, 2019 09:45
Copy link
Contributor

@aerych aerych left a comment

Choose a reason for hiding this comment

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

Heya @danielebogo!

Looking good! All tests pass. I left a couple of nitpicks in comments, but the one about the locale query param is the only one I'd consider a blocker.

Back to you sir!

case unknown

init?(error code: String?) {
guard let code = code else {
Copy link
Contributor

Choose a reason for hiding this comment

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

If you wanted to get rid of the guard you could add a default value to code like so:
init?(error code: String = JetpackInstallError.unknown.rawValue)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At the end I removed the guard without using the default value. Since the init(rawValue:) returns an optional I can use the nil-coalescing to use .unknown as fallback.

completion(false, .unknown)
return
}
let path = String(format: "jetpack-install/%@/?locale=en_US", escapedURL)
Copy link
Contributor

Choose a reason for hiding this comment

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

?locale=en_US I think this is unnecessary (and we probably don't want it hard-coded to en_US regardless). @stevebaranski recently updated things so the locale is automatically added and set to the users preferred device language (iirc).

Copy link

Choose a reason for hiding this comment

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

Thanks for the ping @aerych!

Yes @danielebogo, if appendsPreferredLanguageLocale is true on the underlying WordPressComRestApi instance, this is indeed "free" behavior. Most of the changes I made to this method were focused on preventing duplicate parameter entries that were possible with the logic in-place.

Please let me know if you have questions or if you need additional information.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @aerych and @stevebaranski for the hint 😊

let jetpackRemoteErrorActivationResponseMockFilename = "blog-service-jetpack-remote-error-activation-response.json"
let jetpackRemoteErrorActivationFailureMockFilename = "blog-service-jetpack-remote-error-activation-failure.json"

var endpoint: String { return "jetpack-install/\(encodedURL)/?locale=en_US" }
Copy link
Contributor

Choose a reason for hiding this comment

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

?locale=en_US
Just a note to remove locale here as well if its indeed unnecessary.

@danielebogo
Copy link
Contributor Author

Thanks @aerych ! I fixed the locale and modified a bit the enum init. It's ready for another look!

Copy link
Contributor

@aerych aerych left a comment

Choose a reason for hiding this comment

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

Looks good! I re-ran tests and everything passed.
:shipit: sir!

@danielebogo
Copy link
Contributor Author

Thanks @aerych !

@danielebogo danielebogo merged commit 83483a8 into develop Mar 19, 2019
@danielebogo danielebogo deleted the feature/10277-jetpack-installation-api branch March 20, 2019 08:22
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants