-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #127 from Kos-Kita/testingbooking
testing booking 28%
- Loading branch information
Showing
4 changed files
with
169 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
}) | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.