|
| 1 | +package botapi |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/gotd/td/tg" |
| 8 | +) |
| 9 | + |
| 10 | +func TestDeleteStickerSet(t *testing.T) { |
| 11 | + inv := newMockInvoker() |
| 12 | + inv.reply(tg.StickersDeleteStickerSetRequestTypeID, &tg.BoolTrue{}) |
| 13 | + |
| 14 | + if err := newMockBot(inv).DeleteStickerSet(context.Background(), "s"); err != nil { |
| 15 | + t.Fatalf("DeleteStickerSet: %v", err) |
| 16 | + } |
| 17 | + |
| 18 | + if !inv.called(tg.StickersDeleteStickerSetRequestTypeID) { |
| 19 | + t.Fatal("delete not called") |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +func TestSetStickerSetTitle(t *testing.T) { |
| 24 | + inv := newMockInvoker() |
| 25 | + inv.reply(tg.StickersRenameStickerSetRequestTypeID, &tg.MessagesStickerSet{Set: tg.StickerSet{ShortName: "s"}}) |
| 26 | + |
| 27 | + if err := newMockBot(inv).SetStickerSetTitle(context.Background(), "s", "New Title"); err != nil { |
| 28 | + t.Fatalf("SetStickerSetTitle: %v", err) |
| 29 | + } |
| 30 | + |
| 31 | + var req tg.StickersRenameStickerSetRequest |
| 32 | + |
| 33 | + inv.decode(t, tg.StickersRenameStickerSetRequestTypeID, &req) |
| 34 | + |
| 35 | + if req.Title != "New Title" { |
| 36 | + t.Fatalf("title = %q", req.Title) |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +func TestSetStickerEmojiList(t *testing.T) { |
| 41 | + fid := documentFileID(t, 0x55) |
| 42 | + |
| 43 | + inv := newMockInvoker() |
| 44 | + inv.reply(tg.StickersChangeStickerRequestTypeID, &tg.MessagesStickerSet{Set: tg.StickerSet{ShortName: "s"}}) |
| 45 | + |
| 46 | + if err := newMockBot(inv).SetStickerEmojiList(context.Background(), fid, []string{"😀", "😎"}); err != nil { |
| 47 | + t.Fatalf("SetStickerEmojiList: %v", err) |
| 48 | + } |
| 49 | + |
| 50 | + var req tg.StickersChangeStickerRequest |
| 51 | + |
| 52 | + inv.decode(t, tg.StickersChangeStickerRequestTypeID, &req) |
| 53 | + |
| 54 | + if got, ok := req.GetEmoji(); !ok || got != "😀😎" { |
| 55 | + t.Fatalf("emoji = %q, ok=%v", got, ok) |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +func TestSetStickerKeywords(t *testing.T) { |
| 60 | + fid := documentFileID(t, 0x56) |
| 61 | + |
| 62 | + inv := newMockInvoker() |
| 63 | + inv.reply(tg.StickersChangeStickerRequestTypeID, &tg.MessagesStickerSet{Set: tg.StickerSet{ShortName: "s"}}) |
| 64 | + |
| 65 | + if err := newMockBot(inv).SetStickerKeywords(context.Background(), fid, []string{"a", "b"}); err != nil { |
| 66 | + t.Fatalf("SetStickerKeywords: %v", err) |
| 67 | + } |
| 68 | + |
| 69 | + var req tg.StickersChangeStickerRequest |
| 70 | + |
| 71 | + inv.decode(t, tg.StickersChangeStickerRequestTypeID, &req) |
| 72 | + |
| 73 | + if got, ok := req.GetKeywords(); !ok || got != "a,b" { |
| 74 | + t.Fatalf("keywords = %q, ok=%v", got, ok) |
| 75 | + } |
| 76 | +} |
| 77 | + |
| 78 | +func TestSetStickerMaskPosition(t *testing.T) { |
| 79 | + fid := documentFileID(t, 0x57) |
| 80 | + |
| 81 | + inv := newMockInvoker() |
| 82 | + inv.reply(tg.StickersChangeStickerRequestTypeID, &tg.MessagesStickerSet{Set: tg.StickerSet{ShortName: "s"}}) |
| 83 | + |
| 84 | + pos := &MaskPosition{Point: "eyes", XShift: 0.1, YShift: -0.2, Scale: 2.0} |
| 85 | + if err := newMockBot(inv).SetStickerMaskPosition(context.Background(), fid, pos); err != nil { |
| 86 | + t.Fatalf("SetStickerMaskPosition: %v", err) |
| 87 | + } |
| 88 | + |
| 89 | + var req tg.StickersChangeStickerRequest |
| 90 | + |
| 91 | + inv.decode(t, tg.StickersChangeStickerRequestTypeID, &req) |
| 92 | + |
| 93 | + coords, ok := req.GetMaskCoords() |
| 94 | + if !ok || coords.N != 1 || coords.Zoom != 2.0 { |
| 95 | + t.Fatalf("coords = %#v, ok=%v", coords, ok) |
| 96 | + } |
| 97 | +} |
| 98 | + |
| 99 | +func TestSetStickerMaskPositionInvalidPoint(t *testing.T) { |
| 100 | + fid := documentFileID(t, 0x58) |
| 101 | + |
| 102 | + err := newMockBot(newMockInvoker()).SetStickerMaskPosition(context.Background(), fid, &MaskPosition{Point: "nose"}) |
| 103 | + if err == nil { |
| 104 | + t.Fatal("expected error for invalid point") |
| 105 | + } |
| 106 | +} |
| 107 | + |
| 108 | +func TestReplaceStickerInSet(t *testing.T) { |
| 109 | + fid := documentFileID(t, 0x59) |
| 110 | + newFid := documentFileID(t, 0x5a) |
| 111 | + |
| 112 | + inv := newMockInvoker() |
| 113 | + inv.reply(tg.StickersReplaceStickerRequestTypeID, &tg.MessagesStickerSet{Set: tg.StickerSet{ShortName: "s"}}) |
| 114 | + |
| 115 | + sticker := InputSticker{Sticker: FileID(newFid), Format: StickerFormatStatic, EmojiList: []string{"😀"}} |
| 116 | + if err := newMockBot(inv).ReplaceStickerInSet(context.Background(), fid, sticker); err != nil { |
| 117 | + t.Fatalf("ReplaceStickerInSet: %v", err) |
| 118 | + } |
| 119 | + |
| 120 | + var req tg.StickersReplaceStickerRequest |
| 121 | + |
| 122 | + inv.decode(t, tg.StickersReplaceStickerRequestTypeID, &req) |
| 123 | + |
| 124 | + if req.NewSticker.Emoji != "😀" { |
| 125 | + t.Fatalf("new sticker = %#v", req.NewSticker) |
| 126 | + } |
| 127 | +} |
| 128 | + |
| 129 | +func TestGetCustomEmojiStickers(t *testing.T) { |
| 130 | + inv := newMockInvoker() |
| 131 | + inv.reply(tg.MessagesGetCustomEmojiDocumentsRequestTypeID, &tg.DocumentClassVector{ |
| 132 | + Elems: []tg.DocumentClass{ |
| 133 | + &tg.Document{ |
| 134 | + ID: 1, |
| 135 | + AccessHash: 2, |
| 136 | + MimeType: "image/webp", |
| 137 | + Attributes: []tg.DocumentAttributeClass{ |
| 138 | + &tg.DocumentAttributeSticker{Alt: "😀", Stickerset: &tg.InputStickerSetEmpty{}}, |
| 139 | + }, |
| 140 | + }, |
| 141 | + }, |
| 142 | + }) |
| 143 | + |
| 144 | + stickers, err := newMockBot(inv).GetCustomEmojiStickers(context.Background(), []string{"12345"}) |
| 145 | + if err != nil { |
| 146 | + t.Fatalf("GetCustomEmojiStickers: %v", err) |
| 147 | + } |
| 148 | + |
| 149 | + if len(stickers) != 1 || stickers[0].Type != StickerCustomEmoji || stickers[0].Emoji != "😀" { |
| 150 | + t.Fatalf("stickers = %#v", stickers) |
| 151 | + } |
| 152 | + |
| 153 | + var req tg.MessagesGetCustomEmojiDocumentsRequest |
| 154 | + |
| 155 | + inv.decode(t, tg.MessagesGetCustomEmojiDocumentsRequestTypeID, &req) |
| 156 | + |
| 157 | + if len(req.DocumentID) != 1 || req.DocumentID[0] != 12345 { |
| 158 | + t.Fatalf("ids = %v", req.DocumentID) |
| 159 | + } |
| 160 | +} |
0 commit comments