Skip to content

Add Support Tickets + Eligibility endpoints #743

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

Open
wants to merge 5 commits into
base: trunk
Choose a base branch
from

Conversation

jkmassel
Copy link
Contributor

@jkmassel jkmassel commented May 23, 2025

Adds WP.com support tickets (ie – Zendesk) and support eligibility endpoints.

Support tickets require the ability to upload files – this PR doesn't do that because we'll need to generalize our file upload stuff. I don't think that's a blocker to this PR landing – the majority of the functionality is there.

I've also added a wp_com_e2e package that'll validate that the support tickets / eligibility endpoints function as expected. You can run it like cargo run --bin wp_com_e2e test --token [my_token]. It must be a WordPress iOS token at the moment – we can consider adjusting that later though.

If you run that test (or trust that I did), I think we can consider this PR working. There are also unit tests for parsing the responses, so I think we're pretty well-covered there.

@jkmassel jkmassel force-pushed the add/support-forms branch 3 times, most recently from 029a613 to 4555134 Compare May 23, 2025 17:57
@jkmassel jkmassel changed the title Add/support forms Add Support Tickets + Eligibility endpoints May 23, 2025
@jkmassel jkmassel requested review from oguzkocer and crazytonyli May 23, 2025 18:04
@jkmassel jkmassel self-assigned this May 23, 2025
@jkmassel jkmassel force-pushed the add/support-forms branch from 4555134 to 4a98907 Compare May 23, 2025 18:17
@jkmassel jkmassel marked this pull request as ready for review May 23, 2025 18:17
crazytonyli
crazytonyli previously approved these changes May 25, 2025
pub id: u64,
pub content: String,
pub author: SupportMessageAuthor,
pub role: String,
Copy link
Contributor

Choose a reason for hiding this comment

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

At the moment how the author is parsed id depending on the SupportMessageAuthor enum variant order: it's a "User" if the JSON can be parsed as an "User"; then it's a "Agent" if the JSON can be parsed as an "Agent". Would it be more correct to parse author based on the role value, instead of how the SupportMessageAuthor enum type is declared?

Copy link
Contributor

Choose a reason for hiding this comment

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

Although this would be better, it's also more tricky to do. At least, I couldn't think of an immediate solution to this except for either using a custom parser or separating the SupportMessage type as SupportUserMessage and SupportAgentMessage. (which doesn't sound like a bad idea 🤔 )

Since SupportUserIdentity and SupportAgentIdentity don't have the same fields, I think the way it's implemented is mostly safe. I say mostly, because future changes to these types may make it unsafe as in they might be incorrectly parsed to one type as described in Tony's comment. So, maybe we should separate the message types if we can. (I haven't fully investigated this yet)

What do you think @crazytonyli?

Copy link
Contributor

Choose a reason for hiding this comment

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

or separating the SupportMessage type as SupportUserMessage and SupportAgentMessage.

This sounds good to me 👍

#[serde(untagged)]
pub enum SupportMessageAuthor {
User(SupportUserIdentity),
SupportAgent(SupportAgentIdentity),
Copy link
Contributor

Choose a reason for hiding this comment

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

Should there be an "other" variant, just in case the "role" value is some other value, like "system" messages?

Copy link
Contributor

Choose a reason for hiding this comment

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

In order to do this, we'd need to parse it as a json value because we don't know the structure of the type.

If we know for sure that there are other types of authors, but we don't know the structure of the type, then I think this makes sense to do. Otherwise, it's probably leave it off and implement it when we need to.

Copy link
Contributor

Choose a reason for hiding this comment

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

My concern is that the app may fail to parse the messages if the API introduces a new "author" with a different JSON schema than "user" and "agent".

Copy link
Contributor

Choose a reason for hiding this comment

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

Let me think about this again depending on your answer to this.

My general worry is for a parsing issue to go unnoticed and introducing a fallback inherently has that problem. Ideally I'd like to have a way to not have parsing errors, but still get a notice about the unexpected fallbacks. Once we have logging implemented, it might help with that a bit.

.test()
.await?;
SupportTicketsTest { client: &client }.test().await?;
SupportEligibilityTest { client: &client }.test().await?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason not to use cargo to run these tests, like the existing integration tests?

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 hoping that at some point this could be run against WP.com on each commit to see if there are breaking changes, which is why I started down this path

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we'd still be able to do that with the regular cargo test setup. Is there something specific you're worried about?

Copy link
Contributor

Choose a reason for hiding this comment

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

I can see some value in making this a binary as it'll make it easier to run it from outside of this project without setting up the toolchain.

I don't have a good grasp of the full picture of what we need for this at the moment, so I don't think it's worth changing what's already implemented. Having said that, I don't think the Testable stuff is very useful. So, I simplified it a bit in d08e206.

@crazytonyli crazytonyli self-requested a review May 25, 2025 23:41
@crazytonyli crazytonyli dismissed their stale review May 25, 2025 23:41

Should have been "Request for changes".

Copy link
Contributor

@oguzkocer oguzkocer left a comment

Choose a reason for hiding this comment

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

The implementation looks good overall, but I am not so sure about the e2e testing setup. I've brought up a question in the line comments, let's discuss where to go from there.

.test()
.await?;
SupportTicketsTest { client: &client }.test().await?;
SupportEligibilityTest { client: &client }.test().await?;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we'd still be able to do that with the regular cargo test setup. Is there something specific you're worried about?

@jkmassel
Copy link
Contributor Author

jkmassel commented Jun 9, 2025

I'm ok with whatever testing approach makes sense – if we can pre-compile a binary for Linux that uses the Rust test stuff, then I'm good with it. One other note, I guess, we'll need to be able to chain some tests together so certain actions run before others (can't be avoided for stuff like support tickets).

@jkmassel jkmassel assigned oguzkocer and unassigned jkmassel Jun 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants