2020-06-19 21:50:21 +00:00
|
|
|
package telegraph_test
|
2019-07-24 08:03:29 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2020-06-19 21:50:21 +00:00
|
|
|
"gitlab.com/toby3d/telegraph"
|
2019-07-24 08:03:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestCreatePage(t *testing.T) {
|
2020-06-19 21:50:21 +00:00
|
|
|
content, err := telegraph.ContentFormat(`<p>Hello, world!</p>`)
|
2019-07-24 08:03:29 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
t.Run("invalid", func(t *testing.T) {
|
2020-06-19 21:50:21 +00:00
|
|
|
var a telegraph.Account
|
|
|
|
_, err := a.CreatePage(telegraph.Page{
|
2019-07-24 08:03:29 +00:00
|
|
|
Title: "Sample Page",
|
|
|
|
AuthorName: "Anonymous",
|
|
|
|
Content: content,
|
|
|
|
}, true)
|
|
|
|
assert.Error(t, err)
|
|
|
|
})
|
|
|
|
t.Run("valid", func(t *testing.T) {
|
2020-06-19 21:50:21 +00:00
|
|
|
a := telegraph.Account{
|
2019-07-24 08:03:29 +00:00
|
|
|
AccessToken: "b968da509bb76866c35425099bc0989a5ec3b32997d55286c657e6994bbb",
|
|
|
|
ShortName: "Sandbox",
|
|
|
|
AuthorName: "Anonymous",
|
|
|
|
}
|
|
|
|
|
2020-06-19 21:50:21 +00:00
|
|
|
page, err := a.CreatePage(telegraph.Page{
|
2019-07-24 08:03:29 +00:00
|
|
|
Title: "Sample Page",
|
|
|
|
AuthorName: "Anonymous",
|
|
|
|
Content: content,
|
|
|
|
}, true)
|
|
|
|
if !assert.NoError(t, err) {
|
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
assert.NotEmpty(t, page.URL)
|
|
|
|
})
|
|
|
|
}
|