feat: activity log producers
This commit is contained in:
1 parent
50b1649965
commit
e37a46a027
93 files changed
+3396
-440
No files matched your search
@@ -29,10 +29,10 @@ func TestCreateArticleTitleLengthLimit(t *testing.T) {
|
||||
for _, tc := range cases {
|
||||
t.Run(fmt.Sprintf("length_%d", tc.length), func(t *testing.T) {
|
||||
repo := newMockArticleRepo()
|
||||
uc := useCases.NewCreateArticleUseCase(repo, &fakeBodyRenderer{})
|
||||
uc := useCases.NewCreateArticleUseCase(repo, &fakeBodyRenderer{}, discardRecorder)
|
||||
|
||||
title := strings.Repeat("a", tc.length)
|
||||
result, err := uc.CreateArticle(useCases.CreateArticleCommand{Title: title, Body: "Some body text"})
|
||||
result, err := uc.CreateArticle(testCtx, useCases.CreateArticleCommand{Title: title, Body: "Some body text"})
|
||||
|
||||
if tc.expectValid {
|
||||
if err != nil {
|
||||
@@ -62,9 +62,9 @@ func TestCreateArticleTitleLengthLimit(t *testing.T) {
|
||||
func TestCreateArticlePropagatesRepositoryFailure(t *testing.T) {
|
||||
repo := newMockArticleRepo()
|
||||
repo.fail.failNext("Create")
|
||||
uc := useCases.NewCreateArticleUseCase(repo, &fakeBodyRenderer{})
|
||||
uc := useCases.NewCreateArticleUseCase(repo, &fakeBodyRenderer{}, discardRecorder)
|
||||
|
||||
_, err := uc.CreateArticle(useCases.CreateArticleCommand{Title: "Backyard Renovation Update", Body: "Some body text"})
|
||||
_, err := uc.CreateArticle(testCtx, useCases.CreateArticleCommand{Title: "Backyard Renovation Update", Body: "Some body text"})
|
||||
|
||||
if !errors.Is(err, errRepositoryFailure) {
|
||||
t.Errorf("expected repository failure, got %v", err)
|
||||
@@ -242,8 +242,8 @@ func TestUpdateArticleDelegatesEachOperation(t *testing.T) {
|
||||
|
||||
t.Run("UpdateBody_id1", func(t *testing.T) {
|
||||
repo := newRepo()
|
||||
uc := useCases.NewUpdateArticleUseCase(repo, &fakeBodyRenderer{})
|
||||
result, err := uc.UpdateBody(1, "New body", article.BodyFormatHTML)
|
||||
uc := useCases.NewUpdateArticleUseCase(repo, &fakeBodyRenderer{}, discardRecorder)
|
||||
result, err := uc.UpdateBody(testCtx, 1, "New body", article.BodyFormatHTML)
|
||||
if err != nil {
|
||||
t.Fatalf("expected no error, got %v", err)
|
||||
}
|
||||
@@ -254,8 +254,8 @@ func TestUpdateArticleDelegatesEachOperation(t *testing.T) {
|
||||
|
||||
t.Run("UpdateBody_id9", func(t *testing.T) {
|
||||
repo := newRepo()
|
||||
uc := useCases.NewUpdateArticleUseCase(repo, &fakeBodyRenderer{})
|
||||
_, err := uc.UpdateBody(9, "New body", article.BodyFormatHTML)
|
||||
uc := useCases.NewUpdateArticleUseCase(repo, &fakeBodyRenderer{}, discardRecorder)
|
||||
_, err := uc.UpdateBody(testCtx, 9, "New body", article.BodyFormatHTML)
|
||||
if !errors.Is(err, article.ErrArticleNotFound) {
|
||||
t.Errorf("expected article.ErrArticleNotFound, got %v", err)
|
||||
}
|
||||
@@ -263,8 +263,8 @@ func TestUpdateArticleDelegatesEachOperation(t *testing.T) {
|
||||
|
||||
t.Run("UpdateIsOnline_id1", func(t *testing.T) {
|
||||
repo := newRepo()
|
||||
uc := useCases.NewUpdateArticleUseCase(repo, &fakeBodyRenderer{})
|
||||
result, err := uc.UpdateIsOnline(1, true, article.BodyFormatHTML)
|
||||
uc := useCases.NewUpdateArticleUseCase(repo, &fakeBodyRenderer{}, discardRecorder)
|
||||
result, err := uc.UpdateIsOnline(testCtx, 1, true, article.BodyFormatHTML)
|
||||
if err != nil {
|
||||
t.Fatalf("expected no error, got %v", err)
|
||||
}
|
||||
@@ -275,8 +275,8 @@ func TestUpdateArticleDelegatesEachOperation(t *testing.T) {
|
||||
|
||||
t.Run("UpdateIsOnline_id9", func(t *testing.T) {
|
||||
repo := newRepo()
|
||||
uc := useCases.NewUpdateArticleUseCase(repo, &fakeBodyRenderer{})
|
||||
_, err := uc.UpdateIsOnline(9, true, article.BodyFormatHTML)
|
||||
uc := useCases.NewUpdateArticleUseCase(repo, &fakeBodyRenderer{}, discardRecorder)
|
||||
_, err := uc.UpdateIsOnline(testCtx, 9, true, article.BodyFormatHTML)
|
||||
if !errors.Is(err, article.ErrArticleNotFound) {
|
||||
t.Errorf("expected article.ErrArticleNotFound, got %v", err)
|
||||
}
|
||||
@@ -287,9 +287,9 @@ func TestDeleteArticleReportsMissingArticle(t *testing.T) {
|
||||
t.Run("id_1", func(t *testing.T) {
|
||||
repo := newMockArticleRepo()
|
||||
repo.articles[1] = article.Article{ID: 1}
|
||||
uc := useCases.NewDeleteArticleUseCase(repo)
|
||||
uc := useCases.NewDeleteArticleUseCase(repo, discardRecorder)
|
||||
|
||||
err := uc.DeleteArticle(1)
|
||||
err := uc.DeleteArticle(testCtx, 1)
|
||||
if err != nil {
|
||||
t.Errorf("expected no error, got %v", err)
|
||||
}
|
||||
@@ -298,9 +298,9 @@ func TestDeleteArticleReportsMissingArticle(t *testing.T) {
|
||||
t.Run("id_9", func(t *testing.T) {
|
||||
repo := newMockArticleRepo()
|
||||
repo.articles[1] = article.Article{ID: 1}
|
||||
uc := useCases.NewDeleteArticleUseCase(repo)
|
||||
uc := useCases.NewDeleteArticleUseCase(repo, discardRecorder)
|
||||
|
||||
err := uc.DeleteArticle(9)
|
||||
err := uc.DeleteArticle(testCtx, 9)
|
||||
if !errors.Is(err, article.ErrArticleNotFound) {
|
||||
t.Errorf("expected article.ErrArticleNotFound, got %v", err)
|
||||
}
|
||||
@@ -311,9 +311,9 @@ func TestDeleteArticlePropagatesRepositoryFailure(t *testing.T) {
|
||||
repo := newMockArticleRepo()
|
||||
repo.articles[1] = article.Article{ID: 1}
|
||||
repo.fail.failNext("Delete")
|
||||
uc := useCases.NewDeleteArticleUseCase(repo)
|
||||
uc := useCases.NewDeleteArticleUseCase(repo, discardRecorder)
|
||||
|
||||
err := uc.DeleteArticle(1)
|
||||
err := uc.DeleteArticle(testCtx, 1)
|
||||
if !errors.Is(err, errRepositoryFailure) {
|
||||
t.Errorf("expected repository failure, got %v", err)
|
||||
}
|
||||
@@ -334,13 +334,13 @@ func TestCreateImageDelegatesContentTypeCheck(t *testing.T) {
|
||||
for _, tc := range cases {
|
||||
t.Run(strings.ReplaceAll(tc.contentType, "/", "_"), func(t *testing.T) {
|
||||
repo := newMockImageRepo()
|
||||
uc := useCases.NewCreateImageUseCase(repo, newMockImageStorage())
|
||||
uc := useCases.NewCreateImageUseCase(repo, newMockImageStorage(), discardRecorder)
|
||||
|
||||
content := []byte("fake-image-data")
|
||||
if tc.valid {
|
||||
content = validBytesFor(t, tc.contentType)
|
||||
}
|
||||
result, err := uc.CreateImage(imageDomain.ImageInput{
|
||||
result, err := uc.CreateImage(testCtx, imageDomain.ImageInput{
|
||||
Content: bytes.NewReader(content),
|
||||
Filename: "test.img",
|
||||
ContentType: tc.contentType,
|
||||
@@ -368,9 +368,9 @@ func TestCreateImageDelegatesContentTypeCheck(t *testing.T) {
|
||||
func TestCreateImagePropagatesRepositoryFailure(t *testing.T) {
|
||||
repo := newMockImageRepo()
|
||||
repo.fail.failNext("Create")
|
||||
uc := useCases.NewCreateImageUseCase(repo, newMockImageStorage())
|
||||
uc := useCases.NewCreateImageUseCase(repo, newMockImageStorage(), discardRecorder)
|
||||
|
||||
_, err := uc.CreateImage(imageDomain.ImageInput{
|
||||
_, err := uc.CreateImage(testCtx, imageDomain.ImageInput{
|
||||
Content: bytes.NewReader(pngBytes(t, 3, 2)),
|
||||
Filename: "test.png",
|
||||
ContentType: "image/png",
|
||||
@@ -385,9 +385,9 @@ func TestDeleteImageRequiresExistence(t *testing.T) {
|
||||
t.Run("id_1", func(t *testing.T) {
|
||||
repo := newMockImageRepo()
|
||||
repo.images[1] = imageDomain.Image{ID: 1}
|
||||
uc := useCases.NewDeleteMediaUseCase(repo, newMockImageStorage())
|
||||
uc := useCases.NewDeleteMediaUseCase(repo, newMockImageStorage(), discardRecorder)
|
||||
|
||||
err := uc.Delete(1)
|
||||
err := uc.Delete(testCtx, 1)
|
||||
if err != nil {
|
||||
t.Fatalf("expected no error, got %v", err)
|
||||
}
|
||||
@@ -399,9 +399,9 @@ func TestDeleteImageRequiresExistence(t *testing.T) {
|
||||
t.Run("id_9", func(t *testing.T) {
|
||||
repo := newMockImageRepo()
|
||||
repo.images[1] = imageDomain.Image{ID: 1}
|
||||
uc := useCases.NewDeleteMediaUseCase(repo, newMockImageStorage())
|
||||
uc := useCases.NewDeleteMediaUseCase(repo, newMockImageStorage(), discardRecorder)
|
||||
|
||||
err := uc.Delete(9)
|
||||
err := uc.Delete(testCtx, 9)
|
||||
if !errors.Is(err, imageDomain.ErrImageNotFound) {
|
||||
t.Errorf("expected image.ErrImageNotFound, got %v", err)
|
||||
}
|
||||
@@ -410,10 +410,10 @@ func TestDeleteImageRequiresExistence(t *testing.T) {
|
||||
|
||||
func TestCreateUserAssignsVerificationCode(t *testing.T) {
|
||||
repo := newMockUserRepo()
|
||||
uc := useCases.NewCreateUserUseCase(repo, &stubHasher{}, newMockMailRepo(), "https://cms.example.com")
|
||||
uc := useCases.NewCreateUserUseCase(repo, &stubHasher{}, newMockMailRepo(), "https://cms.example.com", discardRecorder)
|
||||
|
||||
before := time.Now()
|
||||
result, err := uc.CreateUser(useCases.CreateUserCommand{
|
||||
result, err := uc.CreateUser(testCtx, useCases.CreateUserCommand{
|
||||
Username: "alice",
|
||||
Password: "hunter2example",
|
||||
Email: "alice@example.com",
|
||||
@@ -441,7 +441,7 @@ func TestCreateUserAssignsVerificationCode(t *testing.T) {
|
||||
t.Errorf("expected verification_expiration about 2 hours from now, got %v", result.VerificationExpiration)
|
||||
}
|
||||
|
||||
second, err := uc.CreateUser(useCases.CreateUserCommand{
|
||||
second, err := uc.CreateUser(testCtx, useCases.CreateUserCommand{
|
||||
Username: "bob",
|
||||
Password: "hunter2example",
|
||||
Email: "bob@example.com",
|
||||
@@ -457,9 +457,9 @@ func TestCreateUserAssignsVerificationCode(t *testing.T) {
|
||||
func TestCreateUserPropagatesRepositoryFailure(t *testing.T) {
|
||||
repo := newMockUserRepo()
|
||||
repo.fail.failNext("Create")
|
||||
uc := useCases.NewCreateUserUseCase(repo, &stubHasher{}, newMockMailRepo(), "https://cms.example.com")
|
||||
uc := useCases.NewCreateUserUseCase(repo, &stubHasher{}, newMockMailRepo(), "https://cms.example.com", discardRecorder)
|
||||
|
||||
_, err := uc.CreateUser(useCases.CreateUserCommand{
|
||||
_, err := uc.CreateUser(testCtx, useCases.CreateUserCommand{
|
||||
Username: "alice",
|
||||
Password: "hunter2example",
|
||||
Email: "alice@example.com",
|
||||
|
||||
Reference in new issue
Block a user