-
Notifications
You must be signed in to change notification settings - Fork 16
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
Add integration tests for edit status and edit poll #166
base: master
Are you sure you want to change the base?
Add integration tests for edit status and edit poll #166
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #166 +/- ##
============================================
- Coverage 45.00% 44.97% -0.03%
+ Complexity 235 233 -2
============================================
Files 75 75
Lines 2171 2161 -10
Branches 115 115
============================================
- Hits 977 972 -5
+ Misses 1148 1143 -5
Partials 46 46
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. One question I had while writing the methods was whether editing a poll status using editStatus()
really didn't reset the poll. A test along those lines could be added eventually, but shouldn't stop this PR to go through as is.
That's a good point. I'll add another test to this PR. After that, we can merge it. |
Good morning @bocops , I have written a test which checks that the poll data is still there after a poll's status text has been edited (test is added to this branch). Unfortunately, the poll data is reset after the edit. Do you eventually have time to look at this? If not, please let me know. Thanks! 🙂 |
@andregasser I'll have a look at it today. :) |
@andregasser Editing the status not only resets the poll options, but removes the poll completely. I checked this by replacing the failing line in the test with Mastodon documentation is really sparse in that regard, but if that is the case I assume that we would need to add the same poll details ( I further assume that sending the same |
Hm, the use case "edit status" starts to become a bit omplicated from a library user perspective. I wonder if we could hide this complexity from the user and do something like this:
Would be interesting to see if this works. Mastodon API docs simply mention "Note that editing a poll’s options will reset the votes." But setting the same poll values as part of the edit request is probably not considered a change, right? So hopefully, the poll is still there after editing the status.... Regarding the first bullet item above (provide just a single By providing a number of overloads for the - editStatus(statusId, spoilerText, sensitive, language, mediaIds)
- editStatus(statusId, status, spoilerText, sensitive, language, mediaIds)
- editStatus(statusId, status, spoilerText, sensitive, language, poll) I have created these signatures based on the restrictions / constraints documented in the Mastodon API docs. The whole point actually is: If there's a poll present on the status to be edited, we just re-apply the values in the edit request, to make sure the poll is still there after the edit. Alternatively, we could also check other wrapper libraries and see how they handle the edit scenario. Eventually, this gives some valuable input as well.... What do you think? |
Yeah, I wondered about this myself, editing a poll is somewhat complicated. There are some alternatives, each with their own pros and cons, but I really don't know what would be the best way to proceed. Some ideas:
The builder could look something like this: val previousStatusId = "foobar" // ID of the status we want to edit
val previousStatus = getStatus(previousStatusId)
val previousStatusSource = getStatusSource(previousStatusId)
// allow reuse of data that the library user has downloaded already
StatusMethods.EditBuilder(previousStatus, previousStatusSource)
.content("new content text") // editing content means that library user will have loaded and displayed to their user the previous content themselves, so this would be used in combination with this EditBuilder call
.spoiler("spoiler text") // changes spoiler text and adds sensitivity flag, or removes if parameter is null
.addMedia("mediaId") // add another image, keeping existing ones
.removeMedia("mediaId2") // remove a specific image, but not any others
.performEdit() // send all changes
// alternatively, call builder with an ID to have it load the data itself
StatusMethods.EditBuilder(previousStatusId)
.resetPollOptions(listOf("Foo", "Bar", "Baz")) // make library user aware that this will reset the poll
.changePollExpiry(300) // this might allow changing some of the poll but not its options, so not resetting it
.performEdit() // send all changes |
Hello! I will need to dig in a bit more over the weekend to understand how the REST API works. Some more feedback / questions from my side: 1. Status Source {
"id":"<status id>",
"text":"<status text>",
"spoiler_text": "<spoiler text>"
} I have observed that the Mastodon Web Client uses it every time when initiating a status edit. 2. Polls and Status Edits 3. Method Structure I will add more thoughts to this 3rd item later, need to leave now :-) |
Those three attributes may come with HTML tags when loading a |
Hello @bocops , I would once more quickly come back to our discussion, on how many methods / which methods to offer for creating / editing statuses and polls. I have looked at the methods we currently have and I think, we should not change too much now. But I might have found some spots where things could be simplified even a bit more. These are the methods we currently have in our code for creating / editing statuses and polls: fun postStatus(
status: String,
visibility: Status.Visibility = Status.Visibility.Public,
inReplyToId: String? = null,
mediaIds: List<String>? = null,
sensitive: Boolean = false,
spoilerText: String? = null,
language: String? = null
): MastodonRequest<Status>
fun editStatus(
statusId: String,
status: String,
mediaIds: List<String>? = null,
sensitive: Boolean = false,
spoilerText: String? = null,
language: String? = null
): MastodonRequest<Status>
fun scheduleStatus(
status: String,
scheduledAt: String,
visibility: Status.Visibility = Status.Visibility.Public,
inReplyToId: String? = null,
mediaIds: List<String>? = null,
sensitive: Boolean = false,
spoilerText: String? = null,
language: String? = null
): MastodonRequest<ScheduledStatus>
fun postPoll(
status: String,
pollOptions: List<String>,
pollExpiresIn: Int,
visibility: Status.Visibility = Status.Visibility.Public,
pollMultiple: Boolean = false,
pollHideTotals: Boolean = false,
inReplyToId: String? = null,
sensitive: Boolean = false,
spoilerText: String? = null,
language: String? = null
): MastodonRequest<Status>
fun editPoll(
statusId: String,
status: String,
pollOptions: List<String>,
pollExpiresIn: Int,
pollMultiple: Boolean = false,
pollHideTotals: Boolean = false,
sensitive: Boolean = false,
spoilerText: String? = null,
language: String? = null
): MastodonRequest<Status>
fun schedulePoll(
status: String,
scheduledAt: String,
pollOptions: List<String>,
pollExpiresIn: Int,
visibility: Status.Visibility = Status.Visibility.Public,
pollMultiple: Boolean = false,
pollHideTotals: Boolean = false,
inReplyToId: String? = null,
sensitive: Boolean = false,
spoilerText: String? = null,
language: String? = null
) I see two things, which I think we could simplify here:
This would result in the following new method signatures: fun postStatus(
status: String,
visibility: Status.Visibility = Status.Visibility.Public,
inReplyToId: String? = null,
mediaIds: List<String>? = null,
sensitive: Boolean = false,
spoilerText: String? = null,
language: String? = null,
scheduledAt: String? = null
): MastodonRequest<Status>
fun editStatus(
statusId: String,
status: String,
mediaIds: List<String>? = null,
sensitive: Boolean = false,
spoilerText: String? = null,
language: String? = null
): MastodonRequest<Status>
fun postPoll(
status: String,
poll: Poll,
visibility: Status.Visibility = Status.Visibility.Public,
inReplyToId: String? = null,
sensitive: Boolean = false,
spoilerText: String? = null,
language: String? = null,
scheduleAt: String? = null
): MastodonRequest<Status>
fun editPoll(
statusId: String,
status: String,
poll: Poll,
sensitive: Boolean = false,
spoilerText: String? = null,
language: String? = null
): MastodonRequest<Status> Then, let's just describe in KDoc when which method is to be used. For the One issue that still would need to be solved is the thing with the different data returned when a status or a scheduled status is posted ( I would hold back creating builders for a next major release in order to save some time. What do you think? |
Regarding poll data, we already have Merging I think this is another thing that might better be solved using a Builder that ends in either |
We actually have two poll classes at the moment:
As proposed by you, we could move So let's keep the rest as it is and just point out the important points in the KDoc. Would that be fine for you as well? |
Sounds good! :) |
No description provided.