forked from zopsmart/ezgo
-
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.
added coverage.txt into .gitignore and solved some linter warnings
- Loading branch information
Showing
8 changed files
with
66 additions
and
72 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ func TestHTTPLayer(t *testing.T) { | |
db, _, _ := sqlmock.New() | ||
c := &gofr.Context{Container: &gofr.Container{ | ||
Logger: logging.NewLogger(logging.DEBUG), | ||
DB: &gofr.DB{db}, | ||
DB: &gofr.DB{DB: db}, | ||
}} | ||
|
||
testCreateEmployeeHTTP(t, c) | ||
|
@@ -136,7 +136,6 @@ func testGetEmployeeByIDHTTP(t *testing.T, c *gofr.Context) { | |
} | ||
|
||
for i := range testcases { | ||
//req := httptest.NewRequest(http.MethodGet, fmt.Sprintf("/{%s}/employees", testcases[i].input.companyID), bytes.NewBuffer(testcases[i].input.Emp)) | ||
req := httptest.NewRequest(http.MethodGet, "/someURL/", nil) | ||
req = mux.SetURLVars(req, map[string]string{"companyID": testcases[i].input.companyID, "employeeID": testcases[i].input.employeeID}) | ||
gofrReq := gofrHTTP.NewRequest(req) | ||
|
@@ -195,7 +194,7 @@ func testEditEmployeeHTTP(t *testing.T, c *gofr.Context) { | |
}, | ||
} | ||
|
||
for i, _ := range testcases { | ||
for i := range testcases { | ||
req := httptest.NewRequest(http.MethodPut, "/someURL/", nil) | ||
req = mux.SetURLVars(req, map[string]string{"companyID": testcases[i].input.companyID, "employeeID": testcases[i].input.employeeID}) | ||
gofrReq := gofrHTTP.NewRequest(req) | ||
|
@@ -306,7 +305,7 @@ func (m mockService) CreateEmployee(c *gofr.Context, companyID int, emp *models. | |
return models.Employee{}, customerror.ErrDBServer | ||
} | ||
|
||
func (m mockService) GetEmployeeByID(c *gofr.Context, companyID int, employeeID int) (models.Employee, error) { | ||
func (m mockService) GetEmployeeByID(c *gofr.Context, companyID, employeeID int) (models.Employee, error) { | ||
if companyID == 1 && employeeID == 1 { | ||
return models.Employee{ID: 1, Name: "Ishan Pandey", Email: "[email protected]", Phone: 7250073079, Designation: "SDE1", YOE: 2, CompanyID: 1}, nil | ||
} | ||
|
@@ -323,7 +322,7 @@ func (m mockService) GetAllEmployee(c *gofr.Context, companyID int, queryParams | |
return nil, customerror.ErrDBServer | ||
} | ||
|
||
func (m mockService) EditEmployee(c *gofr.Context, companyID int, employeeID int, emp *models.Employee) (models.Employee, error) { | ||
func (m mockService) EditEmployee(c *gofr.Context, companyID, employeeID int, emp *models.Employee) (models.Employee, error) { | ||
if companyID == 1 && employeeID == 3 { | ||
return models.Employee{ID: 3, Name: "Ishanx Pandey", Email: "[email protected]", Phone: 7250073079, Designation: "SDE1", YOE: 2, CompanyID: 1}, nil | ||
} | ||
|
@@ -333,6 +332,6 @@ func (m mockService) EditEmployee(c *gofr.Context, companyID int, employeeID int | |
return models.Employee{}, customerror.ErrDBServer | ||
} | ||
|
||
func (m mockService) DeleteEmployee(c *gofr.Context, companyID int, employeeID int) error { | ||
func (m mockService) DeleteEmployee(c *gofr.Context, companyID, employeeID int) error { | ||
return nil | ||
} |
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 |
---|---|---|
|
@@ -25,7 +25,7 @@ func TestServiceLayer(t *testing.T) { | |
db, _, _ := sqlmock.New() | ||
c := &gofr.Context{Container: &gofr.Container{ | ||
Logger: logging.NewLogger(logging.DEBUG), | ||
DB: &gofr.DB{db}, | ||
DB: &gofr.DB{DB: db}, | ||
}} | ||
|
||
testCreateEmployeeService(t, c) | ||
|
@@ -36,8 +36,7 @@ func TestServiceLayer(t *testing.T) { | |
} | ||
|
||
func testAllEmployeeService(t *testing.T, c *gofr.Context) { | ||
|
||
testCases := []struct { | ||
var testCases = []struct { | ||
input int | ||
expectedOutput []models.Employee | ||
expectedErr error | ||
|
@@ -46,7 +45,7 @@ func testAllEmployeeService(t *testing.T, c *gofr.Context) { | |
{ | ||
input: 1, | ||
expectedOutput: []models.Employee{{1, "Bittu", "[email protected]", 7250073079, "sde1", 2, 1}, | ||
{2, "Bittu Ray", "[email protected]", 7250073080, "sde2", 2, 1}, | ||
{ID: 2, Name: "Bittu Ray", Email: "[email protected]", Phone: 7250073080, Designation: "sde2", YOE: 2, CompanyID: 1}, | ||
}, | ||
expectedErr: nil, | ||
queryParams: map[string]interface{}{ | ||
|
@@ -92,7 +91,6 @@ func testAllEmployeeService(t *testing.T, c *gofr.Context) { | |
}, | ||
}, | ||
} | ||
|
||
for i := range testCases { | ||
dataService := New(mockStore{}) | ||
output, err := dataService.GetAllEmployee(c, testCases[i].input, testCases[i].queryParams) | ||
|
@@ -111,7 +109,7 @@ func testEmployeeByIDService(t *testing.T, c *gofr.Context) { | |
}{ | ||
{ | ||
input: inputData{1, 1}, | ||
expectedOutput: models.Employee{1, "Bittu", "[email protected]", 7250073079, "sde1", 2, 1}, | ||
expectedOutput: models.Employee{ID: 1, Name: "Bittu", Email: "[email protected]", Phone: 7250073079, Designation: "sde1", YOE: 2, CompanyID: 1}, | ||
expectedErr: nil, | ||
}, | ||
|
||
|
@@ -141,7 +139,6 @@ func testEmployeeByIDService(t *testing.T, c *gofr.Context) { | |
} | ||
|
||
func testCreateEmployeeService(t *testing.T, c *gofr.Context) { | ||
|
||
type InputData struct { | ||
companyID int | ||
body models.Employee | ||
|
@@ -197,7 +194,6 @@ func testCreateEmployeeService(t *testing.T, c *gofr.Context) { | |
output, err := dataService.CreateEmployee(c, testCases[i].input.companyID, &testCases[i].input.body) | ||
CheckErrOutput(t, testCases[i].expectedErr, err, testCases[i].expectedOutput, output) | ||
} | ||
|
||
} | ||
|
||
func testEditEmployeeService(t *testing.T, c *gofr.Context) { | ||
|
@@ -242,11 +238,8 @@ func testEditEmployeeService(t *testing.T, c *gofr.Context) { | |
&testCases[i].input.body) | ||
CheckErrOutput(t, testCases[i].expectedErr, err, testCases[i].expectedOutput, output) | ||
} | ||
|
||
} | ||
|
||
func testDeleteEmployeeService(t *testing.T, c *gofr.Context) { | ||
|
||
type InputData struct { | ||
companyID int | ||
employeeID int | ||
|
@@ -304,11 +297,9 @@ func (m mockStore) GetAllEmployeeWithoutDesignation(c *gofr.Context, companyID i | |
if companyID == 2 { | ||
return nil, customerror.ErrDBServer | ||
} | ||
|
||
res := []models.Employee{{1, "Bittu", "[email protected]", 7250073079, "sde1", 2, 1}, | ||
{2, "Bittu Ray", "[email protected]", 7250073080, "sde2", 2, 1}, | ||
} | ||
|
||
return res, nil | ||
} | ||
|
||
|
@@ -319,9 +310,7 @@ func (m mockStore) GetEmployeeByID(c *gofr.Context, companyID, employeeID int) ( | |
if companyID != employeeID { | ||
return models.Employee{}, customerror.ErrRecordNotFound | ||
} | ||
|
||
return models.Employee{}, nil | ||
|
||
} | ||
|
||
func (m mockStore) CreateEmployee(c *gofr.Context, companyID int, emp *models.Employee) (int, error) { | ||
|
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
Oops, something went wrong.