move gotd fork into repo. (#111)
- 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
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.mau.fi/mautrix-telegram/pkg/gotd/tg"
|
||||
"go.mau.fi/mautrix-telegram/pkg/gotd/tgerr"
|
||||
"go.mau.fi/mautrix-telegram/pkg/gotd/tgmock"
|
||||
)
|
||||
|
||||
func TestClient_Status(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
t.Run("Authorized", func(t *testing.T) {
|
||||
mock := tgmock.NewRequire(t)
|
||||
user := &tg.User{
|
||||
Username: "user",
|
||||
}
|
||||
mock.Expect().ThenResult(&tg.UserClassVector{Elems: []tg.UserClass{user}})
|
||||
|
||||
status, err := testClient(mock).Status(ctx)
|
||||
require.NoError(t, err)
|
||||
require.True(t, status.Authorized)
|
||||
require.Equal(t, user, status.User)
|
||||
})
|
||||
|
||||
t.Run("Unauthorized", func(t *testing.T) {
|
||||
mock := tgmock.NewRequire(t)
|
||||
mock.Expect().ThenUnregistered()
|
||||
|
||||
status, err := testClient(mock).Status(ctx)
|
||||
require.NoError(t, err)
|
||||
require.False(t, status.Authorized)
|
||||
})
|
||||
|
||||
t.Run("Error", func(t *testing.T) {
|
||||
mock := tgmock.NewRequire(t)
|
||||
mock.Expect().ThenRPCErr(&tgerr.Error{
|
||||
Code: 500,
|
||||
Message: "BRUH",
|
||||
Type: "BRUH",
|
||||
})
|
||||
|
||||
_, err := testClient(mock).Status(ctx)
|
||||
require.Error(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
func TestClient_IfNecessary(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
t.Run("Authorized", func(t *testing.T) {
|
||||
mock := tgmock.NewRequire(t)
|
||||
testUser := &tg.User{
|
||||
Username: "user",
|
||||
}
|
||||
mock.Expect().ThenResult(&tg.UserClassVector{Elems: []tg.UserClass{testUser}})
|
||||
|
||||
// Pass empty AuthFlow because it should not be called anyway.
|
||||
require.NoError(t, testClient(mock).IfNecessary(ctx, Flow{}))
|
||||
})
|
||||
|
||||
t.Run("Error", func(t *testing.T) {
|
||||
mock := tgmock.NewRequire(t)
|
||||
mock.Expect().ThenRPCErr(&tgerr.Error{
|
||||
Code: 500,
|
||||
Message: "BRUH",
|
||||
Type: "BRUH",
|
||||
})
|
||||
|
||||
// Pass empty AuthFlow because it should not be called anyway.
|
||||
require.Error(t, testClient(mock).IfNecessary(ctx, Flow{}))
|
||||
})
|
||||
}
|
||||
|
||||
func TestClient_Test(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
t.Run("Authorized", func(t *testing.T) {
|
||||
mock := tgmock.NewRequire(t)
|
||||
testUser := &tg.User{
|
||||
Username: "user",
|
||||
}
|
||||
mock.Expect().ThenResult(&tg.UserClassVector{Elems: []tg.UserClass{testUser}})
|
||||
|
||||
// Pass empty AuthFlow because it should not be called anyway.
|
||||
require.NoError(t, testClient(mock).Test(ctx, 2))
|
||||
})
|
||||
}
|
||||
|
||||
func TestClient_TestUser(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
t.Run("Authorized", func(t *testing.T) {
|
||||
mock := tgmock.NewRequire(t)
|
||||
testUser := &tg.User{
|
||||
Username: "user",
|
||||
}
|
||||
mock.Expect().ThenResult(&tg.UserClassVector{Elems: []tg.UserClass{testUser}})
|
||||
|
||||
// Pass empty AuthFlow because it should not be called anyway.
|
||||
require.NoError(t, testClient(mock).TestUser(ctx, "phone", 2))
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user