2023-10-26 06:30:18 +00:00
|
|
|
package community
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/status-im/status-go/services/wallet/thirdparty"
|
|
|
|
"github.com/status-im/status-go/t/helpers"
|
|
|
|
"github.com/status-im/status-go/walletdatabase"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func setupCommunityDataDBTest(t *testing.T) (*DataDB, func()) {
|
|
|
|
db, err := helpers.SetupTestMemorySQLDB(walletdatabase.DbInitializer{})
|
|
|
|
require.NoError(t, err)
|
|
|
|
return NewDataDB(db), func() {
|
|
|
|
require.NoError(t, db.Close())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpdateCommunityInfo(t *testing.T) {
|
|
|
|
db, cleanup := setupCommunityDataDBTest(t)
|
|
|
|
defer cleanup()
|
|
|
|
|
2023-12-13 12:19:25 +00:00
|
|
|
communityData := thirdparty.GenerateTestCommunityInfo(10)
|
2023-11-16 04:18:03 +00:00
|
|
|
extraCommunityID := "extra-community-id"
|
|
|
|
|
2023-10-26 06:30:18 +00:00
|
|
|
for communityID, communityInfo := range communityData {
|
2023-11-16 04:18:03 +00:00
|
|
|
communityInfo := communityInfo // Prevent lint warning G601: Implicit memory aliasing in for loop.
|
|
|
|
err := db.SetCommunityInfo(communityID, &communityInfo)
|
2023-10-26 06:30:18 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
2023-11-16 04:18:03 +00:00
|
|
|
err := db.SetCommunityInfo(extraCommunityID, nil)
|
|
|
|
require.NoError(t, err)
|
2023-10-26 06:30:18 +00:00
|
|
|
|
|
|
|
for communityID, communityInfo := range communityData {
|
2023-11-16 04:18:03 +00:00
|
|
|
info, state, err := db.GetCommunityInfo(communityID)
|
2023-10-26 06:30:18 +00:00
|
|
|
require.NoError(t, err)
|
2023-11-16 04:18:03 +00:00
|
|
|
require.Equal(t, communityInfo, *info)
|
|
|
|
require.True(t, state.LastUpdateSuccesful)
|
2023-10-26 06:30:18 +00:00
|
|
|
}
|
2023-11-16 04:18:03 +00:00
|
|
|
info, state, err := db.GetCommunityInfo(extraCommunityID)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Empty(t, info)
|
|
|
|
require.False(t, state.LastUpdateSuccesful)
|
|
|
|
|
|
|
|
randomCommunityID := "random-community-id"
|
|
|
|
info, state, err = db.GetCommunityInfo(randomCommunityID)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Empty(t, info)
|
|
|
|
require.Empty(t, state)
|
2023-10-26 06:30:18 +00:00
|
|
|
}
|