Skip to content

Commit

Permalink
merge base branch
Browse files Browse the repository at this point in the history
  • Loading branch information
almostinf committed Sep 23, 2024
1 parent d944fb3 commit ab5ec27
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 29 deletions.
10 changes: 5 additions & 5 deletions api/controller/emergency_contact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ var (

testEmergencyContact = moira.EmergencyContact{
ContactID: testContactID,
EmergencyTypes: []moira.EmergencyContactType{moira.EmergencyTypeNotifierOff},
HeartbeatTypes: []moira.HeartbeatType{moira.HeartbeatNotifierOff},
}
testEmergencyContact2 = moira.EmergencyContact{
ContactID: testContactID2,
EmergencyTypes: []moira.EmergencyContactType{moira.EmergencyTypeRedisDisconnected},
HeartbeatTypes: []moira.HeartbeatType{moira.HearbeatTypeNotSet},
}

testEmergencyContactDTO = dto.EmergencyContact{
ContactID: testContactID,
EmergencyTypes: []moira.EmergencyContactType{moira.EmergencyTypeNotifierOff},
HeartbeatTypes: []moira.HeartbeatType{moira.HeartbeatNotifierOff},
}
testEmergencyContact2DTO = dto.EmergencyContact{
ContactID: testContactID2,
EmergencyTypes: []moira.EmergencyContactType{moira.EmergencyTypeRedisDisconnected},
HeartbeatTypes: []moira.HeartbeatType{moira.HearbeatTypeNotSet},
}
)

Expand Down Expand Up @@ -285,7 +285,7 @@ func TestUpdateEmergencyContact(t *testing.T) {

Convey("With empty contact id", func() {
emergencyContactDTO := dto.EmergencyContact{
EmergencyTypes: []moira.EmergencyContactType{moira.EmergencyTypeNotifierOff},
HeartbeatTypes: []moira.HeartbeatType{moira.HeartbeatNotifierOff},
}
database.EXPECT().SaveEmergencyContact(testEmergencyContact).Return(nil)

Expand Down
16 changes: 8 additions & 8 deletions api/dto/emergency_contact.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import (
"github.com/moira-alert/moira"
)

// ErrEmptyEmergencyTypes means that the user has not specified any emergency types.
var ErrEmptyEmergencyTypes = errors.New("emergency types can not be empty")
// ErrEmptyHeartbeatTypes means that the user has not specified any heartbeat types.
var ErrEmptyHeartbeatTypes = errors.New("heartbeat types can not be empty")

// EmergencyContact is the DTO structure for contacts to which notifications will go in the event of special internal Moira problems.
type EmergencyContact struct {
ContactID string `json:"contact_id" example:"1dd38765-c5be-418d-81fa-7a5f879c2315"`
EmergencyTypes []moira.EmergencyContactType `json:"emergency_types" example:"notifier_off"`
ContactID string `json:"contact_id" example:"1dd38765-c5be-418d-81fa-7a5f879c2315"`
HeartbeatTypes []moira.HeartbeatType `json:"heartbeat_types" example:"notifier_off"`
}

// Render is a function that implements chi Renderer interface for EmergencyContact.
Expand All @@ -24,13 +24,13 @@ func (*EmergencyContact) Render(w http.ResponseWriter, r *http.Request) error {

// Bind is a method that implements Binder interface from chi and checks that validity of data in request.
func (emergencyContact *EmergencyContact) Bind(r *http.Request) error {
if len(emergencyContact.EmergencyTypes) == 0 {
return ErrEmptyEmergencyTypes
if len(emergencyContact.HeartbeatTypes) == 0 {
return ErrEmptyHeartbeatTypes
}

for _, emergencyType := range emergencyContact.EmergencyTypes {
for _, emergencyType := range emergencyContact.HeartbeatTypes {
if !emergencyType.IsValid() {
return fmt.Errorf("'%s' emergency type doesn't exist", emergencyType)
return fmt.Errorf("'%s' heartbeat type doesn't exist", emergencyType)
}
}

Expand Down
2 changes: 1 addition & 1 deletion api/dto/emergency_contact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var (

testEmergencyContact = moira.EmergencyContact{
ContactID: testContactID,
EmergencyTypes: []moira.EmergencyContactType{moira.EmergencyTypeNotifierOff},
HeartbeatTypes: []moira.HeartbeatType{moira.HeartbeatNotifierOff},
}
)

Expand Down
28 changes: 14 additions & 14 deletions api/handler/emergency_contact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ var (

testEmergencyContact = moira.EmergencyContact{
ContactID: testContactID,
EmergencyTypes: []moira.EmergencyContactType{moira.EmergencyTypeNotifierOff},
HeartbeatTypes: []moira.HeartbeatType{moira.HeartbeatNotifierOff},
}
testEmergencyContact2 = moira.EmergencyContact{
ContactID: testContactID2,
EmergencyTypes: []moira.EmergencyContactType{moira.EmergencyTypeRedisDisconnected},
HeartbeatTypes: []moira.HeartbeatType{moira.HearbeatTypeNotSet},
}

login = "testLogin"
Expand Down Expand Up @@ -246,7 +246,7 @@ func TestCreateEmergencyContact(t *testing.T) {

Convey("Try to create emergency contact without contact id", func() {
emergencyContact := moira.EmergencyContact{
EmergencyTypes: []moira.EmergencyContactType{moira.EmergencyTypeNotifierOff},
HeartbeatTypes: []moira.HeartbeatType{moira.HeartbeatNotifierOff},
}
emergencyContactDTO := dto.EmergencyContact(emergencyContact)

Expand Down Expand Up @@ -280,7 +280,7 @@ func TestCreateEmergencyContact(t *testing.T) {
So(response.StatusCode, ShouldEqual, http.StatusBadRequest)
})

Convey("Try to create emergency contact without emergency types", func() {
Convey("Try to create emergency contact without heartbeat types", func() {
emergencyContact := moira.EmergencyContact{
ContactID: testContactID,
}
Expand All @@ -293,7 +293,7 @@ func TestCreateEmergencyContact(t *testing.T) {

expectedErr := &api.ErrorResponse{
StatusText: "Invalid request",
ErrorText: dto.ErrEmptyEmergencyTypes.Error(),
ErrorText: dto.ErrEmptyHeartbeatTypes.Error(),
}

testRequest := httptest.NewRequest(http.MethodPost, "/emergency-contact", bytes.NewBuffer(jsonEmergencyContact))
Expand All @@ -316,10 +316,10 @@ func TestCreateEmergencyContact(t *testing.T) {
So(response.StatusCode, ShouldEqual, http.StatusBadRequest)
})

Convey("Try to create emergency contact with invalid emergency type", func() {
Convey("Try to create emergency contact with invalid heartbeat type", func() {
emergencyContact := moira.EmergencyContact{
ContactID: testContactID,
EmergencyTypes: []moira.EmergencyContactType{
HeartbeatTypes: []moira.HeartbeatType{
"notifier_on",
},
}
Expand All @@ -332,7 +332,7 @@ func TestCreateEmergencyContact(t *testing.T) {

expectedErr := &api.ErrorResponse{
StatusText: "Invalid request",
ErrorText: "'notifier_on' emergency type doesn't exist",
ErrorText: "'notifier_on' heartbeat type doesn't exist",
}

testRequest := httptest.NewRequest(http.MethodPost, "/emergency-contact", bytes.NewBuffer(jsonEmergencyContact))
Expand Down Expand Up @@ -472,7 +472,7 @@ func TestUpdateEmergencyContact(t *testing.T) {

Convey("Successfully update emergency contact without contact id in dto", func() {
emergencyContact := moira.EmergencyContact{
EmergencyTypes: []moira.EmergencyContactType{moira.EmergencyTypeNotifierOff},
HeartbeatTypes: []moira.HeartbeatType{moira.HeartbeatNotifierOff},
}
emergencyContactDTO := dto.EmergencyContact(emergencyContact)

Expand Down Expand Up @@ -505,15 +505,15 @@ func TestUpdateEmergencyContact(t *testing.T) {
So(response.StatusCode, ShouldEqual, http.StatusOK)
})

Convey("Invalid Request without emergency types in dto", func() {
Convey("Invalid Request without heartbeat types in dto", func() {
emergencyContact := moira.EmergencyContact{
ContactID: testContactID,
}
emergencyContactDTO := dto.EmergencyContact(emergencyContact)

expectedErr := &api.ErrorResponse{
StatusText: "Invalid request",
ErrorText: dto.ErrEmptyEmergencyTypes.Error(),
ErrorText: dto.ErrEmptyHeartbeatTypes.Error(),
}
jsonEmergencyContact, err := json.Marshal(emergencyContactDTO)
So(err, ShouldBeNil)
Expand All @@ -539,18 +539,18 @@ func TestUpdateEmergencyContact(t *testing.T) {
So(response.StatusCode, ShouldEqual, http.StatusBadRequest)
})

Convey("Invalid Request with undefined emergency type in dto", func() {
Convey("Invalid Request with undefined heartbeat type in dto", func() {
emergencyContact := moira.EmergencyContact{
ContactID: testContactID,
EmergencyTypes: []moira.EmergencyContactType{
HeartbeatTypes: []moira.HeartbeatType{
"notifier_on",
},
}
emergencyContactDTO := dto.EmergencyContact(emergencyContact)

expectedErr := &api.ErrorResponse{
StatusText: "Invalid request",
ErrorText: "'notifier_on' emergency type doesn't exist",
ErrorText: "'notifier_on' heartbeat type doesn't exist",
}
jsonEmergencyContact, err := json.Marshal(emergencyContactDTO)
So(err, ShouldBeNil)
Expand Down
2 changes: 1 addition & 1 deletion database/redis/emergency_contact.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (connector *DbConnector) getEmergencyContactIDs() ([]string, error) {
return emergencyContactIDs, nil
}

// GetHeartbeatTypeContactIDs a method for obtaining contact IDs by specific emergency type.
// GetHeartbeatTypeContactIDs a method for obtaining contact IDs by specific heartbeat type.
func (connector *DbConnector) GetHeartbeatTypeContactIDs(heartbeatType moira.HeartbeatType) ([]string, error) {
c := *connector.client
ctx := connector.context
Expand Down

0 comments on commit ab5ec27

Please sign in to comment.