BUGFIX: spaces ended_at should be updated on saving now
This commit is contained in:
parent
b692d9f2fa
commit
693831704d
@ -28,6 +28,7 @@ func (p Profile) SaveSpace(s scraper.Space) error {
|
|||||||
state=case when :state != "" then :state else state end,
|
state=case when :state != "" then :state else state end,
|
||||||
title=case when :is_details_fetched then :title else title end,
|
title=case when :is_details_fetched then :title else title end,
|
||||||
updated_at=max(:updated_at, updated_at),
|
updated_at=max(:updated_at, updated_at),
|
||||||
|
ended_at=max(:ended_at, ended_at),
|
||||||
is_available_for_replay=:is_available_for_replay,
|
is_available_for_replay=:is_available_for_replay,
|
||||||
replay_watch_count=:replay_watch_count,
|
replay_watch_count=:replay_watch_count,
|
||||||
live_listeners_count=max(:live_listeners_count, live_listeners_count),
|
live_listeners_count=max(:live_listeners_count, live_listeners_count),
|
||||||
|
@ -11,9 +11,7 @@ import (
|
|||||||
"math/rand"
|
"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) {
|
func TestSaveAndLoadSpace(t *testing.T) {
|
||||||
require := require.New(t)
|
require := require.New(t)
|
||||||
profile_path := "test_profiles/TestMediaQueries"
|
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) {
|
func TestNoWorseningSpace(t *testing.T) {
|
||||||
require := require.New(t)
|
require := require.New(t)
|
||||||
assert := assert.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.CreatedAt, scraper.TimestampFromUnix(1000))
|
||||||
assert.Equal(new_space.UpdatedAt, scraper.TimestampFromUnix(2000))
|
assert.Equal(new_space.UpdatedAt, scraper.TimestampFromUnix(2000))
|
||||||
assert.Equal(new_space.CreatedById, scraper.UserID(-1))
|
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)
|
assert.True(new_space.IsDetailsFetched)
|
||||||
}
|
}
|
||||||
|
@ -307,7 +307,7 @@ func create_space_from_id(id int) scraper.Space {
|
|||||||
return scraper.Space{
|
return scraper.Space{
|
||||||
ID: scraper.SpaceID(fmt.Sprintf("some_id_%d", id)),
|
ID: scraper.SpaceID(fmt.Sprintf("some_id_%d", id)),
|
||||||
ShortUrl: fmt.Sprintf("short_url_%d", id),
|
ShortUrl: fmt.Sprintf("short_url_%d", id),
|
||||||
State: "Ended",
|
State: "Running",
|
||||||
Title: "Some Title",
|
Title: "Some Title",
|
||||||
CreatedAt: scraper.TimestampFromUnix(1000),
|
CreatedAt: scraper.TimestampFromUnix(1000),
|
||||||
StartedAt: scraper.TimestampFromUnix(2000),
|
StartedAt: scraper.TimestampFromUnix(2000),
|
||||||
|
@ -23,8 +23,8 @@ type SpaceResponse struct {
|
|||||||
IsSpaceAvailableForReplay bool `json:"is_space_available_for_replay"`
|
IsSpaceAvailableForReplay bool `json:"is_space_available_for_replay"`
|
||||||
IsSpaceAvailableForClipping bool `json:"is_space_available_for_clipping"`
|
IsSpaceAvailableForClipping bool `json:"is_space_available_for_clipping"`
|
||||||
ConversationControls int64 `json:"conversation_controls"`
|
ConversationControls int64 `json:"conversation_controls"`
|
||||||
TotalReplayWatched int64 `json:"total_replay_watched"`
|
TotalReplayWatched int `json:"total_replay_watched"`
|
||||||
TotalLiveListeners int64 `json:"total_live_listeners"`
|
TotalLiveListeners int `json:"total_live_listeners"`
|
||||||
CreatorResults struct {
|
CreatorResults struct {
|
||||||
Result struct {
|
Result struct {
|
||||||
ID int64 `json:"rest_id,string"`
|
ID int64 `json:"rest_id,string"`
|
||||||
|
@ -33,8 +33,8 @@ func TestParseSpaceResponse(t *testing.T) {
|
|||||||
assert.Equal(int64(1665887491804), space.EndedAt.Time.Unix())
|
assert.Equal(int64(1665887491804), space.EndedAt.Time.Unix())
|
||||||
assert.Equal(int64(1665887492705), space.UpdatedAt.Time.Unix())
|
assert.Equal(int64(1665887492705), space.UpdatedAt.Time.Unix())
|
||||||
assert.False(space.IsAvailableForReplay)
|
assert.False(space.IsAvailableForReplay)
|
||||||
assert.Equal(int64(4), space.ReplayWatchCount)
|
assert.Equal(4, space.ReplayWatchCount)
|
||||||
assert.Equal(int64(1), space.LiveListenersCount)
|
assert.Equal(1, space.LiveListenersCount)
|
||||||
|
|
||||||
assert.True(space.IsDetailsFetched)
|
assert.True(space.IsDetailsFetched)
|
||||||
|
|
||||||
|
@ -16,8 +16,8 @@ type Space struct {
|
|||||||
EndedAt Timestamp `db:"ended_at"`
|
EndedAt Timestamp `db:"ended_at"`
|
||||||
UpdatedAt Timestamp
|
UpdatedAt Timestamp
|
||||||
IsAvailableForReplay bool
|
IsAvailableForReplay bool
|
||||||
ReplayWatchCount int64
|
ReplayWatchCount int
|
||||||
LiveListenersCount int64
|
LiveListenersCount int
|
||||||
ParticipantIds []UserID
|
ParticipantIds []UserID
|
||||||
|
|
||||||
CreatedById UserID
|
CreatedById UserID
|
||||||
|
Loading…
x
Reference in New Issue
Block a user