Skip to content

Commit

Permalink
Merge pull request #127 from Kos-Kita/testingbooking
Browse files Browse the repository at this point in the history
testing booking 28%
  • Loading branch information
lendral3n authored Feb 16, 2024
2 parents f39a6c0 + 0405148 commit f5ff95f
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 19 deletions.
1 change: 0 additions & 1 deletion features/booking/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package service
import (
"KosKita/features/booking"
"errors"
// _midtransService "BE-REPO-20/features/midtrans/service"
)

type bookingService struct {
Expand Down
55 changes: 55 additions & 0 deletions features/booking/service/service_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package service

import (
"KosKita/features/booking"
"KosKita/mocks"
"errors"
"testing"

"github.com/stretchr/testify/assert"
)

func TestPostBooking(t *testing.T) {
repo := new(mocks.BookDataInterface)
srv := NewBooking(repo)

input := booking.BookingCore{
ID: "10843",
UserID: 1,
BoardingHouseId: 1,
StartDate: "2024-01-01",
EndDate: "2024-12-31",
PaymentType: "credit_card",
Total: 100000,
Bank: "BCA",
}

// response := booking.BookingCore{
// ID: "10843",
// StartDate: "2024-01-01",
// EndDate: "2024-12-31",
// PaymentType: "credit_card",
// Total: 100000,
// Status: "pending",
// Bank: "BCA",
// VirtualNumber: "1234567890",
// ExpiredAt: "2024-12-31",
// }

t.Run("invalid user id", func(t *testing.T) {
_, err := srv.PostBooking(0, input)

assert.Error(t, err)
assert.EqualError(t, err, "invalid id")
})

t.Run("error from repository", func(t *testing.T) {
repo.On("PostBooking", uint(1), input).Return(nil, errors.New("database error"))

_, err := srv.PostBooking(1, input)

assert.Error(t, err)
assert.EqualError(t, err, "database error")
})

}
66 changes: 57 additions & 9 deletions mocks/ChatDataInterface.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 57 additions & 9 deletions mocks/ChatServiceInterface.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f5ff95f

Please sign in to comment.