Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow visitors to create posts with tags #1221

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

MercierMateo
Copy link

Issue: #1211

Visitors can now create post with tags

Copy link
Contributor

@mattwoberts mattwoberts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking really good - apologies for the slow response in looking at this.

Comment on lines 31 to 43
func (input *CreateNewPost) OnPreExecute(ctx context.Context) error {
input.Tags = make([]*entity.Tag, len(input.TagSlugs))
for i, slug := range input.TagSlugs {
getTag := &query.GetTagBySlug{Slug: slug}
if err := bus.Dispatch(ctx, getTag); err != nil {
return err
}

input.Tags[i] = getTag.Result
}

return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea to make this part of OnPreExecute. You'll just need to update that comment though.

BaseURL string `env:"BASE_URL"`
Locale string `env:"LOCALE,default=en"`
JWTSecret string `env:"JWT_SECRET,required"`
PostCreationWithTagsEnabled bool `env:"POST_CREATION_WITH_TAGS_ENABLED,default=false"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this looks good. I was contemplating if we should have a nested AppFeatures struct, and move this into there so that we could add other things in future, but I think we probably don't need to do that...

@mattwoberts
Copy link
Contributor

Looking good. What are you thinking for tests?

@MercierMateo
Copy link
Author

On the action part I'm not sure anything is needed, but tell me if I'm wrong.

On the handler part I think the needed tests are :

  • create a post with an inexistent tag -> should fail as bad request
  • create a post with a private tag as a standard user -> should fail as bad request
  • create a post with a public tag as a standard user -> should succeed
  • create a post with a public tag and a private tag as an administrator -> should succeed

As of now I think the fails are sent as a 404 error, so I will need to investigate on that before making these tests.

@mattwoberts
Copy link
Contributor

On the action part I'm not sure anything is needed, but tell me if I'm wrong.

On the handler part I think the needed tests are :

  • create a post with an inexistent tag -> should fail as bad request
  • create a post with a private tag as a standard user -> should fail as bad request
  • create a post with a public tag as a standard user -> should succeed
  • create a post with a public tag and a private tag as an administrator -> should succeed

As of now I think the fails are sent as a 404 error, so I will need to investigate on that before making these tests.

I suppose it depends - if you're handler tests poke the action then that's great, if they mock the action though then you might need some action tests to check the logic around building up the tags for example - see how you get on 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants