WordPress-iOS icon indicating copy to clipboard operation
WordPress-iOS copied to clipboard

Remove Alamofire dependency from WordPressKit

Open kean opened this issue 1 year ago • 7 comments

It was "needed" for tests.

To test:

Regression Notes

  1. Potential unintended areas of impact

  2. What I did to test those areas of impact (or what existing automated tests I relied on)

  3. What automated tests I added (or what prevented me from doing so)

PR submission checklist:

  • [ ] I have completed the Regression Notes.
  • [ ] I have considered adding unit tests for my changes.
  • [ ] I have considered adding accessibility improvements for my changes.
  • [ ] I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

Testing checklist:

  • [ ] WordPress.com sites and self-hosted Jetpack sites.
  • [ ] Portrait and landscape orientations.
  • [ ] Light and dark modes.
  • [ ] Fonts: Larger, smaller and bold text.
  • [ ] High contrast.
  • [ ] VoiceOver.
  • [ ] Languages with large words or with letters/accents not frequently used in English.
  • [ ] Right-to-left languages. (Even if translation isn’t complete, formatting should still respect the right-to-left layout)
  • [ ] iPhone and iPad.
  • [ ] Multi-tasking: Split view and Slide over. (iPad)

kean avatar Jun 25 '24 13:06 kean

WordPress Alpha📲 You can test the changes from this Pull Request in WordPress Alpha by scanning the QR code below to install the corresponding build.
App NameWordPress Alpha WordPress Alpha
ConfigurationRelease-Alpha
Build Numberpr23386-ce10657
Version25.1
Bundle IDorg.wordpress.alpha
Commitce106575371f4e2703f282ea590df8dd09aed3cf
App Center BuildWPiOS - One-Offs #10264
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

wpmobilebot avatar Jun 25 '24 13:06 wpmobilebot

Jetpack Alpha📲 You can test the changes from this Pull Request in Jetpack Alpha by scanning the QR code below to install the corresponding build.
App NameJetpack Alpha Jetpack Alpha
ConfigurationRelease-Alpha
Build Numberpr23386-ce10657
Version25.1
Bundle IDcom.jetpack.alpha
Commitce106575371f4e2703f282ea590df8dd09aed3cf
App Center Buildjetpack-installable-builds #9311
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

wpmobilebot avatar Jun 25 '24 13:06 wpmobilebot

I honestly didn't read the tests because the use of Alamofire didn't seem to make sense.

but we should replace it with static test data that can be validated against

Done. Right, this way it'll catch if there any regressions.

kean avatar Jun 26 '24 15:06 kean

Sorry to be annoying – can we use multi-line Swift strings for this so developers can read it right in the code?

Can you drop a comment on the lines you are referring to please?

There are inline base64 binary:

let expected = Data(base64Encoded: "LS10ZXN0Ym91bmRhcnkNCkNvbnRlbnQtRGlzcG9zaXRpb246IGZvcm0tZGF0YTsgbmFtZT0ia2V5LTEiDQoNCmENCi0tdGVzdGJvdW5kYXJ5DQpDb250ZW50LURpc3Bvc2l0aW9uOiBmb3JtLWRhdGE7IG5hbWU9ImtleS0yIg0KDQpiDQotLXRlc3Rib3VuZGFyeS0tDQo=")!

kean avatar Jun 26 '24 18:06 kean

Yeah, all the binary data is just a string like:

--wpkit.boundary.9d4adfc909a08bfa
Content-Disposition: form-data; name="world"

hello
--wpkit.boundary.9d4adfc909a08bfa--

We could probably just use that in the test for easier comparison?

jkmassel avatar Jun 26 '24 18:06 jkmassel

We could probably just use that in the test for easier comparison?

It actually is, isn't it? There are just boundaries and .utf8 "blobs".

I tried it, but there is an issue with newlines. It encodes them as \r\n aka Windows encoding. Swift uses just \n if you have a multiline string.

--testboundary\r\nContent-Disposition: form-data; name=\"key-1\"\r\n\r\na\r\n--testboundary\r\nContent-Disposition: form-data; name=\"key-2\"\r\n\r\nb\r\n--testboundary--\r\n

So this won't be the same:

let expected = """
        --testboundary
        Content-Disposition: form-data; name="key-1"

        a
        --testboundary
        Content-Disposition: form-data; name="key-2"

        b
        --testboundary--

        """.data(using: .utf8)

kean avatar Jun 26 '24 18:06 kean

But this will work:

let expected = "--testboundary\r\nContent-Disposition: form-data; name=\"key-1\"\r\n\r\na\r\n--testboundary\r\nContent-Disposition: form-data; name=\"key-2\"\r\n\r\nb\r\n--testboundary--\r\n".data(using: .utf8)

I'm changing it to that.

kean avatar Jun 26 '24 18:06 kean

1 Warning
:warning: Modules/Package.swift was changed without updating its corresponding Package.resolved. Please resolve the Swift packages in Xcode.

Generated by :no_entry_sign: Danger

dangermattic avatar Jul 05 '24 22:07 dangermattic