owl-blogs/user_test.go

71 lines
1.6 KiB
Go
Raw Normal View History

2022-07-20 17:35:31 +00:00
package kiss_test
import (
"fmt"
"h4kor/kiss-social"
"io/ioutil"
"path"
"testing"
)
func TestCreateNewPostCreatesEntryInPublic(t *testing.T) {
// Create a new user
repo, _ := kiss.CreateRepository(testRepoName())
user, _ := repo.CreateUser(randomUserName())
// Create a new post
2022-07-21 17:02:37 +00:00
user.CreateNewPost("testpost")
2022-07-20 17:35:31 +00:00
files, err := ioutil.ReadDir(path.Join(user.Dir(), "public"))
if err != nil {
t.Error("Error reading directory")
}
if len(files) < 1 {
t.Error("Post not created")
}
}
func TestCreateNewPostMultipleCalls(t *testing.T) {
// Create a new user
repo, _ := kiss.CreateRepository(testRepoName())
user, _ := repo.CreateUser(randomUserName())
// Create a new post
2022-07-21 17:02:37 +00:00
user.CreateNewPost("testpost")
user.CreateNewPost("testpost")
user.CreateNewPost("testpost")
2022-07-20 17:35:31 +00:00
files, err := ioutil.ReadDir(path.Join(user.Dir(), "public"))
if err != nil {
t.Error("Error reading directory")
}
if len(files) < 3 {
t.Error(fmt.Sprintf("Only %d posts created", len(files)))
}
}
2022-07-20 19:12:18 +00:00
func TestCanListUserPosts(t *testing.T) {
// Create a new user
repo, _ := kiss.CreateRepository(testRepoName())
user, _ := repo.CreateUser(randomUserName())
// Create a new post
2022-07-21 17:02:37 +00:00
user.CreateNewPost("testpost")
user.CreateNewPost("testpost")
user.CreateNewPost("testpost")
2022-07-20 19:12:18 +00:00
posts, err := user.Posts()
if err != nil {
t.Error("Error reading posts")
}
if len(posts) != 3 {
t.Error("No posts found")
}
}
2022-07-21 17:44:07 +00:00
func TestCanLoadPost(t *testing.T) {
user := getTestUser()
// Create a new post
user.CreateNewPost("testpost")
posts, _ := user.Posts()
post, _ := user.GetPost(posts[0])
if post.Title() != "testpost" {
t.Error("Wrong title, Got: " + post.Title())
}
}