-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Matthieu Jacquot
committed
Jul 29, 2018
1 parent
82a1bab
commit 4e4bb4c
Showing
12 changed files
with
190 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package uc_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/err0r500/go-realworld-clean/domain" | ||
mock "github.com/err0r500/go-realworld-clean/implem/mock.uc" | ||
"github.com/err0r500/go-realworld-clean/uc" | ||
"github.com/golang/mock/gomock" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestInteractor_GetArticles(t *testing.T) { | ||
expectedArticles := domain.ArticleCollection{art1, art2, art3, art4} | ||
|
||
t.Run("most obvious", func(t *testing.T) { | ||
mockCtrl := gomock.NewController(t) | ||
defer mockCtrl.Finish() | ||
|
||
offset := 2 | ||
filters := uc.NewFilters("jane", "", "") | ||
i := mock.NewMockedInteractor(mockCtrl) | ||
i.ArticleRW.EXPECT().GetRecentFiltered(filters).Return(expectedArticles, nil).Times(1) | ||
|
||
articles, count, err := i.GetUCHandler().GetArticles(10, offset, filters) | ||
assert.NoError(t, err) | ||
assert.Equal(t, 4, count) | ||
assert.Equal(t, expectedArticles[offset:], articles) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,71 @@ | ||
package uc | ||
|
||
import "github.com/err0r500/go-realworld-clean/domain" | ||
import ( | ||
"github.com/err0r500/go-realworld-clean/domain" | ||
) | ||
|
||
func (i interactor) CommentsGet(slug string) ([]domain.Comment, error) { | ||
return nil, nil | ||
article, err := i.articleRW.GetBySlug(slug) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return article.Comments, nil | ||
} | ||
|
||
func (i interactor) CommentsPost(username, slug, comment string) (*domain.Comment, error) { | ||
return nil, nil | ||
commentPoster, err := i.userRW.GetByName(username) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
article, err := i.articleRW.GetBySlug(slug) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
rawComment := domain.Comment{ | ||
Body: comment, | ||
Author: domain.Profile{User: *commentPoster}, | ||
} | ||
|
||
insertedComment, err := i.commentRW.Create(rawComment) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
article.Comments = append(article.Comments, *insertedComment) | ||
|
||
if _, err := i.articleRW.Save(*article); err != nil { | ||
return nil, err | ||
} | ||
|
||
return insertedComment, nil | ||
} | ||
|
||
func (i interactor) CommentsDelete(username string, slug, id string) error { | ||
func (i interactor) CommentsDelete(username, slug string, id int) error { | ||
comment, err := i.commentRW.GetByID(id) | ||
if err != nil { | ||
return err | ||
} | ||
if comment.Author.Name != username { | ||
return errWrongUser | ||
} | ||
|
||
if err := i.commentRW.Delete(id); err != nil { | ||
return err | ||
} | ||
|
||
article, err := i.articleRW.GetBySlug(slug) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
article.UpdateComments(*comment, false) | ||
|
||
if _, err := i.articleRW.Save(*article); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |