BUGFIX: spaces ended_at should be updated on saving now

This commit is contained in:
Alessio 2023-06-08 21:52:22 -03:00
parent b692d9f2fa
commit 693831704d
6 changed files with 40 additions and 11 deletions

View File

@ -28,6 +28,7 @@ func (p Profile) SaveSpace(s scraper.Space) error {
state=case when :state != "" then :state else state end,
title=case when :is_details_fetched then :title else title end,
updated_at=max(:updated_at, updated_at),
ended_at=max(:ended_at, ended_at),
is_available_for_replay=:is_available_for_replay,
replay_watch_count=:replay_watch_count,
live_listeners_count=max(:live_listeners_count, live_listeners_count),

View File

@ -11,9 +11,7 @@ import (
"math/rand"
)
/**
* Create a Space, save it, reload it, and make sure it comes back the same
*/
// Create a Space, save it, reload it, and make sure it comes back the same
func TestSaveAndLoadSpace(t *testing.T) {
require := require.New(t)
profile_path := "test_profiles/TestMediaQueries"
@ -30,6 +28,36 @@ func TestSaveAndLoadSpace(t *testing.T) {
}
}
// Should update a Space
func TestModifySpace(t *testing.T) {
assert := assert.New(t)
require := require.New(t)
profile_path := "test_profiles/TestMediaQueries"
profile := create_or_load_profile(profile_path)
space := create_space_from_id(rand.Int())
err := profile.SaveSpace(space)
require.NoError(err)
// Modify and save
space.State = "Some other state"
space.UpdatedAt = scraper.TimestampFromUnix(9001)
space.EndedAt = scraper.TimestampFromUnix(10001)
space.ReplayWatchCount = 100
space.LiveListenersCount = 50
space.IsDetailsFetched = true
err = profile.SaveSpace(space)
require.NoError(err)
new_space, err := profile.GetSpaceById(space.ID)
require.NoError(err)
assert.Equal(scraper.TimestampFromUnix(9001), new_space.UpdatedAt)
assert.Equal(scraper.TimestampFromUnix(10001), new_space.EndedAt)
assert.Equal(100, new_space.ReplayWatchCount)
assert.Equal(50, new_space.LiveListenersCount)
assert.True(new_space.IsDetailsFetched)
}
func TestNoWorseningSpace(t *testing.T) {
require := require.New(t)
assert := assert.New(t)
@ -72,6 +100,6 @@ func TestNoWorseningSpace(t *testing.T) {
assert.Equal(new_space.CreatedAt, scraper.TimestampFromUnix(1000))
assert.Equal(new_space.UpdatedAt, scraper.TimestampFromUnix(2000))
assert.Equal(new_space.CreatedById, scraper.UserID(-1))
assert.Equal(new_space.LiveListenersCount, int64(100))
assert.Equal(new_space.LiveListenersCount, 100)
assert.True(new_space.IsDetailsFetched)
}

View File

@ -307,7 +307,7 @@ func create_space_from_id(id int) scraper.Space {
return scraper.Space{
ID: scraper.SpaceID(fmt.Sprintf("some_id_%d", id)),
ShortUrl: fmt.Sprintf("short_url_%d", id),
State: "Ended",
State: "Running",
Title: "Some Title",
CreatedAt: scraper.TimestampFromUnix(1000),
StartedAt: scraper.TimestampFromUnix(2000),

View File

@ -23,8 +23,8 @@ type SpaceResponse struct {
IsSpaceAvailableForReplay bool `json:"is_space_available_for_replay"`
IsSpaceAvailableForClipping bool `json:"is_space_available_for_clipping"`
ConversationControls int64 `json:"conversation_controls"`
TotalReplayWatched int64 `json:"total_replay_watched"`
TotalLiveListeners int64 `json:"total_live_listeners"`
TotalReplayWatched int `json:"total_replay_watched"`
TotalLiveListeners int `json:"total_live_listeners"`
CreatorResults struct {
Result struct {
ID int64 `json:"rest_id,string"`

View File

@ -33,8 +33,8 @@ func TestParseSpaceResponse(t *testing.T) {
assert.Equal(int64(1665887491804), space.EndedAt.Time.Unix())
assert.Equal(int64(1665887492705), space.UpdatedAt.Time.Unix())
assert.False(space.IsAvailableForReplay)
assert.Equal(int64(4), space.ReplayWatchCount)
assert.Equal(int64(1), space.LiveListenersCount)
assert.Equal(4, space.ReplayWatchCount)
assert.Equal(1, space.LiveListenersCount)
assert.True(space.IsDetailsFetched)

View File

@ -16,8 +16,8 @@ type Space struct {
EndedAt Timestamp `db:"ended_at"`
UpdatedAt Timestamp
IsAvailableForReplay bool
ReplayWatchCount int64
LiveListenersCount int64
ReplayWatchCount int
LiveListenersCount int
ParticipantIds []UserID
CreatedById UserID