Skip to content

Commit

Permalink
refactor: refactor IntervalAction test to use factory method
Browse files Browse the repository at this point in the history
Close #535

Signed-off-by: weichou <weichou1229@gmail.com>
  • Loading branch information
weichou1229 committed Mar 9, 2021
1 parent 81d8f1f commit 766e8bf
Showing 1 changed file with 7 additions and 24 deletions.
31 changes: 7 additions & 24 deletions v2/dtos/requests/intervalaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,9 @@ import (
)

func addIntervalActionRequestData() AddIntervalActionRequest {
return AddIntervalActionRequest{
BaseRequest: common.BaseRequest{
RequestId: ExampleUUID,
Versionable: common.NewVersionable(),
},
Action: dtos.IntervalAction{
Versionable: common.NewVersionable(),
Name: TestIntervalActionName,
IntervalName: TestIntervalName,
Address: dtos.Address{
Type: v2.REST,
Host: TestHost,
Port: TestPort,
RESTAddress: dtos.RESTAddress{HTTPMethod: TestHTTPMethod},
},
},
}
address := dtos.NewRESTAddress(TestHost, TestPort, TestHTTPMethod)
dto := dtos.NewIntervalAction(TestIntervalActionName, TestIntervalName, address)
return NewAddIntervalActionRequest(dto)
}

func updateIntervalActionRequestData() UpdateIntervalActionRequest {
Expand All @@ -58,12 +44,8 @@ func updateIntervalActionData() dtos.UpdateIntervalAction {
dto.Id = &testId
dto.Name = &testName
dto.IntervalName = &testIntervalName
dto.Address = &dtos.Address{
Type: v2.REST,
Host: TestHost,
Port: TestPort,
RESTAddress: dtos.RESTAddress{HTTPMethod: TestHTTPMethod},
}
address := dtos.NewRESTAddress(TestHost, TestPort, TestHTTPMethod)
dto.Address = &address
return dto
}

Expand Down Expand Up @@ -125,7 +107,7 @@ func TestAddIntervalActionRequest_Validate(t *testing.T) {

func TestAddIntervalAction_UnmarshalJSON(t *testing.T) {
valid := addIntervalActionRequestData()
jsonData, _ := json.Marshal(addIntervalActionRequestData())
jsonData, _ := json.Marshal(valid)
tests := []struct {
name string
expected AddIntervalActionRequest
Expand Down Expand Up @@ -154,6 +136,7 @@ func TestAddIntervalActionReqToIntervalActionModels(t *testing.T) {
requests := []AddIntervalActionRequest{addIntervalActionRequestData()}
expectedIntervalActionModel := []models.IntervalAction{
{
Id: requests[0].Action.Id,
Name: TestIntervalActionName,
IntervalName: TestIntervalName,
Address: dtos.ToAddressModel(requests[0].Action.Address),
Expand Down

0 comments on commit 766e8bf

Please sign in to comment.