-
Notifications
You must be signed in to change notification settings - Fork 260
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
3 changed files
with
177 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -1602,6 +1602,156 @@ func Test_test_mail_batch__batch_id__get(t *testing.T) { | |
assert.Equal(t, 200, response.StatusCode, "Wrong status code returned") | ||
} | ||
|
||
func Test_test_send_client_with_mail_body_compression_enabled(t *testing.T) { | ||
apiKey := "SENDGRID_API_KEY" | ||
client := NewSendClient(apiKey) | ||
client.Headers["Content-Encoding"] = "gzip" | ||
|
||
emailBytes := []byte(` { | ||
"asm": { | ||
"group_id": 1, | ||
"groups_to_display": [ | ||
1, | ||
2, | ||
3 | ||
] | ||
}, | ||
"attachments": [ | ||
{ | ||
"content": "[BASE64 encoded content block here]", | ||
"content_id": "ii_139db99fdb5c3704", | ||
"disposition": "inline", | ||
"filename": "file1.jpg", | ||
"name": "file1", | ||
"type": "jpg" | ||
} | ||
], | ||
"batch_id": "[YOUR BATCH ID GOES HERE]", | ||
"categories": [ | ||
"category1", | ||
"category2" | ||
], | ||
"content": [ | ||
{ | ||
"type": "text/html", | ||
"value": "<html><p>Hello, world!</p><img src=[CID GOES HERE]></img></html>" | ||
} | ||
], | ||
"custom_args": { | ||
"New Argument 1": "New Value 1", | ||
"activationAttempt": "1", | ||
"customerAccountNumber": "[CUSTOMER ACCOUNT NUMBER GOES HERE]" | ||
}, | ||
"from": { | ||
"email": "[email protected]", | ||
"name": "Sam Smith" | ||
}, | ||
"headers": {}, | ||
"ip_pool_name": "[YOUR POOL NAME GOES HERE]", | ||
"mail_settings": { | ||
"bcc": { | ||
"email": "[email protected]", | ||
"enable": true | ||
}, | ||
"bypass_list_management": { | ||
"enable": true | ||
}, | ||
"footer": { | ||
"enable": true, | ||
"html": "<p>Thanks</br>The Twilio SendGrid Team</p>", | ||
"text": "Thanks,/n The Twilio SendGrid Team" | ||
}, | ||
"sandbox_mode": { | ||
"enable": false | ||
}, | ||
"spam_check": { | ||
"enable": true, | ||
"post_to_url": "http://example.com/compliance", | ||
"threshold": 3 | ||
} | ||
}, | ||
"personalizations": [ | ||
{ | ||
"bcc": [ | ||
{ | ||
"email": "[email protected]", | ||
"name": "Sam Doe" | ||
} | ||
], | ||
"cc": [ | ||
{ | ||
"email": "[email protected]", | ||
"name": "Jane Doe" | ||
} | ||
], | ||
"custom_args": { | ||
"New Argument 1": "New Value 1", | ||
"activationAttempt": "1", | ||
"customerAccountNumber": "[CUSTOMER ACCOUNT NUMBER GOES HERE]" | ||
}, | ||
"headers": { | ||
"X-Accept-Language": "en", | ||
"X-Mailer": "MyApp" | ||
}, | ||
"send_at": 1409348513, | ||
"subject": "Hello, World!", | ||
"substitutions": { | ||
"id": "substitutions", | ||
"type": "object" | ||
}, | ||
"to": [ | ||
{ | ||
"email": "[email protected]", | ||
"name": "John Doe" | ||
} | ||
] | ||
} | ||
], | ||
"reply_to": { | ||
"email": "[email protected]", | ||
"name": "Sam Smith" | ||
}, | ||
"send_at": 1409348513, | ||
"subject": "Hello, World!", | ||
"template_id": "[YOUR TEMPLATE ID GOES HERE]", | ||
"tracking_settings": { | ||
"click_tracking": { | ||
"enable": true, | ||
"enable_text": true | ||
}, | ||
"ganalytics": { | ||
"enable": true, | ||
"utm_campaign": "[NAME OF YOUR REFERRER SOURCE]", | ||
"utm_content": "[USE THIS SPACE TO DIFFERENTIATE YOUR EMAIL FROM ADS]", | ||
"utm_medium": "[NAME OF YOUR MARKETING MEDIUM e.g. email]", | ||
"utm_name": "[NAME OF YOUR CAMPAIGN]", | ||
"utm_term": "[IDENTIFY PAID KEYWORDS HERE]" | ||
}, | ||
"open_tracking": { | ||
"enable": true, | ||
"substitution_tag": "%opentrack" | ||
}, | ||
"subscription_tracking": { | ||
"enable": true, | ||
"html": "If you would like to unsubscribe and stop receiving these emails <% clickhere %>.", | ||
"substitution_tag": "<%click here%>", | ||
"text": "If you would like to unsubscribe and stop receiving these emails <% click here %>." | ||
} | ||
} | ||
}`) | ||
email := &mail.SGMailV3{} | ||
err := json.Unmarshal(emailBytes, email) | ||
assert.Nil(t, err, fmt.Sprintf("Unmarshal error: %v", err)) | ||
client.Request.Headers["X-Mock"] = "202" | ||
response, err := client.Send(email) | ||
if err != nil { | ||
t.Log(err) | ||
} | ||
t.Log(response) | ||
assert.Equal(t, 202, response.StatusCode, "Wrong status code returned") | ||
|
||
} | ||
|
||
func Test_test_send_client(t *testing.T) { | ||
apiKey := "SENDGRID_APIKEY" | ||
client := NewSendClient(apiKey) | ||
|