-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquote_getter_test.go
47 lines (39 loc) · 1.96 KB
/
quote_getter_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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestBuildQuoteMessage(t *testing.T) {
testQuoteObj := QuoteObject{
Quote: "quote",
Author: "author",
}
tests := map[string]struct {
input QuoteObject
dogFriday bool
want string
}{
"simple": {input: testQuoteObj, dogFriday: false, want: "\"quote\"\n\n-author"},
"dog friday": {input: testQuoteObj, dogFriday: true, want: "🐕 It's Dog Friday! 🐕\n\n\"quote\"\n\n-author"},
}
for name, tst := range tests {
t.Run(name, func(t *testing.T) {
res := BuildTwilioMessage(&tst.input, tst.dogFriday)
assert.Equal(t, tst.want, res, "not right message")
})
}
}
func TestQuoteDecode(t *testing.T) {
resByteArr := []byte("{\n \"success\": {\n \"total\": 1\n },\n \"contents\": {\n \"quotes\": [\n {\n \"quote\": \"Many a false step was made by standing still.\",\n \"length\": \"45\",\n \"author\": \"Fortune Cookie\",\n \"tags\": [\n \"inspire\",\n \"standing-still\"\n ],\n \"category\": \"inspire\",\n \"language\": \"en\",\n \"date\": \"2021-04-14\",\n \"permalink\": \"https://theysaidso.com/quote/fortune-cookie-many-a-false-step-was-made-by-standing-still\",\n \"id\": \"N0OhL98JryRfjljJqVtwGgeF\",\n \"background\": \"https://theysaidso.com/img/qod/qod-inspire.jpg\",\n \"title\": \"Inspiring Quote of the day\"\n }\n ]\n },\n \"baseurl\": \"https://theysaidso.com\",\n \"copyright\": {\n \"year\": 2023,\n \"url\": \"https://theysaidso.com\"\n }\n}")
res, err := parseQuoteJsonResponse(resByteArr)
assert.Nil(t, err)
assert.Equal(t, "Many a false step was made by standing still.", res.Quote)
assert.Equal(t, "Fortune Cookie", res.Author)
}
func TestBuildQuoteMsgStr(t *testing.T) {
quote := QuoteObject{
Quote: "This is a Quote",
Author: "Author",
}
assert.Equal(t, "\"This is a Quote\"\n\n-Author", buildTextString("e, false))
}