-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): add custom name to contacts (#1021)
- Loading branch information
Showing
5 changed files
with
39 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,7 @@ func TestGetContactById(t *testing.T) { | |
Convey("Get contact by id should be success", t, func() { | ||
contact := moira.ContactData{ | ||
ID: uuid.Must(uuid.NewV4()).String(), | ||
Name: "awesome_name", | ||
Type: "slack", | ||
User: "awesome_moira_user", | ||
Value: "[email protected]", | ||
|
@@ -79,6 +80,7 @@ func TestGetContactById(t *testing.T) { | |
ShouldResemble, | ||
&dto.Contact{ | ||
ID: contact.ID, | ||
Name: contact.Name, | ||
Type: contact.Type, | ||
User: contact.User, | ||
Value: contact.Value, | ||
|
@@ -217,6 +219,28 @@ func TestCreateContact(t *testing.T) { | |
So(contact.ID, ShouldResemble, contact.ID) | ||
}) | ||
|
||
Convey("Success with custom name", func() { | ||
contact := dto.Contact{ | ||
ID: uuid.Must(uuid.NewV4()).String(), | ||
Value: "[email protected]", | ||
Type: "mail", | ||
Name: "some-name", | ||
} | ||
expectedContact := moira.ContactData{ | ||
ID: contact.ID, | ||
Value: contact.Value, | ||
Type: contact.Type, | ||
Name: contact.Name, | ||
Team: teamID, | ||
} | ||
dataBase.EXPECT().GetContact(contact.ID).Return(moira.ContactData{}, database.ErrNil) | ||
dataBase.EXPECT().SaveContact(&expectedContact).Return(nil) | ||
err := CreateContact(dataBase, auth, &contact, "", teamID) | ||
So(err, ShouldBeNil) | ||
So(contact.TeamID, ShouldResemble, teamID) | ||
So(contact.Name, ShouldResemble, expectedContact.Name) | ||
}) | ||
|
||
Convey("Contact exists by id", func() { | ||
contact := &dto.Contact{ | ||
ID: uuid.Must(uuid.NewV4()).String(), | ||
|
@@ -339,12 +363,14 @@ func TestUpdateContact(t *testing.T) { | |
Convey("Success", func() { | ||
contactDTO := dto.Contact{ | ||
Value: "[email protected]", | ||
Name: "some-name", | ||
Type: "mail", | ||
} | ||
contactID := uuid.Must(uuid.NewV4()).String() | ||
contact := moira.ContactData{ | ||
Value: contactDTO.Value, | ||
Type: contactDTO.Type, | ||
Name: contactDTO.Name, | ||
ID: contactID, | ||
User: userLogin, | ||
} | ||
|
@@ -353,6 +379,7 @@ func TestUpdateContact(t *testing.T) { | |
So(err, ShouldBeNil) | ||
So(expectedContact.User, ShouldResemble, userLogin) | ||
So(expectedContact.ID, ShouldResemble, contactID) | ||
So(expectedContact.Name, ShouldResemble, contactDTO.Name) | ||
}) | ||
|
||
Convey("Error save", func() { | ||
|
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 |
---|---|---|
|
@@ -18,6 +18,7 @@ func (*ContactList) Render(w http.ResponseWriter, r *http.Request) error { | |
|
||
type Contact struct { | ||
Type string `json:"type" example:"mail"` | ||
Name string `json:"name,omitempty" example:"Mail Alerts"` | ||
Value string `json:"value" example:"[email protected]"` | ||
ID string `json:"id,omitempty" example:"1dd38765-c5be-418d-81fa-7a5f879c2315"` | ||
User string `json:"user,omitempty" example:""` | ||
|
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 |
---|---|---|
|
@@ -199,6 +199,7 @@ func TestCreateNewContact(t *testing.T) { | |
|
||
newContactDto := &dto.Contact{ | ||
ID: defaultContact, | ||
Name: "Mail Alerts", | ||
Type: "mail", | ||
Value: "[email protected]", | ||
User: login, | ||
|
@@ -212,6 +213,7 @@ func TestCreateNewContact(t *testing.T) { | |
mockDb.EXPECT().GetContact(defaultContact).Return(moira.ContactData{}, db.ErrNil).Times(1) | ||
mockDb.EXPECT().SaveContact(&moira.ContactData{ | ||
ID: newContactDto.ID, | ||
Name: newContactDto.Name, | ||
Type: newContactDto.Type, | ||
Value: newContactDto.Value, | ||
User: newContactDto.User, | ||
|
@@ -271,6 +273,7 @@ func TestCreateNewContact(t *testing.T) { | |
So(actual.Type, ShouldEqual, newContactDto.Type) | ||
So(actual.User, ShouldEqual, newContactDto.User) | ||
So(actual.Value, ShouldEqual, newContactDto.Value) | ||
So(actual.Name, ShouldEqual, newContactDto.Name) | ||
So(response.StatusCode, ShouldEqual, http.StatusOK) | ||
}) | ||
|
||
|
@@ -389,6 +392,7 @@ func TestUpdateContact(t *testing.T) { | |
contactID := defaultContact | ||
updatedContactDto := &dto.Contact{ | ||
ID: contactID, | ||
Name: "Mail Alerts", | ||
Type: "mail", | ||
Value: "[email protected]", | ||
User: defaultLogin, | ||
|
@@ -401,6 +405,7 @@ func TestUpdateContact(t *testing.T) { | |
|
||
mockDb.EXPECT().SaveContact(&moira.ContactData{ | ||
ID: updatedContactDto.ID, | ||
Name: updatedContactDto.Name, | ||
Type: updatedContactDto.Type, | ||
Value: updatedContactDto.Value, | ||
User: updatedContactDto.User, | ||
|
@@ -410,6 +415,7 @@ func TestUpdateContact(t *testing.T) { | |
testRequest := httptest.NewRequest(http.MethodPut, "/contact/"+contactID, bytes.NewBuffer(jsonContact)) | ||
testRequest = testRequest.WithContext(middleware.SetContextValueForTest(testRequest.Context(), ContactKey, moira.ContactData{ | ||
ID: contactID, | ||
Name: updatedContactDto.Name, | ||
Type: updatedContactDto.Type, | ||
Value: updatedContactDto.Value, | ||
User: updatedContactDto.User, | ||
|
@@ -441,6 +447,7 @@ func TestUpdateContact(t *testing.T) { | |
|
||
mockDb.EXPECT().SaveContact(&moira.ContactData{ | ||
ID: updatedContactDto.ID, | ||
Name: updatedContactDto.Name, | ||
Type: updatedContactDto.Type, | ||
Value: updatedContactDto.Value, | ||
User: updatedContactDto.User, | ||
|
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 |
---|---|---|
|
@@ -196,6 +196,7 @@ type Team struct { | |
// ContactData represents contact object. | ||
type ContactData struct { | ||
Type string `json:"type" example:"mail"` | ||
Name string `json:"name,omitempty" example:"Mail Alerts"` | ||
Value string `json:"value" example:"[email protected]"` | ||
ID string `json:"id" example:"1dd38765-c5be-418d-81fa-7a5f879c2315"` | ||
User string `json:"user" example:""` | ||
|