Ivan Belyakov 2df9df10ab fix(tests): moved test db setup to a common place 't/helpers', created
interface for initializing db, which is implemented for appdatabase and
walletdatabase. TBD for multiaccounts DB.
Unified DB initializion for all tests using helpers and new interface.
Reduced sqlcipher kdf iterations for all tests to 1.
2023-08-18 09:00:56 +02:00

63 lines
1.4 KiB
Go

package localnotifications
import (
"database/sql"
"testing"
"github.com/stretchr/testify/require"
"github.com/status-im/status-go/appdatabase"
"github.com/status-im/status-go/t/helpers"
)
func setupAppTestDb(t *testing.T) (*sql.DB, func()) {
db, cleanup, err := helpers.SetupTestSQLDB(appdatabase.DbInitializer{}, "local-notifications-tests-")
require.NoError(t, err)
return db, func() { require.NoError(t, cleanup()) }
}
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)
}