From bdae0d03b256c5a0124060fbd0184080210a8db3 Mon Sep 17 00:00:00 2001 From: Antoine SEIN <142824551+asein-sinch@users.noreply.github.com> Date: Thu, 12 Dec 2024 19:01:30 +0100 Subject: [PATCH] DEVEXP-642: Update types and refactor transformers --- .../src/models/v1/emails/request/enum.ts | 3 + .../src/models/v1/emails/request/helper.ts | 13 ++ .../request/override-properties/index.ts | 1 + .../override-properties.ts | 72 ++++++- .../request/send-email-request/index.ts | 1 + .../send-email-request/send-email-request.ts | 136 +++--------- .../request/send-mime-email-request/index.ts | 1 + .../send-mime-email-request.ts | 94 ++------- .../request/template-properties/index.ts | 1 + .../template-properties.ts | 17 +- .../response/bad-request/bad-request.ts | 10 +- .../v1/emails/response/bad-request/index.ts | 9 +- .../email-not-found/email-not-found.ts | 12 +- .../emails/response/email-not-found/index.ts | 8 +- .../exceeded-queue-quota.ts | 28 +-- .../response/exceeded-queue-quota/index.ts | 8 +- .../generic-response/generic-response.ts | 12 +- .../emails/response/generic-response/index.ts | 8 +- .../get-stored-email-response.ts | 50 ++--- .../response/get-email-response/index.ts | 10 +- .../queue-status-disabled-details/index.ts | 8 +- .../queue-status-disabled-details.ts | 17 +- .../response/send-email-response/index.ts | 8 +- .../send-email-response.ts | 14 +- .../sending-queues-status-response/index.ts | 8 +- .../sending-queues-status-response.ts | 25 ++- .../models/v1/emails/request/helper.test.ts | 51 +++++ .../request/send-email-request.models.ts | 42 ++-- .../emails/request/send-email-request.test.ts | 197 ++++++------------ .../request/send-mime-email-request.models.ts | 22 +- .../request/send-mime-email-request.test.ts | 75 +++---- 31 files changed, 467 insertions(+), 494 deletions(-) create mode 100644 packages/mailgun/src/models/v1/emails/request/enum.ts create mode 100644 packages/mailgun/src/models/v1/emails/request/helper.ts create mode 100644 packages/mailgun/tests/models/v1/emails/request/helper.test.ts diff --git a/packages/mailgun/src/models/v1/emails/request/enum.ts b/packages/mailgun/src/models/v1/emails/request/enum.ts new file mode 100644 index 00000000..747f1d22 --- /dev/null +++ b/packages/mailgun/src/models/v1/emails/request/enum.ts @@ -0,0 +1,3 @@ +export type YesNoEnum = boolean | 'yes' | 'no'; + +export type YesNoHtmlonlyEnum = YesNoEnum | 'htmlonly'; diff --git a/packages/mailgun/src/models/v1/emails/request/helper.ts b/packages/mailgun/src/models/v1/emails/request/helper.ts new file mode 100644 index 00000000..35fae7fe --- /dev/null +++ b/packages/mailgun/src/models/v1/emails/request/helper.ts @@ -0,0 +1,13 @@ +import FormData = require('form-data'); + +export const appendFilteredPropertiesToFormData = ( + obj: Record, + prefix: string, + formData: FormData, +) => { + for (const [key, value] of Object.entries(obj)) { + if (key.startsWith(prefix) && value != null) { + formData.append(key, String(value)); + } + } +}; diff --git a/packages/mailgun/src/models/v1/emails/request/override-properties/index.ts b/packages/mailgun/src/models/v1/emails/request/override-properties/index.ts index 94d31285..3e79b29b 100644 --- a/packages/mailgun/src/models/v1/emails/request/override-properties/index.ts +++ b/packages/mailgun/src/models/v1/emails/request/override-properties/index.ts @@ -1 +1,2 @@ export type { OverrideProperties } from './override-properties'; +export { appendOverridePropertiesToFormData } from './override-properties'; diff --git a/packages/mailgun/src/models/v1/emails/request/override-properties/override-properties.ts b/packages/mailgun/src/models/v1/emails/request/override-properties/override-properties.ts index ada5feb7..c3c0f5c1 100644 --- a/packages/mailgun/src/models/v1/emails/request/override-properties/override-properties.ts +++ b/packages/mailgun/src/models/v1/emails/request/override-properties/override-properties.ts @@ -1,10 +1,13 @@ +import { YesNoEnum, YesNoHtmlonlyEnum } from '../enum'; +import FormData = require('form-data'); + export interface OverrideProperties { /** Tag string. See **Tagging** for more information */ tag?: string; /** Toggles Send Time Optimization (STO) on a per-message basis. String should be set to the number of hours in `[0-9]+h` format, with the minimum being `24h` and the maximum being `72h`. This value defines the time window in which Mailgun will run the optimization algorithm based on prior engagement data of a given recipient. See **Sending a Message with STO** for details. *Please note that STO is only available on certain plans. See www.mailgun.com/pricing for more info* */ - deliveryTimeOptimizePeriod?: string; + deliveryTimeOptimizePeriod?: number; /** Enables/disables DKIM signatures on a per-message basis. Pass `yes` or `no`, `true` or `false` */ - enableDkimSignature?: string; + enableDkimSignature?: YesNoEnum; /** Specify a second domain key to sign the email with. The value is formatted as `signing_domain/selector`, e.g. `example.com/s1`. This tells Mailgun to sign the message with the signing domain `example.com` using the selector `s1`. Note: the domain key specified must have been previously created and activated. */ secondaryDkim?: string; /** Specify an alias of the domain key specified in `o:secondary-dkim`. Also formatted as `public_signing_domain/selector`. `o:secondary-dkim` option must also be provided. Mailgun will sign the message with the provided key of the secondary DKIM, but use the public secondary DKIM name and selector. Note: We will perform a DNS check prior to signing the message to ensure the public keys matches the secondary DKIM. */ @@ -14,21 +17,72 @@ export interface OverrideProperties { /** Toggles Timezone Optimization (TZO) on a per message basis. String should be set to preferred delivery time in `HH:mm` or `hh:mmaa` format, where `HH:mm` is used for 24 hour format without AM/PM and hh:mmaa is used for 12 hour format with AM/PM. See **Sending a Message with TZO** for details. *Please note that TZO is only available on certain plans. See www.mailgun.com/pricing for more info* */ timeZoneLocalize?: string; /** Toggles click tracking on a per-message basis. Has higher priority than domain-level setting. Pass `yes` or `no`, `true` or `false`, or `htmlonly` if you only want links rewritten in the HTML part of the message */ - trackingClicks?: string; + trackingClicks?: YesNoHtmlonlyEnum; /** Toggles both click and open tracking on a per-message basis, see **Tracking Messages** for details. Pass `yes` or `no`, `true` or `false`, or `htmlonly` if you only want links rewritten in the HTML part of the message */ - tracking?: string; + tracking?: YesNoHtmlonlyEnum; /** Toggles opens tracking on a per-message basis. Has higher priority than domain-level setting. Pass `yes` or `no`, `true` or `false` */ - trackingOpens?: string; + trackingOpens?: YesNoEnum; /** If you send long emails that experience truncation or other rendering issues at the recipient, you can ensure opens are being tracked accurately with placement of the tracking pixel at the top of your emails */ - trackingPixelLocationTop?: string; + trackingPixelLocationTop?: YesNoEnum; /** Used to specify an IP Address to send an email that is owned by your account */ sendingIp?: string; /** If an IP Pool ID is provided, the email will be delivered with an IP that belongs in that pool */ sendingIpPool?: string; /** If set to `true` or `yes` this requires the message only be sent over a TLS connection. If a TLS connection can not be established, Mailgun will not deliver the message. If set to `false` or `no`, Mailgun will still try and upgrade the connection, but if Mailgun cannot, the message will be delivered over a plaintext SMTP connection. The default is `false` */ - requireTls?: string; + requireTls?: YesNoEnum; /** If set to `true` or `yes`, the certificate and hostname of the resolved MX Host will not be verified when trying to establish a TLS connection. If set to `false` or `no`, Mailgun will verify the certificate and hostname. If either one can not be verified, a TLS connection will not be established. The default is `false` */ - skipVerification?: string; + skipVerification?: YesNoEnum; /** Enables sending in test mode. Pass `yes` if needed. See **Sending in Test Mode** */ - isTestMode?: boolean; + isTestMode?: YesNoEnum; } + +export const appendOverridePropertiesToFormData = (overrideProperties: OverrideProperties, formData: FormData) => { + if (overrideProperties['tag'] != null) { + formData.append('o:tag', overrideProperties['tag']); + } + if (overrideProperties['deliveryTimeOptimizePeriod'] != null) { + formData.append('o:deliverytime-optimize-period', `${overrideProperties['deliveryTimeOptimizePeriod']}h`); + } + if (overrideProperties['enableDkimSignature'] != null) { + formData.append('o:dkim', String(overrideProperties['enableDkimSignature'])); + } + if (overrideProperties['secondaryDkim'] != null) { + formData.append('o:secondary-dkim', overrideProperties['secondaryDkim']); + } + if (overrideProperties['secondaryDkimPublic'] != null) { + formData.append('o:secondary-dkim-public', overrideProperties['secondaryDkimPublic']); + } + if (overrideProperties['deliveryTime'] != null) { + formData.append('o:deliverytime', overrideProperties['deliveryTime']); + } + if (overrideProperties['timeZoneLocalize'] != null) { + formData.append('o:time-zone-localize', overrideProperties['timeZoneLocalize']); + } + if (overrideProperties['tracking'] != null) { + formData.append('o:tracking', String(overrideProperties['tracking'])); + } + if (overrideProperties['trackingClicks'] != null) { + formData.append('o:tracking-clicks', String(overrideProperties['trackingClicks'])); + } + if (overrideProperties['trackingOpens'] != null) { + formData.append('o:tracking-opens', String(overrideProperties['trackingOpens'])); + } + if (overrideProperties['trackingPixelLocationTop'] != null) { + formData.append('o:tracking-pixel-location-top', String(overrideProperties['trackingPixelLocationTop'])); + } + if (overrideProperties['sendingIp'] != null) { + formData.append('o:sending-ip', overrideProperties['sendingIp']); + } + if (overrideProperties['sendingIpPool'] != null) { + formData.append('o:sending-ip-pool', overrideProperties['sendingIpPool']); + } + if (overrideProperties['requireTls'] != null) { + formData.append('o:require-tls', String(overrideProperties['requireTls'])); + } + if (overrideProperties['skipVerification'] != null) { + formData.append('o:skip-verification', String(overrideProperties['skipVerification'])); + } + if (overrideProperties['isTestMode'] != null) { + formData.append('o:testmode', String(overrideProperties['isTestMode'])); + } +}; diff --git a/packages/mailgun/src/models/v1/emails/request/send-email-request/index.ts b/packages/mailgun/src/models/v1/emails/request/send-email-request/index.ts index cf7e8c76..ba662c40 100644 --- a/packages/mailgun/src/models/v1/emails/request/send-email-request/index.ts +++ b/packages/mailgun/src/models/v1/emails/request/send-email-request/index.ts @@ -1 +1,2 @@ export type { SendEmailRequest } from './send-email-request'; +export { transformSendEmailRequestIntoApiRequestBody } from './send-email-request'; diff --git a/packages/mailgun/src/models/v1/emails/request/send-email-request/send-email-request.ts b/packages/mailgun/src/models/v1/emails/request/send-email-request/send-email-request.ts index ab7b29fb..fccb534a 100644 --- a/packages/mailgun/src/models/v1/emails/request/send-email-request/send-email-request.ts +++ b/packages/mailgun/src/models/v1/emails/request/send-email-request/send-email-request.ts @@ -1,25 +1,20 @@ -import { TemplateProperties } from '../template-properties'; -import { OverrideProperties } from '../override-properties'; +import { appendTemplatePropertiesToFormData, TemplateProperties } from '../template-properties'; +import { appendOverridePropertiesToFormData, OverrideProperties } from '../override-properties'; +import { appendFilteredPropertiesToFormData } from '../helper'; import FormData = require('form-data'); -export type MessageContentWhereHtmlContentCanBeInlineOnly = { +export type MessageContentWithHtmlInline = { /** Body of the message (HTML version) */ html?: string; - /** AMP part of the message. Please follow Google guidelines to compose and send AMP emails */ - amp_html?: string; - /** Body of the message (text version) */ - text?: string; /** Name of a template stored via template API to use to render the email body. See **Templates** for more information */ template?: never; + /** @see TemplateProperties */ + templateProperties?: never; } & CommonEmailProperties; -export type MessageContentWhereHtmlContentCanBeFromTemplateOnly = { +export type MessageContentWithHtmlInTemplate = { /** Name of a template stored via template API to use to render the email body. See **Templates** for more information */ template?: string; - /** AMP part of the message. Please follow Google guidelines to compose and send AMP emails */ - amp_html?: string; - /** Body of the message (text version) */ - text?: string; /** Body of the message (HTML version) */ html?: never; /** @see TemplateProperties */ @@ -37,6 +32,10 @@ export interface CommonEmailProperties { bcc?: string; /** Message subject */ subject: string; + /** Body of the message (text version) */ + text?: string; + /** AMP part of the message. Please follow Google guidelines to compose and send AMP emails */ + amp_html?: string; /** File attachment. You can post multiple `attachment` values. **Important:** You must use `multipart/form-data` encoding for sending attachments */ attachment?: string; /** Attachment with `inline` disposition. Can be used to send inline images (see example). You can post multiple `inline` values */ @@ -46,123 +45,54 @@ export interface CommonEmailProperties { /** h: prefix followed by a Header/Value pair. For example: h:X-Mailgun-Sending-Ip-Pool=xx.xx.xxx.x. */ [key: `h:${string}`]: string; /** `v:` prefix followed by an arbitrary name allows to attach a custom JSON data to the message. See **Attaching Data to Messages** for more information */ - [key: `v:${string}`]: string | number; + [key: `v:${string}`]: string | number | Date; } -export type SendEmailRequest = MessageContentWhereHtmlContentCanBeInlineOnly - | MessageContentWhereHtmlContentCanBeFromTemplateOnly; +export type SendEmailRequest = MessageContentWithHtmlInline + | MessageContentWithHtmlInTemplate; export const transformSendEmailRequestIntoApiRequestBody = (sdkRequest: SendEmailRequest): FormData => { const formData = new FormData(); - if ('html' in sdkRequest && sdkRequest['html'] !== undefined && sdkRequest['html'] !== null) { + if (sdkRequest['html'] != null) { formData.append('html', sdkRequest['html']); } - if ('template' in sdkRequest && sdkRequest['template'] !== undefined && sdkRequest['template'] !== null) { - formData.append('template', sdkRequest['template']); - } - if (sdkRequest['amp_html'] !== undefined && sdkRequest['amp_html'] !== null) { + if (sdkRequest['amp_html'] != null) { formData.append('amp-html', sdkRequest['amp_html']); } - if (sdkRequest['text'] !== undefined && sdkRequest['text'] !== null) { + if (sdkRequest['text'] != null) { formData.append('text', sdkRequest['text']); } - if (sdkRequest['to'] !== undefined && sdkRequest['to'] !== null) { + if (sdkRequest['to'] != null) { formData.append('to', sdkRequest['to']); } - if (sdkRequest['from'] !== undefined && sdkRequest['from'] !== null) { + if (sdkRequest['from'] != null) { formData.append('from', sdkRequest['from']); } - if (sdkRequest['cc'] !== undefined && sdkRequest['cc'] !== null) { + if (sdkRequest['cc'] != null) { formData.append('cc', sdkRequest['cc']); } - if (sdkRequest['bcc'] !== undefined && sdkRequest['bcc'] !== null) { + if (sdkRequest['bcc'] != null) { formData.append('bcc', sdkRequest['bcc']); } - if (sdkRequest['subject'] !== undefined && sdkRequest['subject'] !== null) { + if (sdkRequest['subject'] != null) { formData.append('subject', sdkRequest['subject']); } - if (sdkRequest['attachment'] !== undefined && sdkRequest['attachment'] !== null) { + if (sdkRequest['attachment'] != null) { formData.append('attachment', sdkRequest['attachment']); } - if (sdkRequest['inline'] !== undefined && sdkRequest['inline'] !== null) { + if (sdkRequest['inline'] != null) { formData.append('inline', sdkRequest['inline']); } - if ('templateProperties' in sdkRequest - && sdkRequest.templateProperties !== null - && sdkRequest.templateProperties !== undefined) { - const templateProperties = sdkRequest.templateProperties; - if (templateProperties['text'] !== undefined && templateProperties['text'] !== null) { - formData.append('t:text', templateProperties['text']); - } - if (templateProperties['version'] !== undefined && templateProperties['version'] !== null) { - formData.append('t:version', templateProperties['version']); - } - if (templateProperties['variables'] !== undefined && templateProperties['variables'] !== null) { - formData.append('t:variables', templateProperties['variables']); - } + if (sdkRequest.overrideProperties != null) { + appendOverridePropertiesToFormData(sdkRequest.overrideProperties, formData); } - if (sdkRequest['overrideProperties'] !== undefined && sdkRequest['overrideProperties'] !== null) { - const overrideProperties = sdkRequest['overrideProperties']; - if (overrideProperties['tag'] !== undefined && overrideProperties['tag'] !== null) { - formData.append('o:tag', overrideProperties['tag']); - } - if (overrideProperties['deliveryTimeOptimizePeriod'] !== undefined - && overrideProperties['deliveryTimeOptimizePeriod'] !== null) { - formData.append('o:deliverytime-optimize-period', overrideProperties['deliveryTimeOptimizePeriod']); - } - if (overrideProperties['enableDkimSignature'] !== undefined && overrideProperties['enableDkimSignature'] !== null) { - formData.append('o:dkim', overrideProperties['enableDkimSignature']); - } - if (overrideProperties['secondaryDkim'] !== undefined && overrideProperties['secondaryDkim'] !== null) { - formData.append('o:secondary-dkim', overrideProperties['secondaryDkim']); - } - if (overrideProperties['secondaryDkimPublic'] !== undefined && overrideProperties['secondaryDkimPublic'] !== null) { - formData.append('o:secondary-dkim-public', overrideProperties['secondaryDkimPublic']); - } - if (overrideProperties['deliveryTime'] !== undefined && overrideProperties['deliveryTime'] !== null) { - formData.append('o:deliverytime', overrideProperties['deliveryTime']); - } - if (overrideProperties['timeZoneLocalize'] !== undefined && overrideProperties['timeZoneLocalize'] !== null) { - formData.append('o:time-zone-localize', overrideProperties['timeZoneLocalize']); - } - if (overrideProperties['tracking'] !== undefined && overrideProperties['tracking'] !== null) { - formData.append('o:tracking', overrideProperties['tracking']); - } - if (overrideProperties['trackingClicks'] !== undefined && overrideProperties['trackingClicks'] !== null) { - formData.append('o:tracking-clicks', overrideProperties['trackingClicks']); - } - if (overrideProperties['trackingOpens'] !== undefined && overrideProperties['trackingOpens'] !== null) { - formData.append('o:tracking-opens', overrideProperties['trackingOpens']); - } - if (overrideProperties['trackingPixelLocationTop'] !== undefined - && overrideProperties['trackingPixelLocationTop'] !== null) { - formData.append('o:tracking-pixel-location-top', overrideProperties['trackingPixelLocationTop']); - } - if (overrideProperties['sendingIp'] !== undefined && overrideProperties['sendingIp'] !== null) { - formData.append('o:sending-ip', overrideProperties['sendingIp']); - } - if (overrideProperties['sendingIpPool'] !== undefined && overrideProperties['sendingIpPool'] !== null) { - formData.append('o:sending-ip-pool', overrideProperties['sendingIpPool']); - } - if (overrideProperties['requireTls'] !== undefined && overrideProperties['requireTls'] !== null) { - formData.append('o:require-tls', overrideProperties['requireTls']); - } - if (overrideProperties['skipVerification'] !== undefined && overrideProperties['skipVerification'] !== null) { - formData.append('o:skip-verification', overrideProperties['skipVerification']); - } - if (overrideProperties['isTestMode'] !== undefined && overrideProperties['isTestMode'] !== null) { - formData.append('o:testmode', overrideProperties['isTestMode']); - } + if (sdkRequest['template'] != null) { + formData.append('template', sdkRequest['template']); } - addPropertiesToFormData(sdkRequest, 'h:', formData); - addPropertiesToFormData(sdkRequest, 'v:', formData); - return formData; -}; - -const addPropertiesToFormData = (obj: SendEmailRequest, prefix: string, formData: FormData) => { - for (const [key, value] of Object.entries(obj)) { - if (key.startsWith(prefix) && !!value) { - formData.append(key, value); - } + if (sdkRequest.templateProperties != null) { + appendTemplatePropertiesToFormData(sdkRequest.templateProperties, formData); } + appendFilteredPropertiesToFormData(sdkRequest, 'h:', formData); + appendFilteredPropertiesToFormData(sdkRequest, 'v:', formData); + return formData; }; diff --git a/packages/mailgun/src/models/v1/emails/request/send-mime-email-request/index.ts b/packages/mailgun/src/models/v1/emails/request/send-mime-email-request/index.ts index 22f54c29..309f8231 100644 --- a/packages/mailgun/src/models/v1/emails/request/send-mime-email-request/index.ts +++ b/packages/mailgun/src/models/v1/emails/request/send-mime-email-request/index.ts @@ -1 +1,2 @@ export type { SendMimeEmailRequest } from './send-mime-email-request'; +export { transformSendMimeEmailRequestIntoApiRequestBody } from './send-mime-email-request'; diff --git a/packages/mailgun/src/models/v1/emails/request/send-mime-email-request/send-mime-email-request.ts b/packages/mailgun/src/models/v1/emails/request/send-mime-email-request/send-mime-email-request.ts index ac66408e..241b3c53 100644 --- a/packages/mailgun/src/models/v1/emails/request/send-mime-email-request/send-mime-email-request.ts +++ b/packages/mailgun/src/models/v1/emails/request/send-mime-email-request/send-mime-email-request.ts @@ -1,5 +1,6 @@ -import { TemplateProperties } from '../template-properties'; -import { OverrideProperties } from '../override-properties'; +import { appendTemplatePropertiesToFormData, TemplateProperties } from '../template-properties'; +import { appendOverridePropertiesToFormData, OverrideProperties } from '../override-properties'; +import { appendFilteredPropertiesToFormData } from '../helper'; import FormData = require('form-data'); export interface SendMimeEmailRequest { @@ -23,91 +24,22 @@ export interface SendMimeEmailRequest { export const transformSendMimeEmailRequestIntoApiRequestBody = (sdkRequest: SendMimeEmailRequest): FormData => { const formData = new FormData(); - if (sdkRequest['to'] !== undefined && sdkRequest['to'] !== null) { + if (sdkRequest['to'] != null) { formData.append('to', sdkRequest['to']); } - if ('message' in sdkRequest && sdkRequest['message'] !== undefined && sdkRequest['template'] !== null) { - formData.append('message', sdkRequest['message'], { - filename: 'MimeMessage', - }); + if ('message' in sdkRequest && sdkRequest['message'] != null) { + formData.append('message', sdkRequest['message'], { filename: 'MimeMessage' }); } - if ('template' in sdkRequest && sdkRequest['template'] !== undefined && sdkRequest['template'] !== null) { + if ('template' in sdkRequest && sdkRequest['template'] != null) { formData.append('template', sdkRequest['template']); } - if (sdkRequest['templateProperties'] !== undefined && sdkRequest['templateProperties'] !== null) { - const templateProperties = sdkRequest['templateProperties']; - if (templateProperties['text'] !== undefined && templateProperties['text'] !== null) { - formData.append('t:text', templateProperties['text']); - } - if (templateProperties['version'] !== undefined && templateProperties['version'] !== null) { - formData.append('t:version', templateProperties['version']); - } - if (templateProperties['variables'] !== undefined && templateProperties['variables'] !== null) { - formData.append('t:variables', templateProperties['variables']); - } + if (sdkRequest.templateProperties != null) { + appendTemplatePropertiesToFormData(sdkRequest.templateProperties, formData); } - if (sdkRequest['overrideProperties'] !== undefined && sdkRequest['overrideProperties'] !== null) { - const overrideProperties = sdkRequest['overrideProperties']; - if (overrideProperties['tag'] !== undefined && overrideProperties['tag'] !== null) { - formData.append('o:tag', overrideProperties['tag']); - } - if (overrideProperties['deliveryTimeOptimizePeriod'] !== undefined - && overrideProperties['deliveryTimeOptimizePeriod'] !== null) { - formData.append('o:deliverytime-optimize-period', overrideProperties['deliveryTimeOptimizePeriod']); - } - if (overrideProperties['enableDkimSignature'] !== undefined && overrideProperties['enableDkimSignature'] !== null) { - formData.append('o:dkim', overrideProperties['enableDkimSignature']); - } - if (overrideProperties['secondaryDkim'] !== undefined && overrideProperties['secondaryDkim'] !== null) { - formData.append('o:secondary-dkim', overrideProperties['secondaryDkim']); - } - if (overrideProperties['secondaryDkimPublic'] !== undefined && overrideProperties['secondaryDkimPublic'] !== null) { - formData.append('o:secondary-dkim-public', overrideProperties['secondaryDkimPublic']); - } - if (overrideProperties['deliveryTime'] !== undefined && overrideProperties['deliveryTime'] !== null) { - formData.append('o:deliverytime', overrideProperties['deliveryTime']); - } - if (overrideProperties['timeZoneLocalize'] !== undefined && overrideProperties['timeZoneLocalize'] !== null) { - formData.append('o:time-zone-localize', overrideProperties['timeZoneLocalize']); - } - if (overrideProperties['tracking'] !== undefined && overrideProperties['tracking'] !== null) { - formData.append('o:tracking', overrideProperties['tracking']); - } - if (overrideProperties['trackingClicks'] !== undefined && overrideProperties['trackingClicks'] !== null) { - formData.append('o:tracking-clicks', overrideProperties['trackingClicks']); - } - if (overrideProperties['trackingOpens'] !== undefined && overrideProperties['trackingOpens'] !== null) { - formData.append('o:tracking-opens', overrideProperties['trackingOpens']); - } - if (overrideProperties['trackingPixelLocationTop'] !== undefined - && overrideProperties['trackingPixelLocationTop'] !== null) { - formData.append('o:tracking-pixel-location-top', overrideProperties['trackingPixelLocationTop']); - } - if (overrideProperties['sendingIp'] !== undefined && overrideProperties['sendingIp'] !== null) { - formData.append('o:sending-ip', overrideProperties['sendingIp']); - } - if (overrideProperties['sendingIpPool'] !== undefined && overrideProperties['sendingIpPool'] !== null) { - formData.append('o:sending-ip-pool', overrideProperties['sendingIpPool']); - } - if (overrideProperties['requireTls'] !== undefined && overrideProperties['requireTls'] !== null) { - formData.append('o:require-tls', overrideProperties['requireTls']); - } - if (overrideProperties['skipVerification'] !== undefined && overrideProperties['skipVerification'] !== null) { - formData.append('o:skip-verification', overrideProperties['skipVerification']); - } - if (overrideProperties['isTestMode'] !== undefined && overrideProperties['isTestMode'] !== null) { - formData.append('o:testmode', overrideProperties['isTestMode']); - } + if (sdkRequest.overrideProperties != null) { + appendOverridePropertiesToFormData(sdkRequest.overrideProperties, formData); } - addPropertiesToFormData(sdkRequest, 'h:', formData); - addPropertiesToFormData(sdkRequest, 'v:', formData); + appendFilteredPropertiesToFormData(sdkRequest, 'h:', formData); + appendFilteredPropertiesToFormData(sdkRequest, 'v:', formData); return formData; }; - -const addPropertiesToFormData = (obj: SendMimeEmailRequest, prefix: string, formData: FormData) => { - for (const [key, value] of Object.entries(obj)) { - if (key.startsWith(prefix) && !!value) { - formData.append(key, value); - } - } -}; diff --git a/packages/mailgun/src/models/v1/emails/request/template-properties/index.ts b/packages/mailgun/src/models/v1/emails/request/template-properties/index.ts index 8e761a97..35c01cc2 100644 --- a/packages/mailgun/src/models/v1/emails/request/template-properties/index.ts +++ b/packages/mailgun/src/models/v1/emails/request/template-properties/index.ts @@ -1 +1,2 @@ export type { TemplateProperties } from './template-properties'; +export { appendTemplatePropertiesToFormData } from './template-properties'; diff --git a/packages/mailgun/src/models/v1/emails/request/template-properties/template-properties.ts b/packages/mailgun/src/models/v1/emails/request/template-properties/template-properties.ts index 1bb35243..ea500634 100644 --- a/packages/mailgun/src/models/v1/emails/request/template-properties/template-properties.ts +++ b/packages/mailgun/src/models/v1/emails/request/template-properties/template-properties.ts @@ -1,8 +1,23 @@ +import FormData = require('form-data'); +import { YesNoEnum } from '../enum'; + export interface TemplateProperties { /** Pass `yes` if you want to have a rendered template in the text part of the message in case of template sending */ - text?: string; + text?: YesNoEnum; /** Render a specific version of the given template instead of the latest version. `o:template` option must also be provided. */ version?: string; /** A valid JSON-encoded dictionary used as the input for template variable expansion. See **Templates** for more information */ variables?: string; } + +export const appendTemplatePropertiesToFormData = (templateProperties: TemplateProperties, formData: FormData) => { + if (templateProperties['text'] != null) { + formData.append('t:text', String(templateProperties['text'])); + } + if (templateProperties['version'] != null) { + formData.append('t:version', templateProperties['version']); + } + if (templateProperties['variables'] != null) { + formData.append('t:variables', templateProperties['variables']); + } +}; diff --git a/packages/mailgun/src/models/v1/emails/response/bad-request/bad-request.ts b/packages/mailgun/src/models/v1/emails/response/bad-request/bad-request.ts index 80dd82ae..c6ec15ac 100644 --- a/packages/mailgun/src/models/v1/emails/response/bad-request/bad-request.ts +++ b/packages/mailgun/src/models/v1/emails/response/bad-request/bad-request.ts @@ -1,3 +1,8 @@ +export type BadRequest = Omit; +export interface BadRequestFromApi { + message: string; +} + export const transformBadRequestIntoClientResponse = ( apiResponse: BadRequestFromApi, ): BadRequest => { @@ -6,8 +11,3 @@ export const transformBadRequestIntoClientResponse = ( } = apiResponse; return response; }; - -export type BadRequest = Omit; -export interface BadRequestFromApi { - message: string; -} diff --git a/packages/mailgun/src/models/v1/emails/response/bad-request/index.ts b/packages/mailgun/src/models/v1/emails/response/bad-request/index.ts index 95242d8a..abd2105a 100644 --- a/packages/mailgun/src/models/v1/emails/response/bad-request/index.ts +++ b/packages/mailgun/src/models/v1/emails/response/bad-request/index.ts @@ -1 +1,8 @@ -export type { BadRequest } from './bad-request'; +export type { + BadRequest, + BadRequestFromApi, +} from './bad-request'; +export { + transformBadRequestIntoClientResponse, +} from './bad-request'; + diff --git a/packages/mailgun/src/models/v1/emails/response/email-not-found/email-not-found.ts b/packages/mailgun/src/models/v1/emails/response/email-not-found/email-not-found.ts index 733d835c..c7dfaed5 100644 --- a/packages/mailgun/src/models/v1/emails/response/email-not-found/email-not-found.ts +++ b/packages/mailgun/src/models/v1/emails/response/email-not-found/email-not-found.ts @@ -1,3 +1,9 @@ +export type EmailNotFound = Omit; + +export interface EmailNotFoundFromApi { + message: string; +} + export const transformEmailNotFoundIntoClientResponse = ( apiResponse: EmailNotFoundFromApi, ): EmailNotFound => { @@ -6,9 +12,3 @@ export const transformEmailNotFoundIntoClientResponse = ( } = apiResponse; return response; }; - -export type EmailNotFound = Omit; - -export interface EmailNotFoundFromApi { - message: string; -} diff --git a/packages/mailgun/src/models/v1/emails/response/email-not-found/index.ts b/packages/mailgun/src/models/v1/emails/response/email-not-found/index.ts index 6ed45d38..e95051b8 100644 --- a/packages/mailgun/src/models/v1/emails/response/email-not-found/index.ts +++ b/packages/mailgun/src/models/v1/emails/response/email-not-found/index.ts @@ -1 +1,7 @@ -export type { EmailNotFound } from './email-not-found'; +export type { + EmailNotFound, + EmailNotFoundFromApi, +} from './email-not-found'; +export { + transformEmailNotFoundIntoClientResponse, +} from './email-not-found'; diff --git a/packages/mailgun/src/models/v1/emails/response/exceeded-queue-quota/exceeded-queue-quota.ts b/packages/mailgun/src/models/v1/emails/response/exceeded-queue-quota/exceeded-queue-quota.ts index 17b07299..b5d160e4 100644 --- a/packages/mailgun/src/models/v1/emails/response/exceeded-queue-quota/exceeded-queue-quota.ts +++ b/packages/mailgun/src/models/v1/emails/response/exceeded-queue-quota/exceeded-queue-quota.ts @@ -1,13 +1,8 @@ -import { QueueStatusDisabledDetails } from '../queue-status-disabled-details'; - -export const transformExceededQueueQuota = ( - apiResponse: ExceededQueueQuotaFromApi, -): ExceededQueueQuota => { - return { - disabled: apiResponse.disabled, - isDisabled: apiResponse.is_disabled, - }; -}; +import { + QueueStatusDisabledDetails, + QueueStatusDisabledDetailsFromApi, + transformQueueStatusDisabledDetailsIntoClientResponse, +} from '../queue-status-disabled-details'; export interface ExceededQueueQuota { /** @see QueueStatusDisabledDetails */ @@ -16,7 +11,16 @@ export interface ExceededQueueQuota { } export interface ExceededQueueQuotaFromApi { - /** @see QueueStatusDisabledDetails */ - disabled?: QueueStatusDisabledDetails; + /** @see QueueStatusDisabledDetailsFromApi */ + disabled?: QueueStatusDisabledDetailsFromApi; is_disabled: boolean; } + +export const transformExceededQueueQuota = ( + apiResponse: ExceededQueueQuotaFromApi, +): ExceededQueueQuota => { + return { + disabled: transformQueueStatusDisabledDetailsIntoClientResponse(apiResponse['disabled']), + isDisabled: apiResponse['is_disabled'], + }; +}; diff --git a/packages/mailgun/src/models/v1/emails/response/exceeded-queue-quota/index.ts b/packages/mailgun/src/models/v1/emails/response/exceeded-queue-quota/index.ts index f16dfc1a..1968596a 100644 --- a/packages/mailgun/src/models/v1/emails/response/exceeded-queue-quota/index.ts +++ b/packages/mailgun/src/models/v1/emails/response/exceeded-queue-quota/index.ts @@ -1 +1,7 @@ -export type { ExceededQueueQuota } from './exceeded-queue-quota'; +export type { + ExceededQueueQuota, + ExceededQueueQuotaFromApi, +} from './exceeded-queue-quota'; +export { + transformExceededQueueQuota, +} from './exceeded-queue-quota'; diff --git a/packages/mailgun/src/models/v1/emails/response/generic-response/generic-response.ts b/packages/mailgun/src/models/v1/emails/response/generic-response/generic-response.ts index f475b1ef..46a4ee35 100644 --- a/packages/mailgun/src/models/v1/emails/response/generic-response/generic-response.ts +++ b/packages/mailgun/src/models/v1/emails/response/generic-response/generic-response.ts @@ -1,3 +1,9 @@ +export type GenericResponse = Omit + +export interface GenericResponseFromApi { + message: string; +} + export const transformGenericResponseIntoClientResponse = ( apiResponse: GenericResponseFromApi, ): GenericResponse => { @@ -6,9 +12,3 @@ export const transformGenericResponseIntoClientResponse = ( } = apiResponse; return response; }; - -export type GenericResponse = Omit - -export interface GenericResponseFromApi { - message: string; -} diff --git a/packages/mailgun/src/models/v1/emails/response/generic-response/index.ts b/packages/mailgun/src/models/v1/emails/response/generic-response/index.ts index f1e9e87c..172eff9f 100644 --- a/packages/mailgun/src/models/v1/emails/response/generic-response/index.ts +++ b/packages/mailgun/src/models/v1/emails/response/generic-response/index.ts @@ -1 +1,7 @@ -export type { GenericResponse } from './generic-response'; +export type { + GenericResponse, + GenericResponseFromApi, +} from './generic-response'; +export { + transformGenericResponseIntoClientResponse, +} from './generic-response'; diff --git a/packages/mailgun/src/models/v1/emails/response/get-email-response/get-stored-email-response.ts b/packages/mailgun/src/models/v1/emails/response/get-email-response/get-stored-email-response.ts index 6e08dd2d..235173fc 100644 --- a/packages/mailgun/src/models/v1/emails/response/get-email-response/get-stored-email-response.ts +++ b/packages/mailgun/src/models/v1/emails/response/get-email-response/get-stored-email-response.ts @@ -1,27 +1,3 @@ -export const transformGetEmailResponseIntoClientResponse = ( - apiResponse: GetStoredEmailResponseFromApi, -): GetStoredEmailResponse => { - return { - sender: apiResponse['sender'], - recipients: apiResponse['recipients'], - from: apiResponse['from'], - subject: apiResponse['subject'], - bodyHtml: apiResponse['body-html'], - bodyPlain: apiResponse['body-plain'], - messageHeaders: convertHeaders(apiResponse['message-headers']), - strippedHtml: apiResponse['stripped-html'], - strippedText: apiResponse['stripped-text'], - strippedSignature: apiResponse['stripped-signature'], - }; -}; - -function convertHeaders(headers: MessageHeadersFromApi): MessageHeaders { - return headers.reduce((acc, [key, value]) => { - acc[key] = value; - return acc; - }, {} as MessageHeaders); -} - export interface GetStoredEmailResponse { sender: string, recipients: string, @@ -51,6 +27,30 @@ export interface GetStoredEmailResponseFromApi { export type MessageHeadersFromApi = [string, string | Date][]; -export type MessageHeaders= { +export type MessageHeaders = { [key: string]: string | Date; }; + +export const transformGetEmailResponseIntoClientResponse = ( + apiResponse: GetStoredEmailResponseFromApi, +): GetStoredEmailResponse => { + return { + sender: apiResponse['sender'], + recipients: apiResponse['recipients'], + from: apiResponse['from'], + subject: apiResponse['subject'], + bodyHtml: apiResponse['body-html'], + bodyPlain: apiResponse['body-plain'], + messageHeaders: convertHeaders(apiResponse['message-headers']), + strippedHtml: apiResponse['stripped-html'], + strippedText: apiResponse['stripped-text'], + strippedSignature: apiResponse['stripped-signature'], + }; +}; + +const convertHeaders = (headers: MessageHeadersFromApi): MessageHeaders => { + return headers.reduce((acc, [key, value]) => { + acc[key] = value; + return acc; + }, {} as MessageHeaders); +}; diff --git a/packages/mailgun/src/models/v1/emails/response/get-email-response/index.ts b/packages/mailgun/src/models/v1/emails/response/get-email-response/index.ts index d40813db..e9f3c953 100644 --- a/packages/mailgun/src/models/v1/emails/response/get-email-response/index.ts +++ b/packages/mailgun/src/models/v1/emails/response/get-email-response/index.ts @@ -1 +1,9 @@ -export type { GetStoredEmailResponse, MessageHeaders } from './get-stored-email-response'; +export type { + GetStoredEmailResponse, + MessageHeaders, + GetStoredEmailResponseFromApi, + MessageHeadersFromApi, +} from './get-stored-email-response'; +export { + transformGetEmailResponseIntoClientResponse, +} from './get-stored-email-response'; diff --git a/packages/mailgun/src/models/v1/emails/response/queue-status-disabled-details/index.ts b/packages/mailgun/src/models/v1/emails/response/queue-status-disabled-details/index.ts index d6c63da2..f4ce44f0 100644 --- a/packages/mailgun/src/models/v1/emails/response/queue-status-disabled-details/index.ts +++ b/packages/mailgun/src/models/v1/emails/response/queue-status-disabled-details/index.ts @@ -1 +1,7 @@ -export type { QueueStatusDisabledDetails } from './queue-status-disabled-details'; +export type { + QueueStatusDisabledDetails, + QueueStatusDisabledDetailsFromApi, +} from './queue-status-disabled-details'; +export { + transformQueueStatusDisabledDetailsIntoClientResponse, +} from './queue-status-disabled-details'; diff --git a/packages/mailgun/src/models/v1/emails/response/queue-status-disabled-details/queue-status-disabled-details.ts b/packages/mailgun/src/models/v1/emails/response/queue-status-disabled-details/queue-status-disabled-details.ts index 5a302a1b..9135e9bb 100644 --- a/packages/mailgun/src/models/v1/emails/response/queue-status-disabled-details/queue-status-disabled-details.ts +++ b/packages/mailgun/src/models/v1/emails/response/queue-status-disabled-details/queue-status-disabled-details.ts @@ -1,4 +1,15 @@ -export interface QueueStatusDisabledDetails { - reason: string; - until: string; +export type QueueStatusDisabledDetails = Omit; + +export interface QueueStatusDisabledDetailsFromApi { + 'reason': string; + 'until': string; } + +export const transformQueueStatusDisabledDetailsIntoClientResponse = ( + apiResponse?: QueueStatusDisabledDetailsFromApi, +): QueueStatusDisabledDetails => { + const { + ...response + } = apiResponse; + return response; +}; diff --git a/packages/mailgun/src/models/v1/emails/response/send-email-response/index.ts b/packages/mailgun/src/models/v1/emails/response/send-email-response/index.ts index 0afd055b..8ac506f4 100644 --- a/packages/mailgun/src/models/v1/emails/response/send-email-response/index.ts +++ b/packages/mailgun/src/models/v1/emails/response/send-email-response/index.ts @@ -1 +1,7 @@ -export type { SendEmailResponse } from './send-email-response'; +export type { + SendEmailResponse, + SendEmailResponseFromApi, +} from './send-email-response'; +export { + transformSendEmailResponseIntoClientResponse, +} from './send-email-response'; diff --git a/packages/mailgun/src/models/v1/emails/response/send-email-response/send-email-response.ts b/packages/mailgun/src/models/v1/emails/response/send-email-response/send-email-response.ts index eedfbc21..6809823f 100644 --- a/packages/mailgun/src/models/v1/emails/response/send-email-response/send-email-response.ts +++ b/packages/mailgun/src/models/v1/emails/response/send-email-response/send-email-response.ts @@ -1,3 +1,10 @@ +export type SendEmailResponse = Omit + +export interface SendEmailResponseFromApi { + message: string; + id: string; +} + export const transformSendEmailResponseIntoClientResponse = ( apiResponse: SendEmailResponseFromApi, ): SendEmailResponse => { @@ -6,10 +13,3 @@ export const transformSendEmailResponseIntoClientResponse = ( } = apiResponse; return response; }; - -export type SendEmailResponse = Omit - -export interface SendEmailResponseFromApi { - message: string; - id: string; -} diff --git a/packages/mailgun/src/models/v1/emails/response/sending-queues-status-response/index.ts b/packages/mailgun/src/models/v1/emails/response/sending-queues-status-response/index.ts index 9a8adf99..12491b05 100644 --- a/packages/mailgun/src/models/v1/emails/response/sending-queues-status-response/index.ts +++ b/packages/mailgun/src/models/v1/emails/response/sending-queues-status-response/index.ts @@ -1 +1,7 @@ -export type { SendingQueuesStatusResponse } from './sending-queues-status-response'; +export type { + SendingQueuesStatusResponse, + SendingQueuesStatusResponseFromApi, +} from './sending-queues-status-response'; +export { + transformSendingQueuesStatusResponseIntoClientResponse, +} from './sending-queues-status-response'; diff --git a/packages/mailgun/src/models/v1/emails/response/sending-queues-status-response/sending-queues-status-response.ts b/packages/mailgun/src/models/v1/emails/response/sending-queues-status-response/sending-queues-status-response.ts index ba92da4a..32c722a2 100644 --- a/packages/mailgun/src/models/v1/emails/response/sending-queues-status-response/sending-queues-status-response.ts +++ b/packages/mailgun/src/models/v1/emails/response/sending-queues-status-response/sending-queues-status-response.ts @@ -1,14 +1,4 @@ -import { ExceededQueueQuota } from '../exceeded-queue-quota'; -import { ExceededQueueQuotaFromApi, transformExceededQueueQuota } from '../exceeded-queue-quota/exceeded-queue-quota'; - -export const transformSendingQueuesStatusResponseIntoClientResponse = ( - apiResponse: SendingQueuesStatusResponseFromApi, -): SendingQueuesStatusResponse => { - return { - scheduled: transformExceededQueueQuota(apiResponse.scheduled), - regular: transformExceededQueueQuota(apiResponse.regular), - }; -}; +import { ExceededQueueQuota, ExceededQueueQuotaFromApi, transformExceededQueueQuota } from '../exceeded-queue-quota'; export interface SendingQueuesStatusResponse { /** @see ExceededQueueQuota */ @@ -18,8 +8,17 @@ export interface SendingQueuesStatusResponse { } export interface SendingQueuesStatusResponseFromApi { - /** @see ExceededQueueQuota */ + /** @see ExceededQueueQuotaFromApi */ scheduled: ExceededQueueQuotaFromApi; - /** @see ExceededQueueQuota */ + /** @see ExceededQueueQuotaFromApi */ regular: ExceededQueueQuotaFromApi; } + +export const transformSendingQueuesStatusResponseIntoClientResponse = ( + apiResponse: SendingQueuesStatusResponseFromApi, +): SendingQueuesStatusResponse => { + return { + scheduled: transformExceededQueueQuota(apiResponse['scheduled']), + regular: transformExceededQueueQuota(apiResponse['regular']), + }; +}; diff --git a/packages/mailgun/tests/models/v1/emails/request/helper.test.ts b/packages/mailgun/tests/models/v1/emails/request/helper.test.ts new file mode 100644 index 00000000..748ceeaf --- /dev/null +++ b/packages/mailgun/tests/models/v1/emails/request/helper.test.ts @@ -0,0 +1,51 @@ +import FormData = require('form-data'); +import { appendFilteredPropertiesToFormData } from '../../../../../src/models/v1/emails/request/helper'; + +describe('appendFilteredPropertiesToFormData', () => { + let formData: FormData; + let appendSpy: jest.SpyInstance; + + beforeEach(() => { + formData = new FormData(); + appendSpy = jest.spyOn(formData, 'append'); + }); + + afterEach(() => { + appendSpy.mockRestore(); + }); + + it('should append properties with the specified prefix to FormData', () => { + const obj = { + 'o:dkim': true, + 'o:tracking': 'yes', + 'v:first_name': 'John', + 'v:last_name': 'Smith', + 'v:my_message_id': '123', + 'v:date1': '2024-06-06T13:42:42', + 'v:date2': new Date('2024-06-06T13:42:42'), + }; + + appendFilteredPropertiesToFormData(obj, 'v:', formData); + + expect(appendSpy).toHaveBeenCalledTimes(5); + expect(appendSpy).toHaveBeenCalledWith('v:first_name', 'John'); + expect(appendSpy).toHaveBeenCalledWith('v:last_name', 'Smith'); + expect(appendSpy).toHaveBeenCalledWith('v:my_message_id', '123'); + expect(appendSpy).toHaveBeenCalledWith('v:date1', '2024-06-06T13:42:42'); + expect(appendSpy).toHaveBeenCalledWith('v:date2', + 'Thu Jun 06 2024 13:42:42 GMT+0200 (Central European Summer Time)'); + }); + + it('should not append properties with null or undefined values', () => { + const obj = { + 'o:dkim': true, + 'o:tracking': 'yes', + 'v:null': null, + 'v:undefined': undefined, + }; + + appendFilteredPropertiesToFormData(obj, 'v:', formData); + + expect(appendSpy).not.toHaveBeenCalled(); + }); +}); diff --git a/packages/mailgun/tests/models/v1/emails/request/send-email-request.models.ts b/packages/mailgun/tests/models/v1/emails/request/send-email-request.models.ts index 12c70f0c..73fb983c 100644 --- a/packages/mailgun/tests/models/v1/emails/request/send-email-request.models.ts +++ b/packages/mailgun/tests/models/v1/emails/request/send-email-request.models.ts @@ -16,17 +16,17 @@ export const sendEmailRequestWithHtml: Mailgun.SendEmailRequest = { sendingIp: 'sendingIp value', sendingIpPool: 'sendingIpPool value', deliveryTime: 'deliveryTime value', - deliveryTimeOptimizePeriod: 'deliveryTimeOptimizePeriod value', - enableDkimSignature: 'enableDkimSignature value', + deliveryTimeOptimizePeriod: 24, + enableDkimSignature: 'yes', secondaryDkim: 'secondaryDkim value', - secondaryDkimPublic: 'secondaryDkim value', - requireTls: 'requireTls value', - skipVerification: 'skipVerification value', - timeZoneLocalize: 'timeZoneLocalize value', - tracking: 'tracking value', - trackingClicks: 'trackingClicks value', - trackingOpens: 'trackingOpens value', - trackingPixelLocationTop: 'trackingPixelLocationTop value', + secondaryDkimPublic: 'secondaryDkimPublic value', + requireTls: false, + skipVerification: true, + timeZoneLocalize: '02:00PM', + tracking: 'htmlonly', + trackingClicks: 'htmlonly', + trackingOpens: 'yes', + trackingPixelLocationTop: 'no', isTestMode: false, }, 'h:X-Mailgun-Sending-Ip-Pool': 'xx.xx.xxx.x', @@ -48,7 +48,7 @@ export const sendEmailRequestWithTemplate: Mailgun.SendEmailRequest = { inline: 'inline value', templateProperties: { version: 'version value', - text: 'text value', + text: 'yes', variables: 'variables value', }, overrideProperties: { @@ -56,17 +56,17 @@ export const sendEmailRequestWithTemplate: Mailgun.SendEmailRequest = { sendingIp: 'sendingIp value', sendingIpPool: 'sendingIpPool value', deliveryTime: 'deliveryTime value', - deliveryTimeOptimizePeriod: 'deliveryTimeOptimizePeriod value', - enableDkimSignature: 'enableDkimSignature value', + deliveryTimeOptimizePeriod: 36, + enableDkimSignature: true, secondaryDkim: 'secondaryDkim value', - secondaryDkimPublic: 'secondaryDkim value', - requireTls: 'requireTls value', - skipVerification: 'skipVerification value', - timeZoneLocalize: 'timeZoneLocalize value', - tracking: 'tracking value', - trackingClicks: 'trackingClicks value', - trackingOpens: 'trackingOpens value', - trackingPixelLocationTop: 'trackingPixelLocationTop value', + secondaryDkimPublic: 'secondaryDkimPublic value', + requireTls: 'yes', + skipVerification: 'no', + timeZoneLocalize: '04:15AM', + tracking: 'yes', + trackingClicks: 'no', + trackingOpens: true, + trackingPixelLocationTop: false, isTestMode: false, }, 'h:X-Mailgun-Sending-Ip-Pool': 'xx.xx.xxx.x', diff --git a/packages/mailgun/tests/models/v1/emails/request/send-email-request.test.ts b/packages/mailgun/tests/models/v1/emails/request/send-email-request.test.ts index e1965fa3..31988889 100644 --- a/packages/mailgun/tests/models/v1/emails/request/send-email-request.test.ts +++ b/packages/mailgun/tests/models/v1/emails/request/send-email-request.test.ts @@ -1,9 +1,6 @@ import FormData = require('form-data'); -import { Mailgun } from '../../../../../src'; -import { - transformSendEmailRequestIntoApiRequestBody, -} from '../../../../../src/models'; import { sendEmailRequestWithHtml, sendEmailRequestWithTemplate } from './send-email-request.models'; +import { transformSendEmailRequestIntoApiRequestBody } from '../../../../../src/models'; describe('SendEmailRequest', () => { @@ -20,140 +17,74 @@ describe('SendEmailRequest', () => { it('should transform a client object using HTML into an API object', () => { transformSendEmailRequestIntoApiRequestBody(sendEmailRequestWithHtml); expect(appendSpy).toHaveBeenCalledTimes(30); - expect(appendSpy).toHaveBeenCalledWith('from', - sendEmailRequestWithHtml.from); - expect(appendSpy).toHaveBeenCalledWith('to', - sendEmailRequestWithHtml.to); - expect(appendSpy).toHaveBeenCalledWith('cc', - sendEmailRequestWithHtml.cc); - expect(appendSpy).toHaveBeenCalledWith('bcc', - sendEmailRequestWithHtml.bcc); - expect(appendSpy).toHaveBeenCalledWith('subject', - sendEmailRequestWithHtml.subject); - expect(appendSpy).toHaveBeenCalledWith('text', - sendEmailRequestWithHtml.text); - expect(appendSpy).toHaveBeenCalledWith('html', - sendEmailRequestWithHtml.html); - expect(appendSpy).toHaveBeenCalledWith('amp-html', - sendEmailRequestWithHtml.amp_html); - expect(appendSpy).toHaveBeenCalledWith('attachment', - sendEmailRequestWithHtml.attachment); - expect(appendSpy).toHaveBeenCalledWith('inline', - sendEmailRequestWithHtml.inline); - expect(appendSpy).toHaveBeenCalledWith('o:tag', - sendEmailRequestWithHtml.overrideProperties?.tag); - expect(appendSpy).toHaveBeenCalledWith('o:sending-ip', - sendEmailRequestWithHtml.overrideProperties?.sendingIp); - expect(appendSpy).toHaveBeenCalledWith('o:sending-ip-pool', - sendEmailRequestWithHtml.overrideProperties?.sendingIpPool); - expect(appendSpy).toHaveBeenCalledWith('o:deliverytime', - sendEmailRequestWithHtml.overrideProperties?.deliveryTime); - expect(appendSpy).toHaveBeenCalledWith('o:deliverytime-optimize-period', - sendEmailRequestWithHtml.overrideProperties?.deliveryTimeOptimizePeriod); - expect(appendSpy).toHaveBeenCalledWith('o:dkim', - sendEmailRequestWithHtml.overrideProperties?.enableDkimSignature); - expect(appendSpy).toHaveBeenCalledWith('o:secondary-dkim', - sendEmailRequestWithHtml.overrideProperties?.secondaryDkim); - expect(appendSpy).toHaveBeenCalledWith('o:secondary-dkim-public', - sendEmailRequestWithHtml.overrideProperties?.secondaryDkimPublic); - expect(appendSpy).toHaveBeenCalledWith('o:require-tls', - sendEmailRequestWithHtml.overrideProperties?.requireTls); - expect(appendSpy).toHaveBeenCalledWith('o:skip-verification', - sendEmailRequestWithHtml.overrideProperties?.skipVerification); - expect(appendSpy).toHaveBeenCalledWith('o:time-zone-localize', - sendEmailRequestWithHtml.overrideProperties?.timeZoneLocalize); - expect(appendSpy).toHaveBeenCalledWith('o:tracking', - sendEmailRequestWithHtml.overrideProperties?.tracking); - expect(appendSpy).toHaveBeenCalledWith('o:tracking-opens', - sendEmailRequestWithHtml.overrideProperties?.trackingOpens); - expect(appendSpy).toHaveBeenCalledWith('o:tracking-clicks', - sendEmailRequestWithHtml.overrideProperties?.trackingClicks); - expect(appendSpy).toHaveBeenCalledWith('o:tracking-pixel-location-top', - sendEmailRequestWithHtml.overrideProperties?.trackingPixelLocationTop); - expect(appendSpy).toHaveBeenCalledWith('o:testmode', - sendEmailRequestWithHtml.overrideProperties?.isTestMode); - expect(appendSpy).toHaveBeenCalledWith('h:X-Mailgun-Sending-Ip-Pool', - sendEmailRequestWithHtml['h:X-Mailgun-Sending-Ip-Pool']); - expect(appendSpy).toHaveBeenCalledWith('v:first_name', - sendEmailRequestWithHtml['v:first_name']); - expect(appendSpy).toHaveBeenCalledWith('v:last_name', - sendEmailRequestWithHtml['v:last_name']); - expect(appendSpy).toHaveBeenCalledWith('v:my_message_id', - sendEmailRequestWithHtml['v:my_message_id']); + expect(appendSpy).toHaveBeenCalledWith('from', 'from value'); + expect(appendSpy).toHaveBeenCalledWith('to', 'to value'); + expect(appendSpy).toHaveBeenCalledWith('cc', 'cc value'); + expect(appendSpy).toHaveBeenCalledWith('bcc', 'bcc value'); + expect(appendSpy).toHaveBeenCalledWith('subject', 'subject value'); + expect(appendSpy).toHaveBeenCalledWith('text', 'text value'); + expect(appendSpy).toHaveBeenCalledWith('html', 'html value'); + expect(appendSpy).toHaveBeenCalledWith('amp-html', 'amp_html value'); + expect(appendSpy).toHaveBeenCalledWith('attachment', 'attachment value'); + expect(appendSpy).toHaveBeenCalledWith('inline', 'inline value'); + expect(appendSpy).toHaveBeenCalledWith('o:tag', 'tag value'); + expect(appendSpy).toHaveBeenCalledWith('o:sending-ip', 'sendingIp value'); + expect(appendSpy).toHaveBeenCalledWith('o:sending-ip-pool', 'sendingIpPool value'); + expect(appendSpy).toHaveBeenCalledWith('o:deliverytime', 'deliveryTime value'); + expect(appendSpy).toHaveBeenCalledWith('o:deliverytime-optimize-period', '24h'); + expect(appendSpy).toHaveBeenCalledWith('o:dkim', 'yes'); + expect(appendSpy).toHaveBeenCalledWith('o:secondary-dkim', 'secondaryDkim value'); + expect(appendSpy).toHaveBeenCalledWith('o:secondary-dkim-public', 'secondaryDkimPublic value'); + expect(appendSpy).toHaveBeenCalledWith('o:require-tls', 'false'); + expect(appendSpy).toHaveBeenCalledWith('o:skip-verification', 'true'); + expect(appendSpy).toHaveBeenCalledWith('o:time-zone-localize', '02:00PM'); + expect(appendSpy).toHaveBeenCalledWith('o:tracking', 'htmlonly'); + expect(appendSpy).toHaveBeenCalledWith('o:tracking-clicks', 'htmlonly'); + expect(appendSpy).toHaveBeenCalledWith('o:tracking-opens', 'yes'); + expect(appendSpy).toHaveBeenCalledWith('o:tracking-pixel-location-top', 'no'); + expect(appendSpy).toHaveBeenCalledWith('o:testmode', 'false'); + expect(appendSpy).toHaveBeenCalledWith('h:X-Mailgun-Sending-Ip-Pool', 'xx.xx.xxx.x'); + expect(appendSpy).toHaveBeenCalledWith('v:first_name', 'John'); + expect(appendSpy).toHaveBeenCalledWith('v:last_name', 'Smith'); + expect(appendSpy).toHaveBeenCalledWith('v:my_message_id', '123'); }); it('should transform a client object using a template into an API object', () => { transformSendEmailRequestIntoApiRequestBody(sendEmailRequestWithTemplate); expect(appendSpy).toHaveBeenCalledTimes(33); - expect(appendSpy).toHaveBeenCalledWith('from', - sendEmailRequestWithTemplate.from); - expect(appendSpy).toHaveBeenCalledWith('to', - sendEmailRequestWithTemplate.to); - expect(appendSpy).toHaveBeenCalledWith('cc', - sendEmailRequestWithTemplate.cc); - expect(appendSpy).toHaveBeenCalledWith('bcc', - sendEmailRequestWithTemplate.bcc); - expect(appendSpy).toHaveBeenCalledWith('subject', - sendEmailRequestWithTemplate.subject); - expect(appendSpy).toHaveBeenCalledWith('text', - sendEmailRequestWithTemplate.text); - expect(appendSpy).toHaveBeenCalledWith('template', - sendEmailRequestWithTemplate.template); - expect(appendSpy).toHaveBeenCalledWith('amp-html', - sendEmailRequestWithTemplate.amp_html); - expect(appendSpy).toHaveBeenCalledWith('attachment', - sendEmailRequestWithTemplate.attachment); - expect(appendSpy).toHaveBeenCalledWith('inline', - sendEmailRequestWithTemplate.inline); - expect(appendSpy).toHaveBeenCalledWith('o:tag', - sendEmailRequestWithTemplate.overrideProperties?.tag); - expect(appendSpy).toHaveBeenCalledWith('o:sending-ip', - sendEmailRequestWithTemplate.overrideProperties?.sendingIp); - expect(appendSpy).toHaveBeenCalledWith('o:sending-ip-pool', - sendEmailRequestWithTemplate.overrideProperties?.sendingIpPool); - expect(appendSpy).toHaveBeenCalledWith('o:deliverytime', - sendEmailRequestWithTemplate.overrideProperties?.deliveryTime); - expect(appendSpy).toHaveBeenCalledWith('o:deliverytime-optimize-period', - sendEmailRequestWithTemplate.overrideProperties?.deliveryTimeOptimizePeriod); - expect(appendSpy).toHaveBeenCalledWith('o:dkim', - sendEmailRequestWithTemplate.overrideProperties?.enableDkimSignature); - expect(appendSpy).toHaveBeenCalledWith('o:secondary-dkim', - sendEmailRequestWithTemplate.overrideProperties?.secondaryDkim); - expect(appendSpy).toHaveBeenCalledWith('o:secondary-dkim-public', - sendEmailRequestWithTemplate.overrideProperties?.secondaryDkimPublic); - expect(appendSpy).toHaveBeenCalledWith('o:require-tls', - sendEmailRequestWithTemplate.overrideProperties?.requireTls); - expect(appendSpy).toHaveBeenCalledWith('o:skip-verification', - sendEmailRequestWithTemplate.overrideProperties?.skipVerification); - expect(appendSpy).toHaveBeenCalledWith('o:time-zone-localize', - sendEmailRequestWithTemplate.overrideProperties?.timeZoneLocalize); - expect(appendSpy).toHaveBeenCalledWith('o:tracking', - sendEmailRequestWithTemplate.overrideProperties?.tracking); - expect(appendSpy).toHaveBeenCalledWith('o:tracking-opens', - sendEmailRequestWithTemplate.overrideProperties?.trackingOpens); - expect(appendSpy).toHaveBeenCalledWith('o:tracking-clicks', - sendEmailRequestWithTemplate.overrideProperties?.trackingClicks); - expect(appendSpy).toHaveBeenCalledWith('o:tracking-pixel-location-top', - sendEmailRequestWithTemplate.overrideProperties?.trackingPixelLocationTop); - expect(appendSpy).toHaveBeenCalledWith('o:testmode', - sendEmailRequestWithTemplate.overrideProperties?.isTestMode); - expect(appendSpy).toHaveBeenCalledWith('t:text', - // eslint-disable-next-line max-len - (sendEmailRequestWithTemplate as Mailgun.MessageContentWhereHtmlContentCanBeFromTemplateOnly).templateProperties?.text); - expect(appendSpy).toHaveBeenCalledWith('t:version', - // eslint-disable-next-line max-len - (sendEmailRequestWithTemplate as Mailgun.MessageContentWhereHtmlContentCanBeFromTemplateOnly).templateProperties?.version); - expect(appendSpy).toHaveBeenCalledWith('t:variables', - // eslint-disable-next-line max-len - (sendEmailRequestWithTemplate as Mailgun.MessageContentWhereHtmlContentCanBeFromTemplateOnly).templateProperties?.variables); - expect(appendSpy).toHaveBeenCalledWith('h:X-Mailgun-Sending-Ip-Pool', - sendEmailRequestWithTemplate['h:X-Mailgun-Sending-Ip-Pool']); - expect(appendSpy).toHaveBeenCalledWith('v:first_name', - sendEmailRequestWithTemplate['v:first_name']); - expect(appendSpy).toHaveBeenCalledWith('v:last_name', - sendEmailRequestWithTemplate['v:last_name']); - expect(appendSpy).toHaveBeenCalledWith('v:my_message_id', - sendEmailRequestWithTemplate['v:my_message_id']); + expect(appendSpy).toHaveBeenCalledWith('from', 'from value'); + expect(appendSpy).toHaveBeenCalledWith('to', 'to value'); + expect(appendSpy).toHaveBeenCalledWith('cc', 'cc value'); + expect(appendSpy).toHaveBeenCalledWith('bcc', 'bcc value'); + expect(appendSpy).toHaveBeenCalledWith('subject', 'subject value'); + expect(appendSpy).toHaveBeenCalledWith('text', 'text value'); + expect(appendSpy).toHaveBeenCalledWith('template', 'template value'); + expect(appendSpy).toHaveBeenCalledWith('amp-html', 'amp_html value'); + expect(appendSpy).toHaveBeenCalledWith('attachment', 'attachment value'); + expect(appendSpy).toHaveBeenCalledWith('inline', 'inline value'); + expect(appendSpy).toHaveBeenCalledWith('o:tag', 'tag value'); + expect(appendSpy).toHaveBeenCalledWith('o:sending-ip', 'sendingIp value'); + expect(appendSpy).toHaveBeenCalledWith('o:sending-ip-pool', 'sendingIpPool value'); + expect(appendSpy).toHaveBeenCalledWith('o:deliverytime', 'deliveryTime value'); + expect(appendSpy).toHaveBeenCalledWith('o:deliverytime-optimize-period', '36h'); + expect(appendSpy).toHaveBeenCalledWith('o:dkim', 'true'); + expect(appendSpy).toHaveBeenCalledWith('o:secondary-dkim', 'secondaryDkim value'); + expect(appendSpy).toHaveBeenCalledWith('o:secondary-dkim-public', 'secondaryDkimPublic value'); + expect(appendSpy).toHaveBeenCalledWith('o:require-tls', 'yes'); + expect(appendSpy).toHaveBeenCalledWith('o:skip-verification', 'no'); + expect(appendSpy).toHaveBeenCalledWith('o:time-zone-localize', '04:15AM'); + expect(appendSpy).toHaveBeenCalledWith('o:tracking', 'yes'); + expect(appendSpy).toHaveBeenCalledWith('o:tracking-clicks', 'no'); + expect(appendSpy).toHaveBeenCalledWith('o:tracking-opens', 'true'); + expect(appendSpy).toHaveBeenCalledWith('o:tracking-pixel-location-top', 'false'); + expect(appendSpy).toHaveBeenCalledWith('o:testmode', 'false'); + expect(appendSpy).toHaveBeenCalledWith('t:text', 'yes'); + expect(appendSpy).toHaveBeenCalledWith('t:version', 'version value'); + expect(appendSpy).toHaveBeenCalledWith('t:variables', 'variables value'); + expect(appendSpy).toHaveBeenCalledWith('h:X-Mailgun-Sending-Ip-Pool', 'xx.xx.xxx.x'); + expect(appendSpy).toHaveBeenCalledWith('v:first_name', 'John'); + expect(appendSpy).toHaveBeenCalledWith('v:last_name', 'Smith'); + expect(appendSpy).toHaveBeenCalledWith('v:my_message_id', '123'); }); }); diff --git a/packages/mailgun/tests/models/v1/emails/request/send-mime-email-request.models.ts b/packages/mailgun/tests/models/v1/emails/request/send-mime-email-request.models.ts index 345d5302..2188c21a 100644 --- a/packages/mailgun/tests/models/v1/emails/request/send-mime-email-request.models.ts +++ b/packages/mailgun/tests/models/v1/emails/request/send-mime-email-request.models.ts @@ -6,7 +6,7 @@ export const sendMimeEmailRequest: Mailgun.SendMimeEmailRequest = { template: 'template value', templateProperties: { version: 'version value', - text: 'text value', + text: 'yes', variables: 'variables value', }, overrideProperties: { @@ -14,17 +14,17 @@ export const sendMimeEmailRequest: Mailgun.SendMimeEmailRequest = { sendingIp: 'sendingIp value', sendingIpPool: 'sendingIpPool value', deliveryTime: 'deliveryTime value', - deliveryTimeOptimizePeriod: 'deliveryTimeOptimizePeriod value', - enableDkimSignature: 'enableDkimSignature value', + deliveryTimeOptimizePeriod: 72, + enableDkimSignature: false, secondaryDkim: 'secondaryDkim value', - secondaryDkimPublic: 'secondaryDkim value', - requireTls: 'requireTls value', - skipVerification: 'skipVerification value', - timeZoneLocalize: 'timeZoneLocalize value', - tracking: 'tracking value', - trackingClicks: 'trackingClicks value', - trackingOpens: 'trackingOpens value', - trackingPixelLocationTop: 'trackingPixelLocationTop value', + secondaryDkimPublic: 'secondaryDkimPublic value', + requireTls: false, + skipVerification: false, + timeZoneLocalize: '12:00PM', + tracking: 'no', + trackingClicks: 'no', + trackingOpens: 'no', + trackingPixelLocationTop: 'no', isTestMode: false, }, 'h:X-Mailgun-Sending-Ip-Pool': 'xx.xx.xxx.x', diff --git a/packages/mailgun/tests/models/v1/emails/request/send-mime-email-request.test.ts b/packages/mailgun/tests/models/v1/emails/request/send-mime-email-request.test.ts index 12b57af5..c84326fd 100644 --- a/packages/mailgun/tests/models/v1/emails/request/send-mime-email-request.test.ts +++ b/packages/mailgun/tests/models/v1/emails/request/send-mime-email-request.test.ts @@ -8,56 +8,31 @@ describe('SendMimeEmailRequest', () => { const appendSpy = jest.spyOn(FormData.prototype, 'append'); transformSendMimeEmailRequestIntoApiRequestBody(sendMimeEmailRequest); expect(appendSpy).toHaveBeenCalledTimes(26); - expect(appendSpy).toHaveBeenCalledWith('to', - sendMimeEmailRequest.to); - expect(appendSpy).toHaveBeenCalledWith('template', - sendMimeEmailRequest.template); - expect(appendSpy).toHaveBeenCalledWith('o:tag', - sendMimeEmailRequest.overrideProperties?.tag); - expect(appendSpy).toHaveBeenCalledWith('o:sending-ip', - sendMimeEmailRequest.overrideProperties?.sendingIp); - expect(appendSpy).toHaveBeenCalledWith('o:sending-ip-pool', - sendMimeEmailRequest.overrideProperties?.sendingIpPool); - expect(appendSpy).toHaveBeenCalledWith('o:deliverytime', - sendMimeEmailRequest.overrideProperties?.deliveryTime); - expect(appendSpy).toHaveBeenCalledWith('o:deliverytime-optimize-period', - sendMimeEmailRequest.overrideProperties?.deliveryTimeOptimizePeriod); - expect(appendSpy).toHaveBeenCalledWith('o:dkim', - sendMimeEmailRequest.overrideProperties?.enableDkimSignature); - expect(appendSpy).toHaveBeenCalledWith('o:secondary-dkim', - sendMimeEmailRequest.overrideProperties?.secondaryDkim); - expect(appendSpy).toHaveBeenCalledWith('o:secondary-dkim-public', - sendMimeEmailRequest.overrideProperties?.secondaryDkimPublic); - expect(appendSpy).toHaveBeenCalledWith('o:require-tls', - sendMimeEmailRequest.overrideProperties?.requireTls); - expect(appendSpy).toHaveBeenCalledWith('o:skip-verification', - sendMimeEmailRequest.overrideProperties?.skipVerification); - expect(appendSpy).toHaveBeenCalledWith('o:time-zone-localize', - sendMimeEmailRequest.overrideProperties?.timeZoneLocalize); - expect(appendSpy).toHaveBeenCalledWith('o:tracking', - sendMimeEmailRequest.overrideProperties?.tracking); - expect(appendSpy).toHaveBeenCalledWith('o:tracking-opens', - sendMimeEmailRequest.overrideProperties?.trackingOpens); - expect(appendSpy).toHaveBeenCalledWith('o:tracking-clicks', - sendMimeEmailRequest.overrideProperties?.trackingClicks); - expect(appendSpy).toHaveBeenCalledWith('o:tracking-pixel-location-top', - sendMimeEmailRequest.overrideProperties?.trackingPixelLocationTop); - expect(appendSpy).toHaveBeenCalledWith('o:testmode', - sendMimeEmailRequest.overrideProperties?.isTestMode); - expect(appendSpy).toHaveBeenCalledWith('t:text', - sendMimeEmailRequest.templateProperties?.text); - expect(appendSpy).toHaveBeenCalledWith('t:version', - sendMimeEmailRequest.templateProperties?.version); - expect(appendSpy).toHaveBeenCalledWith('t:variables', - sendMimeEmailRequest.templateProperties?.variables); - expect(appendSpy).toHaveBeenCalledWith('h:X-Mailgun-Sending-Ip-Pool', - sendMimeEmailRequest['h:X-Mailgun-Sending-Ip-Pool']); - expect(appendSpy).toHaveBeenCalledWith('v:first_name', - sendMimeEmailRequest['v:first_name']); - expect(appendSpy).toHaveBeenCalledWith('v:last_name', - sendMimeEmailRequest['v:last_name']); - expect(appendSpy).toHaveBeenCalledWith('v:my_message_id', - sendMimeEmailRequest['v:my_message_id']); + expect(appendSpy).toHaveBeenCalledWith('to', 'to value'); + expect(appendSpy).toHaveBeenCalledWith('template', 'template value'); + expect(appendSpy).toHaveBeenCalledWith('o:tag', 'tag value'); + expect(appendSpy).toHaveBeenCalledWith('o:sending-ip', 'sendingIp value'); + expect(appendSpy).toHaveBeenCalledWith('o:sending-ip-pool', 'sendingIpPool value'); + expect(appendSpy).toHaveBeenCalledWith('o:deliverytime', 'deliveryTime value'); + expect(appendSpy).toHaveBeenCalledWith('o:deliverytime-optimize-period', '72h'); + expect(appendSpy).toHaveBeenCalledWith('o:dkim', 'false'); + expect(appendSpy).toHaveBeenCalledWith('o:secondary-dkim', 'secondaryDkim value'); + expect(appendSpy).toHaveBeenCalledWith('o:secondary-dkim-public', 'secondaryDkimPublic value'); + expect(appendSpy).toHaveBeenCalledWith('o:require-tls', 'false'); + expect(appendSpy).toHaveBeenCalledWith('o:skip-verification', 'false'); + expect(appendSpy).toHaveBeenCalledWith('o:time-zone-localize', '12:00PM'); + expect(appendSpy).toHaveBeenCalledWith('o:tracking', 'no'); + expect(appendSpy).toHaveBeenCalledWith('o:tracking-opens', 'no'); + expect(appendSpy).toHaveBeenCalledWith('o:tracking-clicks', 'no'); + expect(appendSpy).toHaveBeenCalledWith('o:tracking-pixel-location-top', 'no'); + expect(appendSpy).toHaveBeenCalledWith('o:testmode', 'false'); + expect(appendSpy).toHaveBeenCalledWith('t:text', 'yes'); + expect(appendSpy).toHaveBeenCalledWith('t:version', 'version value'); + expect(appendSpy).toHaveBeenCalledWith('t:variables', 'variables value'); + expect(appendSpy).toHaveBeenCalledWith('h:X-Mailgun-Sending-Ip-Pool', 'xx.xx.xxx.x'); + expect(appendSpy).toHaveBeenCalledWith('v:first_name', 'John'); + expect(appendSpy).toHaveBeenCalledWith('v:last_name', 'Smith'); + expect(appendSpy).toHaveBeenCalledWith('v:my_message_id', '123'); }); });