Skip to content

Commit ce10b72

Browse files
authored
Merge pull request #27 from mtrezza/release-1.0.6
Release 1.0.6
2 parents e487dcf + f1cb906 commit ce10b72

File tree

4 files changed

+69
-9
lines changed

4 files changed

+69
-9
lines changed

CHANGELOG.md

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,40 @@
11
# Changelog
22

3-
# main
4-
[Full Changelog](https://github.com/mtrezza/parse-server-api-mail-adapter/compare/1.0.5...master)
3+
Jump directly to a version:
4+
5+
| 1.x |
6+
|------------------------------------|
7+
| [**1.0.6 (latest release)**](#106) |
8+
| [1.0.5](#105) |
9+
| [1.0.4](#104) |
10+
| [1.0.3](#103) |
11+
| [1.0.2](#102) |
12+
| [1.0.1](#101) |
13+
| [1.0.0](#100) |
14+
15+
# Unreleased (Main Branch)
16+
[Full Changelog](https://github.com/mtrezza/parse-server-api-mail-adapter/compare/1.0.6...master)
17+
18+
### ⚠️ Breaking Changes
19+
*(none)*
20+
21+
### 🚀 Notable Changes
22+
*(none)*
23+
24+
### 🧬 Other Changes
25+
*(none)*
26+
27+
# 1.0.6
28+
[Full Changelog](https://github.com/mtrezza/parse-server-api-mail-adapter/compare/1.0.5...1.0.6)
29+
30+
### ⚠️ Breaking Changes
31+
*(none)*
32+
33+
### 🚀 Notable Changes
34+
*(none)*
35+
36+
### 🧬 Other Changes
37+
- Fixes failing to send email in Cloud Code without template (Manuel Trezza) [#26](https://github.com/mtrezza/parse-server-api-mail-adapter/pull/26)
538

639
# 1.0.5
740
[Full Changelog](https://github.com/mtrezza/parse-server-api-mail-adapter/compare/1.0.4...1.0.5)

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "parse-server-api-mail-adapter",
3-
"version": "1.0.5",
3+
"version": "1.0.6",
44
"description": "API Mail Adapter for Parse Server",
55
"main": "./lib/index.js",
66
"repository": {
@@ -10,7 +10,10 @@
1010
"keywords": [
1111
"parse",
1212
"parse-server",
13-
"email-adapter"
13+
"mail-adapter",
14+
"email-adapter",
15+
"mail",
16+
"email"
1417
],
1518
"author": "Manuel Trezza",
1619
"license": "MIT",

spec/ApiMailAdapter.spec.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,26 @@ describe('ApiMailAdapter', () => {
251251
expect(_sendMail.calls.all()[0].args[0]).toEqual(expectedArguments);
252252
});
253253

254+
it('allows sendMail() without using a template', async () => {
255+
const adapter = new ApiMailAdapter(config);
256+
const apiCallbackSpy = spyOn(adapter, 'apiCallback').and.callFake(apiResponseSuccess);
257+
const options = {
258+
sender: config.sender,
259+
recipient: '[email protected]',
260+
subject: 'ExampleSubject',
261+
text: 'ExampleText',
262+
html: 'ExampleHtml',
263+
};
264+
265+
await expectAsync(adapter.sendMail(options)).toBeResolved();
266+
const apiPayload = apiCallbackSpy.calls.all()[0].args[0].payload;
267+
expect(apiPayload.from).toEqual(options.sender);
268+
expect(apiPayload.to).toEqual(options.recipient);
269+
expect(apiPayload.subject).toEqual(options.subject);
270+
expect(apiPayload.text).toEqual(options.text);
271+
expect(apiPayload.html).toEqual(options.html);
272+
});
273+
254274
it('passes user to callback when user is passed to sendMail()', async () => {
255275
const adapter = new ApiMailAdapter(config);
256276
const localeCallbackSpy = spyOn(config.templates.customEmailWithLocaleCallback, 'localeCallback').and.callThrough();
@@ -385,7 +405,6 @@ describe('ApiMailAdapter', () => {
385405
const adapter = new ApiMailAdapter(config);
386406
const configs = [
387407
{ templateName: 'invalid' },
388-
{ templateName: 'invalid', direct: true }
389408
];
390409
for (const config of configs) {
391410
await expectAsync(adapter._sendMail(config)).toBeRejectedWith(Errors.Error.noTemplateWithName('invalid'));

src/ApiMailAdapter.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,15 @@ class ApiMailAdapter extends MailAdapter {
125125
const templateName = email.templateName;
126126

127127
// If template name is not set
128-
if (!templateName) {
128+
if (!templateName && !email.direct) {
129129
throw Errors.Error.templateConfigurationNoName;
130130
}
131131

132132
// Get template
133133
const template = this.templates[templateName];
134134

135135
// If template does not exist
136-
if (!template) {
136+
if (!template && !email.direct) {
137137
throw Errors.Error.noTemplateWithName(templateName);
138138
}
139139

@@ -142,7 +142,12 @@ class ApiMailAdapter extends MailAdapter {
142142
// 1. Placeholders set in the template (default)
143143
// 2. Placeholders set in the email
144144
// 3. Placeholders returned by the placeholder callback
145-
const placeholders = template.placeholders || {};
145+
let placeholders = {};
146+
147+
// Add template placeholders
148+
if (template) {
149+
placeholders = Object.assign(placeholders, template.placeholders || {});
150+
}
146151

147152
// If the email is sent directly via Cloud Code
148153
if (email.direct) {
@@ -218,7 +223,7 @@ class ApiMailAdapter extends MailAdapter {
218223
*/
219224
async _createApiData(options) {
220225
let { message } = options;
221-
const { template, user, placeholders = {} } = options;
226+
const { template = {}, user, placeholders = {} } = options;
222227
const { placeholderCallback, localeCallback } = template;
223228
let locale;
224229

0 commit comments

Comments
 (0)