list user posts
This commit is contained in:
parent
c45cb3eb00
commit
407b4ce7a2
9
user.go
9
user.go
|
@ -25,6 +25,15 @@ func (user User) Name() string {
|
|||
return user.name
|
||||
}
|
||||
|
||||
func (user User) Posts() ([]Post, error) {
|
||||
postNames := listDir(path.Join(user.Dir(), "public"))
|
||||
posts := make([]Post, len(postNames))
|
||||
for i, name := range postNames {
|
||||
posts[i] = Post{user: user, title: name}
|
||||
}
|
||||
return posts, nil
|
||||
}
|
||||
|
||||
func CreateNewPost(user User, title string) {
|
||||
timestamp := time.Now().UTC().Unix()
|
||||
folder_name := fmt.Sprintf("%d-%s", timestamp, title)
|
||||
|
|
17
user_test.go
17
user_test.go
|
@ -39,3 +39,20 @@ func TestCreateNewPostMultipleCalls(t *testing.T) {
|
|||
t.Error(fmt.Sprintf("Only %d posts created", len(files)))
|
||||
}
|
||||
}
|
||||
|
||||
func TestCanListUserPosts(t *testing.T) {
|
||||
// Create a new user
|
||||
repo, _ := kiss.CreateRepository(testRepoName())
|
||||
user, _ := repo.CreateUser(randomUserName())
|
||||
// Create a new post
|
||||
kiss.CreateNewPost(user, "testpost")
|
||||
kiss.CreateNewPost(user, "testpost")
|
||||
kiss.CreateNewPost(user, "testpost")
|
||||
posts, err := user.Posts()
|
||||
if err != nil {
|
||||
t.Error("Error reading posts")
|
||||
}
|
||||
if len(posts) != 3 {
|
||||
t.Error("No posts found")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue