2020-10-28 07:56:14 +00:00
|
|
|
package localnotifications
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
"github.com/status-im/status-go/appdatabase"
|
2023-08-11 11:28:45 +00:00
|
|
|
"github.com/status-im/status-go/t/helpers"
|
2020-10-28 07:56:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func setupAppTestDb(t *testing.T) (*sql.DB, func()) {
|
2023-08-11 11:28:45 +00:00
|
|
|
db, cleanup, err := helpers.SetupTestSQLDB(appdatabase.DbInitializer{}, "local-notifications-tests-")
|
2020-10-28 07:56:14 +00:00
|
|
|
require.NoError(t, err)
|
2023-08-11 11:28:45 +00:00
|
|
|
return db, func() { require.NoError(t, cleanup()) }
|
2020-10-28 07:56:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func setupTestDB(t *testing.T, db *sql.DB) (*Database, func()) {
|
|
|
|
return NewDB(db, 1777), func() {
|
|
|
|
require.NoError(t, db.Close())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestWalletPreferences(t *testing.T) {
|
|
|
|
appDB, appStop := setupAppTestDb(t)
|
|
|
|
defer appStop()
|
|
|
|
|
|
|
|
db, stop := setupTestDB(t, appDB)
|
|
|
|
defer stop()
|
|
|
|
|
|
|
|
enabled := true
|
|
|
|
require.NoError(t, db.ChangeWalletPreference(enabled))
|
|
|
|
rst, err := db.GetWalletPreference()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, enabled, rst.Enabled)
|
|
|
|
|
|
|
|
enabled = false
|
|
|
|
require.NoError(t, db.ChangeWalletPreference(enabled))
|
|
|
|
rst, err = db.GetWalletPreference()
|
|
|
|
require.Equal(t, enabled, rst.Enabled)
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPreferences(t *testing.T) {
|
|
|
|
appDB, appStop := setupAppTestDb(t)
|
|
|
|
defer appStop()
|
|
|
|
|
|
|
|
db, stop := setupTestDB(t, appDB)
|
|
|
|
defer stop()
|
|
|
|
|
|
|
|
enabled := true
|
|
|
|
|
|
|
|
require.NoError(t, db.ChangeWalletPreference(enabled))
|
|
|
|
rst, err := db.GetPreferences()
|
|
|
|
|
|
|
|
require.Equal(t, 1, len(rst))
|
|
|
|
require.Equal(t, enabled, rst[0].Enabled)
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|