7a04f298d2
- update to latest telegram layer - remove some references to fields in tg.Entities that don't exist in the schema - originally added here: https://github.com/beeper/td/commit/820929062a2ba0104397bc01235ab58a9cff780e - referenced here - https://github.com/mautrix/telegramgo/commit/124f0967ed195b5a380c9bd02e170ada9710dde3 - https://github.com/mautrix/telegramgo/commit/4205047aab2e0639217148b5d125bfaab668bd8e
62 lines
1.3 KiB
Go
62 lines
1.3 KiB
Go
package e2etest
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/go-faster/errors"
|
|
"github.com/stretchr/testify/require"
|
|
"go.uber.org/zap/zaptest"
|
|
|
|
"go.mau.fi/mautrix-telegram/pkg/gotd/telegram/auth"
|
|
"go.mau.fi/mautrix-telegram/pkg/gotd/tg"
|
|
)
|
|
|
|
type mockFlow struct {
|
|
flag bool
|
|
}
|
|
|
|
var _ auth.FlowClient = &mockFlow{}
|
|
|
|
func (m *mockFlow) SignIn(context.Context, string, string, string) (*tg.AuthAuthorization, error) {
|
|
// Ensure retry.
|
|
if !m.flag {
|
|
m.flag = true
|
|
return nil, auth.ErrPasswordAuthNeeded
|
|
}
|
|
|
|
return m.Password(context.Background(), "")
|
|
}
|
|
|
|
func (m *mockFlow) SendCode(context.Context, string, auth.SendCodeOptions) (tg.AuthSentCodeClass, error) {
|
|
return &tg.AuthSentCode{
|
|
PhoneCodeHash: "hash",
|
|
Type: &tg.AuthSentCodeTypeApp{},
|
|
Timeout: 10,
|
|
}, nil
|
|
}
|
|
|
|
func (m *mockFlow) Password(context.Context, string) (*tg.AuthAuthorization, error) {
|
|
return &tg.AuthAuthorization{
|
|
User: &tg.User{
|
|
ID: 10,
|
|
Username: "aboba",
|
|
},
|
|
}, nil
|
|
}
|
|
|
|
func (m *mockFlow) SignUp(context.Context, auth.SignUp) (*tg.AuthAuthorization, error) {
|
|
return nil, errors.New("must not be called")
|
|
}
|
|
|
|
func TestSuite_Authenticate(t *testing.T) {
|
|
ctx := context.Background()
|
|
logger := zaptest.NewLogger(t)
|
|
s := NewSuite(t, TestOptions{
|
|
Logger: logger,
|
|
})
|
|
|
|
flow := &mockFlow{}
|
|
require.NoError(t, s.Authenticate(ctx, flow))
|
|
}
|