-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(admin): Adding support APIs For Admin (#44)
* feat: Get All Inactive User API Added * Two Tests Added * Some Test Written * Some Chnages
- Loading branch information
Showing
9 changed files
with
371 additions
and
2 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,21 @@ | ||
package tradeuser | ||
|
||
import ( | ||
"github.com/gofiber/fiber/v2" | ||
"github.com/rpsoftech/bullion-server/src/interfaces" | ||
"github.com/rpsoftech/bullion-server/src/services" | ||
) | ||
|
||
func apiGetInActiveTradeUsers(c *fiber.Ctx) error { | ||
bullionId, err := interfaces.ExtractBullionIdFromCtx(c) | ||
if err != nil { | ||
return err | ||
} | ||
entity, err := services.TradeUserService.FindAndReturnAllInActiveTradeUsers(bullionId) | ||
if err != nil { | ||
return err | ||
} else { | ||
return c.JSON(entity) | ||
} | ||
|
||
} |
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,47 @@ | ||
package interfaces | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestAdminUserEntity(t *testing.T) { | ||
e := &AdminUserEntity{} | ||
// // c.createNewId() | ||
// Admin() | ||
t.Run("Create New Admin Entity", func(t *testing.T) { | ||
if e.BaseEntity != nil { | ||
t.Fatalf("BaseEntity is not nil") | ||
} | ||
if e.UserRolesInterface != nil { | ||
t.Fatalf("UserRolesInterface is not nil") | ||
} | ||
e.CreateNewEntity("admin", "password", "nickName", "bullionId") | ||
if e.BaseEntity == nil { | ||
t.Fatalf("BaseEntity is nil") | ||
} | ||
if e.UserName != "admin" { | ||
t.Fatalf("UserName is not admin") | ||
} | ||
if e.Password != "password" { | ||
t.Fatalf("Password is not password") | ||
} | ||
if e.NickName != "nickName" { | ||
t.Fatalf("NickName is not nickName") | ||
} | ||
if e.BullionId != "bullionId" { | ||
t.Fatalf("BullionId is not bullionId") | ||
} | ||
if e.UserRolesInterface == nil { | ||
t.Fatalf("UserRolesInterface is nil") | ||
} | ||
if e.UserRolesInterface.Role != ROLE_ADMIN { | ||
t.Fatalf("UserRolesInterface Role is not ROLE_ADMIN") | ||
} | ||
testBaseEntityCreateNewId(t, e.BaseEntity) | ||
t.Run("password match", func(t *testing.T) { | ||
if !e.MatchPassword("password") { | ||
t.Fatalf("Password does not match") | ||
} | ||
}) | ||
}) | ||
} |
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,71 @@ | ||
package interfaces | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
) | ||
|
||
func testBaseEntityCreateNewId(t *testing.T, c *BaseEntity) { | ||
|
||
if c.ID == "" { | ||
t.Fatalf("Id is empty") | ||
} | ||
|
||
if c.CreatedAt.IsZero() { | ||
t.Fatalf("CreatedAt is empty") | ||
} | ||
if c.ModifiedAt.IsZero() { | ||
t.Fatalf("ModifiedAt is empty") | ||
} | ||
if !c.CreatedAtExported.IsZero() { | ||
t.Fatalf("CreatedAtExported is not empty %d", c.CreatedAtExported.Unix()) | ||
} | ||
if !c.ModifiedAtExported.IsZero() { | ||
t.Fatalf("ModifiedAtExported is not empty") | ||
} | ||
} | ||
|
||
func TestBaseEntity(t *testing.T) { | ||
c := &BaseEntity{} | ||
c.createNewId() | ||
t.Run("Create New ID", func(t *testing.T) { | ||
id := c.ID | ||
c.createNewId() | ||
if c.ID == id { | ||
t.Fatalf("Id Should Be Different") | ||
} | ||
testBaseEntityCreateNewId(t, c) | ||
}) | ||
t.Run("AddTimeStamps", func(t *testing.T) { | ||
now := time.Now() | ||
c.CreatedAt = now | ||
c.ModifiedAt = now | ||
c.AddTimeStamps() | ||
if c.CreatedAtExported != now { | ||
t.Fatalf("CreatedAt and CreatedAtExported Should be same") | ||
} | ||
if c.ModifiedAtExported != now { | ||
t.Fatalf("ModifiedAt and ModifiedAtExported Should be same") | ||
} | ||
}) | ||
t.Run("RestoreTimeStamp", func(t *testing.T) { | ||
now := time.Now() | ||
c.CreatedAtExported = now | ||
c.ModifiedAtExported = now | ||
c.RestoreTimeStamp() | ||
if c.CreatedAt != now { | ||
t.Fatalf("CreatedAt and CreatedAtExported Should be same") | ||
} | ||
if c.ModifiedAt != now { | ||
t.Fatalf("ModifiedAt and ModifiedAtExported Should be same") | ||
} | ||
}) | ||
t.Run("Updated", func(t *testing.T) { | ||
now := time.Now() | ||
c.ModifiedAt = now | ||
c.Updated() | ||
if c.ModifiedAt.Before(now) { | ||
t.Fatalf("ModifiedAt Should be greater than now") | ||
} | ||
}) | ||
} |
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
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