-
Notifications
You must be signed in to change notification settings - Fork 0
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
Attemped unit tests + refactoring code #53
Conversation
} | ||
|
||
// Implement the CreatePreferences method for the MockStore | ||
func (m *MockStore) CreatePreferences(ctx context.Context, preferences models.Preferences) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This mock looks right, super clean
return nil | ||
} | ||
|
||
// Implement the UpdateProfilePreferences method for the MockStore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work abyan, looks awesome
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great work here @abyan-n !
return c.Status(fiber.StatusCreated).JSON(req) | ||
// Call CreateFriendship method to interact with db | ||
if err := s.store.CreateFriendship(c.Context(), req); err != nil { | ||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with the central error handler, can just bubble up an errors.New("failed to create friendship")
var req models.Friendship | ||
// Parse the request body and check for errors | ||
if err := c.BodyParser(&req); err != nil { | ||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would recommend using errs.InvalidJSON(err)
. would refactor that func to be
func InvalidJSON(err error) APIError {
return NewAPIError(http.StatusBadRequest, err)
}
so we can drill down the actual error to the client. more ergonomic since we can tell them they forgot to close with a }
instead of a blanket Cannot parse JSON
} | ||
|
||
// On success, return 201 and req body | ||
return c.Status(fiber.StatusCreated).JSON(req) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good stuff
) | ||
|
||
// Mock Service structure | ||
type MockStore struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would prob want to convert this to and interface then move it to backend/internal/handlers/friendship/friendship.go
. then have your actual and your mock impl the interface.
Description
No Ticket
Please include a summary of the changes and the related issue. Please also
include relevant motivation, context, and images!
Adding unit tests for friendship handler routes -- only create friendship as of now
Refactored createFriendship endpoint and the route definiton
How Has This Been Tested?
Unit tests
Checklist