-
Notifications
You must be signed in to change notification settings - Fork 7
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
1 parent
4d26d52
commit fb4af68
Showing
6 changed files
with
202 additions
and
10 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 |
---|---|---|
@@ -0,0 +1,125 @@ | ||
package contact | ||
|
||
import ( | ||
"bytes" | ||
"embed" | ||
"encoding/json" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
"utils" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/tj/assert" | ||
) | ||
|
||
//go:embed templates/contact-email-template.html | ||
var templateFS embed.FS | ||
|
||
var repo *Template | ||
var err error | ||
var testRequests []utils.TestRequest | ||
|
||
const ( | ||
SEND_CONTACT_MAIL = "/api/send-contact-mail" | ||
) | ||
|
||
var contactDetailInput = ContactDetails{ | ||
Name: "shruti", | ||
Designation: "I am individual entrepreneur running my own business.", | ||
DesignationInfo: "I am an owner of the business and I run canopas business. For more information about my business, you can visit the following links.", | ||
SocialMediaLinks: map[string]interface{}{ | ||
"website": "https://canopas.com/", | ||
"facebook": "https://www.facebook.com/canopassoftware", | ||
"twitter": "https://twitter.com/canopassoftware", | ||
"instagram": "https://www.instagram.com/canopassoftware/", | ||
}, | ||
Idea: "I have an idea for my business that I want to implement with your help.", | ||
Reason: "I have a rough design for the product I want to develop.", | ||
Email: "[email protected]", | ||
Message: "i'm very interested work with this company", | ||
ContactType: "Chat or Email", | ||
} | ||
|
||
func Test_init(t *testing.T) { | ||
repo, err = initializeRepo() | ||
assert.Nil(t, err) | ||
testRequests = []utils.TestRequest{ | ||
{ | ||
Url: SEND_CONTACT_MAIL, | ||
Method: "POST", | ||
Headers: nil, | ||
Body: contactDetailInput, | ||
ResponseCode: http.StatusOK, | ||
ResponseTypeArray: false, | ||
ExpectedData: expectedContactData(), | ||
}, | ||
} | ||
} | ||
|
||
func TestAllAPIs(t *testing.T) { | ||
|
||
asserts := assert.New(t) | ||
engine := gin.New() | ||
|
||
setUpRouter(engine) | ||
|
||
for _, testData := range testRequests { | ||
|
||
w := httptest.NewRecorder() | ||
var req *http.Request | ||
var got interface{} | ||
|
||
if testData.Body != nil { | ||
requestByte, _ := json.Marshal(testData.Body) | ||
reqBodyData := bytes.NewReader(requestByte) | ||
req, err = http.NewRequest(testData.Method, testData.Url, reqBodyData) | ||
} else { | ||
req, err = http.NewRequest(testData.Method, testData.Url, nil) | ||
} | ||
|
||
asserts.NoError(err) | ||
|
||
engine.ServeHTTP(w, req) | ||
assert.Equal(t, testData.ResponseCode, w.Code) | ||
if testData.ResponseTypeArray { | ||
got = utils.GotArrayData(w, t) | ||
} else { | ||
got = utils.GotData(w, t) | ||
} | ||
|
||
assert.Equal(t, testData.ExpectedData, got) | ||
|
||
} | ||
} | ||
|
||
func initializeRepo() (*Template, error) { | ||
|
||
repo = New(templateFS) | ||
|
||
return repo, err | ||
} | ||
|
||
// configure api you want to test | ||
func setUpRouter(engine *gin.Engine) { | ||
engine.POST(SEND_CONTACT_MAIL, repo.SendContactMail) | ||
} | ||
|
||
func expectedContactData() map[string]interface{} { | ||
contact := make(map[string]interface{}) | ||
contact["name"] = "shruti" | ||
contact["designation"] = "I am individual entrepreneur running my own business." | ||
contact["designation_info"] = "I am an owner of the business and I run canopas business. For more information about my business, you can visit the following links." | ||
contact["social_media_links"] = map[string]interface{}{ | ||
"facebook": "https://www.facebook.com/canopassoftware", | ||
"instagram": "https://www.instagram.com/canopassoftware/", | ||
"twitter": "https://twitter.com/canopassoftware", | ||
"website": "https://canopas.com/", | ||
} | ||
contact["idea"] = "I have an idea for my business that I want to implement with your help." | ||
contact["reason"] = "I have a rough design for the product I want to develop." | ||
contact["email"] = "[email protected]" | ||
contact["message"] = "i'm very interested work with this company" | ||
contact["contact_type"] = "Chat or Email" | ||
return contact | ||
} |
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,40 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> | ||
<meta name="HandheldFriendly" content="true" /> | ||
</head> | ||
<body> | ||
<div class="review-application-div"> | ||
<p> | ||
<span>Hello, My name is </span | ||
><span class="title-span"><b>{{.Name}}</b></span> | ||
</p> | ||
<p> | ||
<span class="apply-title">{{.Designation}}</span> | ||
</p> | ||
<p> | ||
<span>{{.DesignationInfo}}</span> | ||
</p> | ||
<p> | ||
Website : {{.SocialMediaLinks.website}} <br /> | ||
Facebook : {{.SocialMediaLinks.facebook}} <br /> | ||
Twitter : {{.SocialMediaLinks.twitter}} <br /> | ||
Instagram : {{.SocialMediaLinks.instagram}} <br /> | ||
Other : {{.SocialMediaLinks.other}} <br /> | ||
</p> | ||
<p> | ||
<span><b>Here are my preferences:</b></span> <br /> | ||
<span class="title-span"> {{.Idea}}</span><br /> | ||
<span class="title-span"> {{.Reason}}</span> | ||
</p> | ||
|
||
<p> | ||
<span><i>Email : </i></span><span class="title-span"> {{.Email}}</span> | ||
</p> | ||
<p><span class="title-span">Description : {{.Message}}</span></p> | ||
</div> | ||
</body> | ||
</html> |