generated from NdoleStudio/go-http-client
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to delete message threads
- Loading branch information
1 parent
f2fad94
commit 503d615
Showing
8 changed files
with
162 additions
and
14 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
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package stubs | ||
|
||
// MessageThreadIndexResponse response from the /v1/message-threads endpoint | ||
func MessageThreadIndexResponse() []byte { | ||
return []byte(` | ||
{ | ||
"data": [ | ||
{ | ||
"color": "indigo", | ||
"contact": "+18005550100", | ||
"created_at": "2022-06-05T14:26:09.527976+03:00", | ||
"id": "32343a19-da5e-4b1b-a767-3298a73703ca", | ||
"is_archived": false, | ||
"last_message_content": "This is a sample message content", | ||
"last_message_id": "32343a19-da5e-4b1b-a767-3298a73703ca", | ||
"order_timestamp": "2022-06-05T14:26:09.527976+03:00", | ||
"owner": "+18005550199", | ||
"status": "PENDING", | ||
"updated_at": "2022-06-05T14:26:09.527976+03:00", | ||
"user_id": "WB7DRDWrJZRGbYrv2CKGkqbzvqdC" | ||
} | ||
], | ||
"message": "item created successfully", | ||
"status": "success" | ||
} | ||
`) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package stubs | ||
|
||
// HttpInternalServerErrorResponse internal error response | ||
func HttpInternalServerErrorResponse() []byte { | ||
return []byte(` | ||
{ | ||
"message": "We ran into an internal error while handling the request.", | ||
"status": "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
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 |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package httpsms | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"github.com/google/uuid" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/NdoleStudio/httpsms-go/internal/helpers" | ||
"github.com/NdoleStudio/httpsms-go/internal/stubs" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestMessageThreadService_Index(t *testing.T) { | ||
// Setup | ||
t.Parallel() | ||
|
||
// Arrange | ||
apiKey := "test-api-key" | ||
server := helpers.MakeTestServer(http.StatusOK, stubs.MessageThreadIndexResponse()) | ||
client := New(WithBaseURL(server.URL), WithAPIKey(apiKey)) | ||
|
||
indexParams := &MessageThreadIndexParams{ | ||
IsArchived: false, | ||
Skip: 0, | ||
Query: nil, | ||
Limit: 10, | ||
Owner: fromNumber, | ||
} | ||
|
||
// Act | ||
threads, response, err := client.MessageThreads.Index(context.Background(), indexParams) | ||
|
||
// Assert | ||
assert.Nil(t, err) | ||
|
||
assert.Equal(t, http.StatusOK, response.HTTPResponse.StatusCode) | ||
|
||
jsonContent, _ := json.Marshal(threads) | ||
assert.JSONEq(t, string(stubs.MessageThreadIndexResponse()), string(jsonContent)) | ||
|
||
// Teardown | ||
server.Close() | ||
} | ||
|
||
func TestMessageThreadService_IndexWithError(t *testing.T) { | ||
// Setup | ||
t.Parallel() | ||
|
||
// Arrange | ||
apiKey := "test-api-key" | ||
server := helpers.MakeTestServer(http.StatusInternalServerError, stubs.HttpInternalServerErrorResponse()) | ||
client := New(WithBaseURL(server.URL), WithAPIKey(apiKey)) | ||
|
||
// Act | ||
_, response, err := client.MessageThreads.Index(context.Background(), &MessageThreadIndexParams{}) | ||
|
||
// Assert | ||
assert.NotNil(t, err) | ||
assert.Equal(t, http.StatusInternalServerError, response.HTTPResponse.StatusCode) | ||
assert.Equal(t, string(stubs.HttpInternalServerErrorResponse()), string(*response.Body)) | ||
|
||
// Teardown | ||
server.Close() | ||
} | ||
|
||
func TestMessageThreadService_Delete(t *testing.T) { | ||
// Setup | ||
t.Parallel() | ||
|
||
// Arrange | ||
apiKey := "test-api-key" | ||
server := helpers.MakeTestServer(http.StatusOK, nil) | ||
client := New(WithBaseURL(server.URL), WithAPIKey(apiKey)) | ||
|
||
// Act | ||
response, err := client.MessageThreads.Delete(context.Background(), uuid.New()) | ||
|
||
// Assert | ||
assert.Nil(t, err) | ||
assert.Equal(t, http.StatusOK, response.HTTPResponse.StatusCode) | ||
|
||
// Teardown | ||
server.Close() | ||
} | ||
|
||
func TestMessageThreadService_DeleteWithError(t *testing.T) { | ||
// Setup | ||
t.Parallel() | ||
|
||
// Arrange | ||
apiKey := "test-api-key" | ||
server := helpers.MakeTestServer(http.StatusInternalServerError, stubs.HttpInternalServerErrorResponse()) | ||
client := New(WithBaseURL(server.URL), WithAPIKey(apiKey)) | ||
|
||
// Act | ||
response, err := client.MessageThreads.Delete(context.Background(), uuid.New()) | ||
|
||
// Assert | ||
assert.NotNil(t, err) | ||
assert.Equal(t, http.StatusInternalServerError, response.HTTPResponse.StatusCode) | ||
|
||
// Teardown | ||
server.Close() | ||
} |