Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/go_modules/backend/github.com/aws…
Browse files Browse the repository at this point in the history
…/aws-sdk-go-1.52.2
  • Loading branch information
garrettladley authored May 7, 2024
2 parents 9abb564 + 6d5fe10 commit b71c024
Show file tree
Hide file tree
Showing 17 changed files with 896 additions and 480 deletions.
1 change: 1 addition & 0 deletions backend/entities/clubs/tag/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ func ClubTag(clubParams types.RouteParams) {

clubTags := clubParams.Router.Group("/tags")

// api/v1/clubs/:clubID/tags/*
clubTags.Get("/", clubTagController.GetClubTags)
clubTags.Post("/", clubParams.AuthMiddleware.ClubAuthorizeById, clubTagController.CreateClubTags)
clubTags.Delete("/:tagID", clubParams.AuthMiddleware.ClubAuthorizeById, clubTagController.DeleteClubTag)
Expand Down
2 changes: 1 addition & 1 deletion backend/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5
github.com/aws/aws-sdk-go v1.52.2
github.com/garrettladley/mattress v0.4.0
github.com/go-playground/validator/v10 v10.19.0
github.com/go-playground/validator/v10 v10.20.0
github.com/goccy/go-json v0.10.2
github.com/gofiber/fiber/v2 v2.52.4
github.com/gofiber/swagger v1.0.0
Expand Down
4 changes: 2 additions & 2 deletions backend/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/o
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.19.0 h1:ol+5Fu+cSq9JD7SoSqe04GMI92cbn0+wvQ3bZ8b/AU4=
github.com/go-playground/validator/v10 v10.19.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBExVwjEviJTixqxL8=
github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/gofiber/fiber/v2 v2.52.4 h1:P+T+4iK7VaqUsq2PALYEfBBo6bJZ4q3FP8cZ84EggTM=
Expand Down
180 changes: 179 additions & 1 deletion backend/tests/api/club_member_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,57 @@ import (
"testing"

"github.com/GenerateNU/sac/backend/entities/models"
"github.com/GenerateNU/sac/backend/errors"
h "github.com/GenerateNU/sac/backend/tests/api/helpers"
"github.com/goccy/go-json"
"github.com/gofiber/fiber/v2"
"github.com/google/uuid"
)

func TestCreateMembershipWorks(t *testing.T) {
appAssert, _, clubUUID := CreateSampleClub(h.InitTest(t))

appAssert.TestOnStatusAndTester(
h.TestRequest{
Method: fiber.MethodPost,
Path: fmt.Sprintf("/api/v1/clubs/%s/members/:userID", clubUUID),
Role: &models.Super,
TestUserIDReplaces: h.StringToPointer(":userID"),
},
h.TesterWithStatus{
Status: fiber.StatusCreated,
Tester: func(eaa h.ExistingAppAssert, resp *http.Response) {
var user models.User

err := eaa.App.Conn.Where("id = ?", eaa.App.TestUser.UUID).Preload("Member").First(&user)

eaa.Assert.NilError(err)

eaa.Assert.Equal(2, len(user.Member)) // SAC Super Club and the one just added

eaa.Assert.Equal(clubUUID, user.Member[1].ID) // second club AKA the one just added

var club models.Club

err = eaa.App.Conn.Where("id = ?", clubUUID).Preload("Member").First(&club)

eaa.Assert.NilError(err)

eaa.Assert.Equal(1, len(club.Member))

eaa.Assert.Equal(eaa.App.TestUser.UUID, club.Member[0].ID)
},
},
).Close()
}

func TestClubMemberWorks(t *testing.T) {
appAssert, _, clubUUID := CreateSampleClub(h.InitTest(t))

appAssert.TestOnStatus(
h.TestRequest{
Method: fiber.MethodPost,
Path: fmt.Sprintf("/api/v1/users/:userID/member/%s", clubUUID),
Path: fmt.Sprintf("/api/v1/clubs/%s/members/:userID", clubUUID),
Role: &models.Super,
TestUserIDReplaces: h.StringToPointer(":userID"),
},
Expand Down Expand Up @@ -56,3 +95,142 @@ func TestClubMemberWorks(t *testing.T) {
},
).Close()
}

func TestCreateMembershipFailsClubIdNotExists(t *testing.T) {
appAssert, _, _ := CreateSampleClub(h.InitTest(t))

uuid := uuid.New()

appAssert.TestOnErrorAndTester(
h.TestRequest{
Method: fiber.MethodPost,
Path: fmt.Sprintf("/api/v1/clubs/%s/members/:userID", uuid),
Role: &models.Super,
TestUserIDReplaces: h.StringToPointer(":userID"),
},
h.ErrorWithTester{
Error: errors.ClubNotFound,
Tester: func(eaa h.ExistingAppAssert, resp *http.Response) {
var club models.Club

err := eaa.App.Conn.Where("id = ?", uuid).First(&club).Error

eaa.Assert.Assert(err != nil)
},
},
).Close()
}

func TestCreateMembershipFailsUserIdNotExists(t *testing.T) {
appAssert, _, clubUUID := CreateSampleClub(h.InitTest(t))

uuid := uuid.New()

appAssert.TestOnErrorAndTester(
h.TestRequest{
Method: fiber.MethodPost,
Path: fmt.Sprintf("/api/v1/clubs/%s/members/%s", clubUUID, uuid),
Role: &models.Super,
},
h.ErrorWithTester{
Error: errors.UserNotFound,
Tester: func(eaa h.ExistingAppAssert, resp *http.Response) {
var user models.User

err := eaa.App.Conn.Where("id = ?", uuid).First(&user).Error

eaa.Assert.Assert(err != nil)
},
},
).Close()
}

func TestDeleteMembershipWorks(t *testing.T) {
appAssert, _, clubUUID := CreateSampleClub(h.InitTest(t))

appAssert.TestOnStatus(
h.TestRequest{
Method: fiber.MethodPost,
Path: fmt.Sprintf("/api/v1/clubs/%s/members/:userID", clubUUID),
Role: &models.Super,
TestUserIDReplaces: h.StringToPointer(":userID"),
},
fiber.StatusCreated,
).TestOnStatusAndTester(
h.TestRequest{
Method: fiber.MethodDelete,
Path: fmt.Sprintf("/api/v1/clubs/%s/members/:userID", clubUUID),
Role: &models.Super,
TestUserIDReplaces: h.StringToPointer(":userID"),
},
h.TesterWithStatus{
Status: fiber.StatusNoContent,
Tester: func(eaa h.ExistingAppAssert, resp *http.Response) {
var user models.User

err := eaa.App.Conn.Where("id = ?", eaa.App.TestUser.UUID).Preload("Member").First(&user)

eaa.Assert.NilError(err)

eaa.Assert.Equal(1, len(user.Member)) // SAC Super Club

var club models.Club

err = eaa.App.Conn.Where("id = ?", clubUUID).Preload("Member").First(&club)

eaa.Assert.NilError(err)

eaa.Assert.Equal(0, len(club.Member))
},
},
).Close()
}

func TestDeleteMembershipFailsClubIdNotExists(t *testing.T) {
appAssert, _, _ := CreateSampleClub(h.InitTest(t))

uuid := uuid.New()

appAssert.TestOnErrorAndTester(
h.TestRequest{
Method: fiber.MethodDelete,
Path: fmt.Sprintf("/api/v1/clubs/%s/members/:userID", uuid),
Role: &models.Super,
TestUserIDReplaces: h.StringToPointer(":userID"),
},
h.ErrorWithTester{
Error: errors.ClubNotFound,
Tester: func(eaa h.ExistingAppAssert, resp *http.Response) {
var club models.Club

err := eaa.App.Conn.Where("id = ?", uuid).First(&club).Error

eaa.Assert.Assert(err != nil)
},
},
).Close()
}

func TestDeleteMembershipFailsUserIdNotExists(t *testing.T) {
appAssert, _, clubUUID := CreateSampleClub(h.InitTest(t))

uuid := uuid.New()

appAssert.TestOnErrorAndTester(
h.TestRequest{
Method: fiber.MethodDelete,
Path: fmt.Sprintf("/api/v1/clubs/%s/members/%s", clubUUID, uuid),
Role: &models.Super,
},
h.ErrorWithTester{
Error: errors.UserNotFound,
Tester: func(eaa h.ExistingAppAssert, resp *http.Response) {
var user models.User

err := eaa.App.Conn.Where("id = ?", uuid).First(&user).Error

eaa.Assert.Assert(err != nil)
},
},
).Close()
}
Loading

0 comments on commit b71c024

Please sign in to comment.