Skip to content

Commit

Permalink
add Comment RW
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthieu Jacquot committed Aug 9, 2018
1 parent 82cd3f8 commit c190a46
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 34 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ make
```

### Run the integration tests
Start the server with an existing user
```
./go-realworld-clean --populate=true
```

In another terminal, run the tests against the API
```
newman run api/Conduit.postman_collection.json \
-e api/Conduit.postman_integration_test_environment.json \
Expand Down
68 changes: 34 additions & 34 deletions api/Conduit.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -1662,41 +1662,33 @@
"description": null,
"item": [
{
"name": "All Comments for Article",
"name": "Create Comment for Article",
"event": [
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
"var is200Response = responseCode.code === 200",
"",
"tests['Response code is 200 OK'] = is200Response;",
"",
"if(is200Response){",
" var responseJSON = JSON.parse(responseBody);",
"var responseJSON = JSON.parse(responseBody);",
"",
" tests['Response contains \"comments\" property'] = responseJSON.hasOwnProperty('comments');",
"tests['Response contains \"comment\" property'] = responseJSON.hasOwnProperty('comment');",
"",
" if(responseJSON.comments.length){",
" var comment = responseJSON.comments[0];",
"var comment = responseJSON.comment || {};",
"",
" tests['Comment has \"id\" property'] = comment.hasOwnProperty('id');",
" tests['Comment has \"body\" property'] = comment.hasOwnProperty('body');",
" tests['Comment has \"createdAt\" property'] = comment.hasOwnProperty('createdAt');",
" tests['\"createdAt\" property is an ISO 8601 timestamp'] = new Date(comment.createdAt).toISOString() === comment.createdAt;",
" tests['Comment has \"updatedAt\" property'] = comment.hasOwnProperty('updatedAt');",
" tests['\"updatedAt\" property is an ISO 8601 timestamp'] = new Date(comment.updatedAt).toISOString() === comment.updatedAt;",
" tests['Comment has \"author\" property'] = comment.hasOwnProperty('author');",
" }",
"}",
"tests['Comment has \"id\" property'] = comment.hasOwnProperty('id');",
"tests['Comment has \"body\" property'] = comment.hasOwnProperty('body');",
"tests['Comment has \"createdAt\" property'] = comment.hasOwnProperty('createdAt');",
"tests['\"createdAt\" property is an ISO 8601 timestamp'] = new Date(comment.createdAt).toISOString() === comment.createdAt;",
"tests['Comment has \"updatedAt\" property'] = comment.hasOwnProperty('updatedAt');",
"tests['\"updatedAt\" property is an ISO 8601 timestamp'] = new Date(comment.updatedAt).toISOString() === comment.updatedAt;",
"tests['Comment has \"author\" property'] = comment.hasOwnProperty('author');",
""
]
}
}
],
"request": {
"method": "GET",
"method": "POST",
"header": [
{
"key": "Content-Type",
Expand All @@ -1713,7 +1705,7 @@
],
"body": {
"mode": "raw",
"raw": ""
"raw": "{\"comment\":{\"body\":\"Thank you so much!\"}}"
},
"url": {
"raw": "{{apiUrl}}/articles/how-to-train-your-dragon/comments",
Expand All @@ -1730,33 +1722,41 @@
"response": []
},
{
"name": "Create Comment for Article",
"name": "All Comments for Article",
"event": [
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
"var responseJSON = JSON.parse(responseBody);",
"var is200Response = responseCode.code === 200",
"",
"tests['Response contains \"comment\" property'] = responseJSON.hasOwnProperty('comment');",
"tests['Response code is 200 OK'] = is200Response;",
"",
"var comment = responseJSON.comment || {};",
"if(is200Response){",
" var responseJSON = JSON.parse(responseBody);",
"",
"tests['Comment has \"id\" property'] = comment.hasOwnProperty('id');",
"tests['Comment has \"body\" property'] = comment.hasOwnProperty('body');",
"tests['Comment has \"createdAt\" property'] = comment.hasOwnProperty('createdAt');",
"tests['\"createdAt\" property is an ISO 8601 timestamp'] = new Date(comment.createdAt).toISOString() === comment.createdAt;",
"tests['Comment has \"updatedAt\" property'] = comment.hasOwnProperty('updatedAt');",
"tests['\"updatedAt\" property is an ISO 8601 timestamp'] = new Date(comment.updatedAt).toISOString() === comment.updatedAt;",
"tests['Comment has \"author\" property'] = comment.hasOwnProperty('author');",
" tests['Response contains \"comments\" property'] = responseJSON.hasOwnProperty('comments');",
"",
" if(responseJSON.comments.length){",
" var comment = responseJSON.comments[0];",
"",
" tests['Comment has \"id\" property'] = comment.hasOwnProperty('id');",
" tests['Comment has \"body\" property'] = comment.hasOwnProperty('body');",
" tests['Comment has \"createdAt\" property'] = comment.hasOwnProperty('createdAt');",
" tests['\"createdAt\" property is an ISO 8601 timestamp'] = new Date(comment.createdAt).toISOString() === comment.createdAt;",
" tests['Comment has \"updatedAt\" property'] = comment.hasOwnProperty('updatedAt');",
" tests['\"updatedAt\" property is an ISO 8601 timestamp'] = new Date(comment.updatedAt).toISOString() === comment.updatedAt;",
" tests['Comment has \"author\" property'] = comment.hasOwnProperty('author');",
" }",
"}",
""
]
}
}
],
"request": {
"method": "POST",
"method": "GET",
"header": [
{
"key": "Content-Type",
Expand All @@ -1773,7 +1773,7 @@
],
"body": {
"mode": "raw",
"raw": "{\"comment\":{\"body\":\"Thank you so much!\"}}"
"raw": ""
},
"url": {
"raw": "{{apiUrl}}/articles/how-to-train-your-dragon/comments",
Expand Down
1 change: 1 addition & 0 deletions implem/memory.articleRW/readWriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func (rw rw) Save(article domain.Article) (*domain.Article, error) {
return nil, uc.ErrNotFound
}

article.UpdatedAt = time.Now()
rw.store.Store(article.Slug, article)

return rw.GetBySlug(article.Slug)
Expand Down
4 changes: 4 additions & 0 deletions implem/memory.commentRW/readWriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (

"errors"

"time"

"github.com/err0r500/go-realworld-clean/domain"
"github.com/err0r500/go-realworld-clean/uc"
)
Expand All @@ -23,6 +25,8 @@ func (rw rw) Create(comment domain.Comment) (*domain.Comment, error) {
if _, err := rw.GetByID(comment.ID); err == nil {
return nil, uc.ErrAlreadyInUse
}
comment.CreatedAt = time.Now()
comment.UpdatedAt = time.Now()

rw.store.Store(comment.ID, comment)

Expand Down
3 changes: 3 additions & 0 deletions implem/mock.uc/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type MockedInteractor struct {
Slugger *MockSlugger
ArticleValidator *MockArticleValidator
TagsRW *MockTagsRW
CommentRW *MockCommentRW
}

type SimpleLogger struct{}
Expand All @@ -38,6 +39,7 @@ func NewMockedInteractor(mockCtrl *gomock.Controller) MockedInteractor {
Slugger: NewMockSlugger(mockCtrl),
ArticleValidator: NewMockArticleValidator(mockCtrl),
TagsRW: NewMockTagsRW(mockCtrl),
CommentRW: NewMockCommentRW(mockCtrl),
}
}

Expand All @@ -52,5 +54,6 @@ func (i MockedInteractor) GetUCHandler() uc.Handler {
Slugger: i.Slugger,
ArticleValidator: i.ArticleValidator,
TagsRW: i.TagsRW,
CommentRW: i.CommentRW,
}.New()
}
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/err0r500/go-realworld-clean/implem/jwt.authHandler"
"github.com/err0r500/go-realworld-clean/implem/logrus.logger"
"github.com/err0r500/go-realworld-clean/implem/memory.articleRW"
"github.com/err0r500/go-realworld-clean/implem/memory.commentRW"
"github.com/err0r500/go-realworld-clean/implem/memory.tagsRW"
"github.com/err0r500/go-realworld-clean/implem/memory.userRW"
"github.com/err0r500/go-realworld-clean/implem/user.validator"
Expand Down Expand Up @@ -77,6 +78,7 @@ func run() {
Slugger: slugger.New(),
ArticleValidator: articleValidator.New(),
TagsRW: tagsRW.New(),
CommentRW: commentRW.New(),
}.New(),
authHandler,
routerLogger,
Expand Down
5 changes: 5 additions & 0 deletions uc/HANDLER.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type HandlerConstructor struct {
Logger Logger
UserRW UserRW
ArticleRW ArticleRW
CommentRW CommentRW
UserValidator UserValidator
AuthHandler AuthHandler
Slugger Slugger
Expand Down Expand Up @@ -90,6 +91,9 @@ func (c HandlerConstructor) New() Handler {
if c.TagsRW == nil {
log.Fatal("missing TagsRW")
}
if c.CommentRW == nil {
log.Fatal("missing CommentRW")
}

return interactor{
logger: c.Logger,
Expand All @@ -100,5 +104,6 @@ func (c HandlerConstructor) New() Handler {
slugger: c.Slugger,
articleValidator: c.ArticleValidator,
tagsRW: c.TagsRW,
commentRW: c.CommentRW,
}
}

0 comments on commit c190a46

Please sign in to comment.