Skip to content

Commit

Permalink
✅ Add login test case (#388)
Browse files Browse the repository at this point in the history
  • Loading branch information
tosone authored Jul 7, 2024
1 parent 7a1b18a commit 2ada28d
Show file tree
Hide file tree
Showing 11 changed files with 173 additions and 242 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
./scripts/run_minio.sh
sleep 5
- name: Download cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: /home/runner/.cache/go-build
key: ${{ runner.os }}-go-test-sqlite3-${{ github.sha }}
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ gormgen: ## Generate gorm model from database
@$(GOCMD) run ./pkg/dal/cmd/gen.go

swagen: ## Generate swagger from code comments
# go install github.com/swaggo/swag/cmd/swag@latest
@swag fmt
@swag init --output pkg/handlers/apidocs

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ require (
github.com/googleapis/gax-go/v2 v2.12.3 // indirect
github.com/gopherjs/gopherjs v1.17.2 // indirect
github.com/gorilla/mux v1.8.1 // indirect
github.com/gorilla/schema v1.3.0 // indirect
github.com/gorilla/schema v1.4.1 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/gosuri/uitable v0.0.4 // indirect
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -987,8 +987,8 @@ github.com/gorilla/handlers v1.5.2 h1:cLTUSsNkgcwhgRqvCNmdbRWG0A3N4F+M2nWKdScwyE
github.com/gorilla/handlers v1.5.2/go.mod h1:dX+xVpaxdSw+q0Qek8SSsl3dfMk3jNddUkMzo0GtH0w=
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
github.com/gorilla/schema v1.3.0 h1:rbciOzXAx3IB8stEFnfTwO3sYa6EWlQk79XdyustPDA=
github.com/gorilla/schema v1.3.0/go.mod h1:Dg5SSm5PV60mhF2NFaTV1xuYYj8tV8NOPRo4FggUMnM=
github.com/gorilla/schema v1.4.1 h1:jUg5hUjCSDZpNGLuXQOgIWGdlgrIdYvgQ0wZtdK1M3E=
github.com/gorilla/schema v1.4.1/go.mod h1:Dg5SSm5PV60mhF2NFaTV1xuYYj8tV8NOPRo4FggUMnM=
github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
Expand Down
32 changes: 32 additions & 0 deletions pkg/handlers/apidocs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4599,6 +4599,17 @@ const docTemplate = `{
"User"
],
"summary": "Login user",
"parameters": [
{
"description": "User login object",
"name": "message",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/types.PostUserLoginRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
Expand Down Expand Up @@ -7120,6 +7131,27 @@ const docTemplate = `{
}
}
},
"types.PostUserLoginRequest": {
"type": "object",
"required": [
"password",
"username"
],
"properties": {
"password": {
"type": "string",
"maxLength": 20,
"minLength": 5,
"example": "Admin@123"
},
"username": {
"type": "string",
"maxLength": 20,
"minLength": 2,
"example": "sigma"
}
}
},
"types.PostUserLoginResponse": {
"type": "object",
"properties": {
Expand Down
32 changes: 32 additions & 0 deletions pkg/handlers/apidocs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -4591,6 +4591,17 @@
"User"
],
"summary": "Login user",
"parameters": [
{
"description": "User login object",
"name": "message",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/types.PostUserLoginRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
Expand Down Expand Up @@ -7112,6 +7123,27 @@
}
}
},
"types.PostUserLoginRequest": {
"type": "object",
"required": [
"password",
"username"
],
"properties": {
"password": {
"type": "string",
"maxLength": 20,
"minLength": 5,
"example": "Admin@123"
},
"username": {
"type": "string",
"maxLength": 20,
"minLength": 2,
"example": "sigma"
}
}
},
"types.PostUserLoginResponse": {
"type": "object",
"properties": {
Expand Down
23 changes: 23 additions & 0 deletions pkg/handlers/apidocs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,22 @@ definitions:
example: 21911
type: integer
type: object
types.PostUserLoginRequest:
properties:
password:
example: Admin@123
maxLength: 20
minLength: 5
type: string
username:
example: sigma
maxLength: 20
minLength: 2
type: string
required:
- password
- username
type: object
types.PostUserLoginResponse:
properties:
email:
Expand Down Expand Up @@ -4725,6 +4741,13 @@ paths:
post:
consumes:
- application/json
parameters:
- description: User login object
in: body
name: message
required: true
schema:
$ref: '#/definitions/types.PostUserLoginRequest'
produces:
- application/json
responses:
Expand Down
7 changes: 4 additions & 3 deletions pkg/handlers/users/users_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ import (
// @Accept json
// @Produce json
// @Router /users/login [post]
// @Failure 500 {object} xerrors.ErrCode
// @Failure 401 {object} xerrors.ErrCode
// @Success 200 {object} types.PostUserLoginResponse
// @Param message body types.PostUserLoginRequest true "User login object"
// @Failure 500 {object} xerrors.ErrCode
// @Failure 401 {object} xerrors.ErrCode
// @Success 200 {object} types.PostUserLoginResponse
func (h *handler) Login(c echo.Context) error {
ctx := log.Logger.WithContext(c.Request().Context())

Expand Down
Loading

0 comments on commit 2ada28d

Please sign in to comment.