-
Notifications
You must be signed in to change notification settings - Fork 0
/
userInfo_test.go
33 lines (23 loc) · 1.09 KB
/
userInfo_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package telegram
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestNewUser(t *testing.T) {
// fake good data returned from Tlg API
dataGood := []byte(`{"ok":true,"result":[{"update_id":123123,"message":{"message_id":830,"from":{"id":789456,"is_bot":false,"first_name":"мαяgαяιηє","username":"Testname","language_code":"en"},"chat":{"id":123456,"first_name":"мαяgαяιηє","username":"Testname","type":"private"},"date":1572619731,"text":"boom"}}]}`)
tlg := Telegram{}
// decode to ReceiveTlg struct
recv := ReceiveTlg{}
err := tlg.decodeJson(dataGood, &recv)
assert.NoErrorf(t, err, "shouldn't return error")
assert.Equalf(t, 1, len(recv.Result), "results slice must have 1 elem")
user, err := NewUser(&recv.Result[0].Message)
assert.NoError(t, err, "NewUser() shoudn't return error")
userOrig := recv.Result[0].Message.From
assert.Equal(t, userOrig.ID, user.Id)
assert.Equal(t, userOrig.FirstName, user.FirstName)
assert.Equal(t, userOrig.LastName, user.LastName)
assert.Equal(t, userOrig.UserName, user.UserName)
assert.Equal(t, userOrig.IsBot, user.isBot)
}