mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-22 12:07:31 -06:00
[bugfix] Update poll delete/update db queries (#2361)
This commit is contained in:
parent
8d0c017cf2
commit
0b99f14d64
3 changed files with 98 additions and 39 deletions
|
|
@ -26,6 +26,7 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/suite"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtscontext"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/id"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/util"
|
||||
|
|
@ -304,15 +305,64 @@ func (suite *PollTestSuite) TestDeletePollVotes() {
|
|||
suite.NoError(err)
|
||||
|
||||
// Fetch latest version of poll from database.
|
||||
poll, err = suite.db.GetPollByID(ctx, poll.ID)
|
||||
poll, err = suite.db.GetPollByID(
|
||||
gtscontext.SetBarebones(ctx),
|
||||
poll.ID,
|
||||
)
|
||||
suite.NoError(err)
|
||||
|
||||
// Check that poll counts are all zero.
|
||||
suite.Equal(*poll.Voters, 0)
|
||||
suite.Equal(poll.Votes, make([]int, len(poll.Options)))
|
||||
suite.Equal(make([]int, len(poll.Options)), poll.Votes)
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *PollTestSuite) TestDeletePollVotesNoPoll() {
|
||||
// Create a new context for this test.
|
||||
ctx, cncl := context.WithCancel(context.Background())
|
||||
defer cncl()
|
||||
|
||||
// Try to delete votes of nonexistent poll.
|
||||
nonPollID := "01HF6V4XWTSZWJ80JNPPDTD4DB"
|
||||
|
||||
err := suite.db.DeletePollVotes(ctx, nonPollID)
|
||||
suite.NoError(err)
|
||||
}
|
||||
|
||||
func (suite *PollTestSuite) TestDeletePollVotesBy() {
|
||||
ctx, cncl := context.WithCancel(context.Background())
|
||||
defer cncl()
|
||||
|
||||
for _, vote := range suite.testPollVotes {
|
||||
// Fetch before version of pollBefore from database.
|
||||
pollBefore, err := suite.db.GetPollByID(ctx, vote.PollID)
|
||||
suite.NoError(err)
|
||||
|
||||
// Delete this poll vote.
|
||||
err = suite.db.DeletePollVoteBy(ctx, vote.PollID, vote.AccountID)
|
||||
suite.NoError(err)
|
||||
|
||||
// Fetch after version of poll from database.
|
||||
pollAfter, err := suite.db.GetPollByID(ctx, vote.PollID)
|
||||
suite.NoError(err)
|
||||
|
||||
// Voters count should be reduced by 1.
|
||||
suite.Equal(*pollBefore.Voters-1, *pollAfter.Voters)
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *PollTestSuite) TestDeletePollVotesByNoAccount() {
|
||||
ctx, cncl := context.WithCancel(context.Background())
|
||||
defer cncl()
|
||||
|
||||
// Try to delete a poll by nonexisting account.
|
||||
pollID := suite.testPolls["local_account_1_status_6_poll"].ID
|
||||
nonAccountID := "01HF6T545G1G8ZNMY1S3ZXJ608"
|
||||
|
||||
err := suite.db.DeletePollVoteBy(ctx, pollID, nonAccountID)
|
||||
suite.NoError(err)
|
||||
}
|
||||
|
||||
func TestPollTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(PollTestSuite))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue