Skip to content

Commit

Permalink
another resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
JolyBI3ll committed Dec 20, 2024
1 parent 26c9184 commit 042191a
Showing 1 changed file with 0 additions and 67 deletions.
67 changes: 0 additions & 67 deletions microservices/ads_service/repository/ads_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -655,73 +655,6 @@ func TestUpdatePlace_UserNotAuthorized(t *testing.T) {
assert.NoError(t, err)
}

func TestDeletePlace(t *testing.T) {
if err := logger.InitLoggers(); err != nil {
log.Fatalf("Failed to initialize loggers: %v", err)
}
defer func() {
err := logger.SyncLoggers()
if err != nil {
return
}
}()

db, mock, err := setupDBMock()
assert.Nil(t, err)

adRepo := NewAdRepository(db)
ctx := context.Background()

adId := "1"
userId := "123"

mock.ExpectQuery(regexp.QuoteMeta(`SELECT * FROM "ads" WHERE uuid = $1 ORDER BY "ads"."uuid" LIMIT $2`)).
WithArgs(adId, 1).
WillReturnRows(sqlmock.NewRows([]string{"uuid", "address", "authorUUID"}).
AddRow("1", "test_address", "123"))

mock.ExpectBegin()
mock.ExpectExec(regexp.QuoteMeta(`DELETE FROM "images" WHERE "adId" = $1`)).
WithArgs(adId).
WillReturnResult(sqlmock.NewResult(1, 1))
mock.ExpectCommit()

mock.ExpectBegin()
mock.ExpectExec(regexp.QuoteMeta(`DELETE FROM "ad_positions" WHERE "adId" = $1`)).
WithArgs(adId).
WillReturnResult(sqlmock.NewResult(1, 1))
mock.ExpectCommit()

mock.ExpectBegin()
mock.ExpectExec(regexp.QuoteMeta(`DELETE FROM "ad_available_dates" WHERE "adId" = $1`)).
WithArgs(adId).
WillReturnResult(sqlmock.NewResult(1, 1))
mock.ExpectCommit()

mock.ExpectBegin()
mock.ExpectExec(regexp.QuoteMeta(`DELETE FROM "ad_rooms" WHERE "adId" = $1`)).
WithArgs(adId).
WillReturnResult(sqlmock.NewResult(1, 1))
mock.ExpectCommit()

mock.ExpectBegin()
mock.ExpectExec(regexp.QuoteMeta(`DELETE FROM "requests" WHERE "adId" = $1`)).
WithArgs(adId).
WillReturnResult(sqlmock.NewResult(1, 1))
mock.ExpectCommit()

mock.ExpectBegin()
mock.ExpectExec(regexp.QuoteMeta(`DELETE FROM "ads" WHERE "ads"."uuid" = $1`)).
WithArgs(adId).
WillReturnResult(sqlmock.NewResult(1, 1))
mock.ExpectCommit()

err = adRepo.DeletePlace(ctx, adId, userId)

assert.NoError(t, err)
assert.NoError(t, mock.ExpectationsWereMet())
}

func TestDeletePlace_Failure(t *testing.T) {
if err := logger.InitLoggers(); err != nil {
log.Fatalf("Failed to initialize loggers: %v", err)
Expand Down

0 comments on commit 042191a

Please sign in to comment.