generated from Real-Dev-Squad/website-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
22 additions
and
15 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 |
---|---|---|
@@ -1,29 +1,35 @@ | ||
package service | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/Real-Dev-Squad/discord-service/fixtures" | ||
_ "github.com/Real-Dev-Squad/discord-service/tests/helpers" | ||
"github.com/Real-Dev-Squad/discord-service/utils" | ||
|
||
"github.com/bwmarrin/discordgo" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestHelloService(t *testing.T) { | ||
|
||
t.Run("should return a success response with a message", func(t *testing.T) { | ||
w := httptest.NewRecorder() | ||
r, _ := http.NewRequest("GET", "/", nil) | ||
jsonBytes, _ := json.Marshal(fixtures.HelloCommand) | ||
r, _ := http.NewRequest("POST", "/", bytes.NewBuffer(jsonBytes)) | ||
|
||
CS.discordMessage = fixtures.HelloCommand | ||
CS.HelloService(w, r) | ||
|
||
assert.Equal(t, http.StatusOK, w.Code) | ||
var response discordgo.InteractionResponse | ||
err := json.NewDecoder(w.Body).Decode(&response) | ||
assert.NoError(t, err) | ||
assert.Equal(t, discordgo.InteractionResponseChannelMessageWithSource, response.Type) | ||
assert.Equal(t, "Hey there! Congratulations, you just executed your first slash command", response.Data.Content) | ||
assert.Equal(t, utils.ResponseGenerator.HelloResponse(fixtures.HelloCommand.Member.User.ID), response.Data.Content) | ||
}) | ||
} |
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,11 @@ | ||
package utils | ||
|
||
import "fmt" | ||
|
||
type responseGenerator struct{} | ||
|
||
func (r *responseGenerator) HelloResponse(userId string) string { | ||
return fmt.Sprintf("Hey there <@%s>! Congratulations, you just executed your first slash command", userId) | ||
} | ||
|
||
var ResponseGenerator = &responseGenerator{} |