diff --git a/persistence/space_queries.go b/persistence/space_queries.go index bd5c616..d727954 100644 --- a/persistence/space_queries.go +++ b/persistence/space_queries.go @@ -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), diff --git a/persistence/space_queries_test.go b/persistence/space_queries_test.go index 0f621c1..f224471 100644 --- a/persistence/space_queries_test.go +++ b/persistence/space_queries_test.go @@ -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) } diff --git a/persistence/utils_test.go b/persistence/utils_test.go index 176fc70..398f271 100644 --- a/persistence/utils_test.go +++ b/persistence/utils_test.go @@ -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), diff --git a/scraper/api_types_spaces.go b/scraper/api_types_spaces.go index 2dedcf6..01d71cc 100644 --- a/scraper/api_types_spaces.go +++ b/scraper/api_types_spaces.go @@ -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"` diff --git a/scraper/api_types_spaces_test.go b/scraper/api_types_spaces_test.go index dfd2fa0..09f4980 100644 --- a/scraper/api_types_spaces_test.go +++ b/scraper/api_types_spaces_test.go @@ -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) diff --git a/scraper/space.go b/scraper/space.go index 37859e0..9310dd8 100644 --- a/scraper/space.go +++ b/scraper/space.go @@ -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