Skip to content

Commit

Permalink
add swagger, good test
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitriyKomarovCoder committed Nov 29, 2023
1 parent 7c47d67 commit be180d7
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 21 deletions.
21 changes: 16 additions & 5 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ const docTemplate = `{
}
}
},
"/api/auth/checkLogin/{login}": {
"get": {
"/api/auth/checkLogin/": {
"post": {
"description": "Get bool parametrs about unique login",
"produces": [
"application/json"
Expand Down Expand Up @@ -322,7 +322,7 @@ const docTemplate = `{
}
],
"responses": {
"202": {
"201": {
"description": "User Created",
"schema": {
"$ref": "#/definitions/http.Response-auth_SignResponse"
Expand Down Expand Up @@ -696,8 +696,8 @@ const docTemplate = `{
},
{
"type": "string",
"example": "2023-11-21T19:30:57+03:00",
"name": "date",
"example": "2023-12-21T19:30:57+03:00",
"name": "end_date",
"in": "query"
},
{
Expand All @@ -711,6 +711,12 @@ const docTemplate = `{
"example": true,
"name": "outcome",
"in": "query"
},
{
"type": "string",
"example": "2023-11-21T19:30:57+03:00",
"name": "start_date",
"in": "query"
}
],
"responses": {
Expand Down Expand Up @@ -1269,6 +1275,9 @@ const docTemplate = `{
"id": {
"type": "string"
},
"login": {
"type": "string"
},
"username": {
"type": "string"
}
Expand Down Expand Up @@ -1334,9 +1343,11 @@ const docTemplate = `{
"type": "object",
"properties": {
"account_income": {
"description": "???",
"type": "string"
},
"account_outcome": {
"description": "???",
"type": "string"
},
"categories": {
Expand Down
21 changes: 16 additions & 5 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@
}
}
},
"/api/auth/checkLogin/{login}": {
"get": {
"/api/auth/checkLogin/": {
"post": {
"description": "Get bool parametrs about unique login",
"produces": [
"application/json"
Expand Down Expand Up @@ -316,7 +316,7 @@
}
],
"responses": {
"202": {
"201": {
"description": "User Created",
"schema": {
"$ref": "#/definitions/http.Response-auth_SignResponse"
Expand Down Expand Up @@ -690,8 +690,8 @@
},
{
"type": "string",
"example": "2023-11-21T19:30:57+03:00",
"name": "date",
"example": "2023-12-21T19:30:57+03:00",
"name": "end_date",
"in": "query"
},
{
Expand All @@ -705,6 +705,12 @@
"example": true,
"name": "outcome",
"in": "query"
},
{
"type": "string",
"example": "2023-11-21T19:30:57+03:00",
"name": "start_date",
"in": "query"
}
],
"responses": {
Expand Down Expand Up @@ -1263,6 +1269,9 @@
"id": {
"type": "string"
},
"login": {
"type": "string"
},
"username": {
"type": "string"
}
Expand Down Expand Up @@ -1328,9 +1337,11 @@
"type": "object",
"properties": {
"account_income": {
"description": "???",
"type": "string"
},
"account_outcome": {
"description": "???",
"type": "string"
},
"categories": {
Expand Down
18 changes: 13 additions & 5 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ definitions:
properties:
id:
type: string
login:
type: string
username:
type: string
type: object
Expand Down Expand Up @@ -53,8 +55,10 @@ definitions:
http.CreateTransaction:
properties:
account_income:
description: ???
type: string
account_outcome:
description: ???
type: string
categories:
items:
Expand Down Expand Up @@ -542,8 +546,8 @@ paths:
summary: Validate Auth
tags:
- Auth
/api/auth/checkLogin/{login}:
get:
/api/auth/checkLogin/:
post:
description: Get bool parametrs about unique login
produces:
- application/json
Expand Down Expand Up @@ -608,7 +612,7 @@ paths:
produces:
- application/json
responses:
"202":
"201":
description: User Created
schema:
$ref: '#/definitions/http.Response-auth_SignResponse'
Expand Down Expand Up @@ -879,9 +883,9 @@ paths:
in: query
name: category
type: string
- example: "2023-11-21T19:30:57+03:00"
- example: "2023-12-21T19:30:57+03:00"
in: query
name: date
name: end_date
type: string
- example: true
in: query
Expand All @@ -891,6 +895,10 @@ paths:
in: query
name: outcome
type: boolean
- example: "2023-11-21T19:30:57+03:00"
in: query
name: start_date
type: string
produces:
- application/json
responses:
Expand Down
4 changes: 2 additions & 2 deletions internal/common/http/request_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ func GetQueryParam(r *http.Request) (*models.QueryListOptions, error) {
}
}

startDateStr := values.Get("startDate")
endDateStr := values.Get("endDate")
startDateStr := values.Get("start_date")
endDateStr := values.Get("end_date")

if startDateStr != "" {
params.StartDate, err = time.Parse(time.RFC3339, startDateStr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,18 +155,18 @@ func TestHandler_GetFeed(t *testing.T) {
},
},
{
name: "Invalid Query outcome",
name: "Invalid Query start_date",
user: user,
queryParam: "outcome='trueee'",
queryParam: "start_date='trueee'",
expectedCode: http.StatusBadRequest,
expectedBody: `{"status":400,"message":"invalid url parameter"}`,
mockUsecaseFn: func(mockUsecase *mocks.MockUsecase) {
},
},
{
name: "Invalid Query outcome",
name: "Invalid Query end_date",
user: user,
queryParam: "date='trueee'",
queryParam: "end_date='trueee'",
expectedCode: http.StatusBadRequest,
expectedBody: `{"status":400,"message":"invalid url parameter"}`,
mockUsecaseFn: func(mockUsecase *mocks.MockUsecase) {
Expand Down
4 changes: 4 additions & 0 deletions scripts/coverage_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
go test -coverprofile=coverage.out.tmp -coverpkg=./... ./...
cat coverage.out.tmp | grep -v _mock.go | grep -v _easyjson.go | grep -v .pb.go | grep -v _grpc.go > coverage.out
go tool cover -func=coverage.out
go tool cover -html=coverage.out -o coverage.html

0 comments on commit be180d7

Please sign in to comment.