diff --git a/src/campaign/email.dto.ts b/src/campaign/email.dto.ts
index 2a15367..ba08ea6 100644
--- a/src/campaign/email.dto.ts
+++ b/src/campaign/email.dto.ts
@@ -14,9 +14,9 @@ export class EmailRequestDto implements SendRequest {
@IsString()
readonly subject: string;
- @IsOptional()
- @IsString()
- readonly textData: string;
+ // @IsOptional()
+ // @IsString()
+ // readonly textData: string;
@IsOptional()
@IsString()
diff --git a/src/campaign/maijet.service.ts b/src/campaign/maijet.service.ts
index b8d596f..703287e 100644
--- a/src/campaign/maijet.service.ts
+++ b/src/campaign/maijet.service.ts
@@ -33,14 +33,18 @@ export class MailjetService {
})),
Subject: data.subject,
- TextPart: data.textData,
+ // TextPart: data.textData,
+ HTMLPart: data.htmlData,
},
],
});
return { status: 200, errors: null } as SendResponse;
} catch (error) {
- return { status: 500, errors: [error] } as SendResponse;
+ return {
+ status: error.response.status,
+ errors: [error.orginalMessage || 'Une erreur est survenue'],
+ } as SendResponse;
}
}
}
diff --git a/src/mailjet/maijet.service.ts b/src/mailjet/maijet.service.ts
index 432ce61..276e05b 100644
--- a/src/mailjet/maijet.service.ts
+++ b/src/mailjet/maijet.service.ts
@@ -40,8 +40,10 @@ export class MailjetService {
return { status: 200, errors: null } as SendResponse;
} catch (error) {
- console.error('🚀 sendEmail ~ error:', error);
- return { status: 500, errors: [error] } as SendResponse;
+ return {
+ status: error.response.statuss,
+ errors: [error.orginalMessage || 'Une erreur est survenue'],
+ } as SendResponse;
}
}
}
diff --git a/test/mailer.spec.ts b/test/mailer.spec.ts
index 4f3a754..55abf30 100644
--- a/test/mailer.spec.ts
+++ b/test/mailer.spec.ts
@@ -24,11 +24,393 @@ describe('CampaignController', () => {
describe('send', () => {
it('should send an email', async () => {
const payload: EmailRequestDto = {
- senderEmail: 'contact@fidelcly.com',
- subject: 'Test Email',
- recipients: ['recipient@fidelcly.com'],
- textData: 'This is a test email',
- htmlData: '
This is a test email
',
+ senderEmail: 'kfc@fidelcly.com',
+ subject: 'KFC (Test)',
+ recipients: ['andimanieta@andimanieta.com', 'sihamais98@gmail.com'],
+ // textData: 'This is a test email',
+ htmlData: `
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ |
+
+
+
+ |
+
+
+
+
+ |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ |
+
+
+
+
+ Mardi Tenders
+ !
+
+ |
+
+
+
+
+
+
+ |
+
+
+
+ |
+
+
+
+
+ Bonjour,
+ Tous les mardis, pour un bucket
+ tenders acheté, on vous offre un troisième pour votre prochain passage
+
+ Equipe KFC Villetaneuse
+
+ |
+
+
+
+
+ |
+
+
+
+
+ |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Designed with Mailjet
+ This e-mail was sent to
+ [[EMAIL_TO]] because you've opted-in to receive news and promotional emails from us. Click
+ here to unsubscribe.
+
+ |
+
+
+
+
+ |
+
+
+
+
+
+
+
+ `,
templateUrl: '',
};
@@ -39,16 +421,16 @@ describe('CampaignController', () => {
it('should not send email', async () => {
const payload: EmailRequestDto = {
- senderEmail: 'contact@fidelcly.com',
+ senderEmail: 'test@fidelcly.com',
subject: 'Test Email',
recipients: [],
- textData: 'This is a test email',
+ // textData: 'This is a test email',
htmlData: 'This is a test email
',
templateUrl: '',
};
const result = await mailjetService.sendEmail(payload);
- expect(result.status).toBe(500);
+ expect(result.status).toBe(400);
expect(result.errors).toBeDefined();
});
});