Skip to content

Commit

Permalink
other: Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
olexandr-mazepa committed Jan 7, 2025
1 parent 21f91ac commit 77a0966
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 51 deletions.
5 changes: 0 additions & 5 deletions dist/Types/Domains/Domains.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ export type DomainInfo = DomainUpdateInfo & {
wildcard?: boolean | 'true' | 'false';
pool_id?: '';
ips?: '';
spam_action?: 'disabled' | 'block' | 'tag';
smtp_password?: string;
use_automatic_sender_security?: boolean | 'true' | 'false';
web_prefix?: string;
web_scheme?: string;
};
export type DomainInfoReq = DomainInfo & {
force_dkim_authority?: 'true' | 'false';
Expand Down
4 changes: 2 additions & 2 deletions dist/mailgun.node.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/mailgun.web.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/Classes/Domains/domainsClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export default class DomainsClient implements IDomainsClient {
if (typeof data?.active === 'boolean') {
preparedData.active = (data?.active) ? 'yes' : 'no';
}
return this.request.putWithFD(urljoin('/v3/domains', domain, 'tracking', type), data)
return this.request.putWithFD(urljoin('/v3/domains', domain, 'tracking', type), preparedData)
.then((res : APIResponse) => this._parseTrackingUpdate(res as UpdateDomainTrackingResponse));
}

Expand Down
5 changes: 0 additions & 5 deletions lib/Types/Domains/Domains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ export type DomainInfo = DomainUpdateInfo & {
wildcard?: boolean | 'true' | 'false';
pool_id?: '';
ips?: '';
spam_action?: 'disabled' | 'block' | 'tag';
smtp_password?: string;
use_automatic_sender_security?: boolean | 'true' | 'false';
web_prefix?: string;
web_scheme?: string;
}

export type DomainInfoReq = DomainInfo & {
Expand Down
144 changes: 108 additions & 36 deletions test/domains.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ describe('DomainsClient', function () {
reqObject,
domainCredentialsClient,
domainTemplatesClient,
domainTagsClient
domainTagsClient,
// eslint-disable-next-line @typescript-eslint/no-empty-function
{ warn: () => {} }
);
api = nock('https://api.mailgun.net');
});
Expand All @@ -55,10 +57,15 @@ describe('DomainsClient', function () {
type: 'custom',
wildcard: true,
skip_verification: true,
require_tls: true
require_tls: true,
id: 'test_id',
is_disabled: false,
use_automatic_sender_security: false,
web_prefix: 'web_prefix_value',
web_scheme: 'https'
}];

api.get('/v3/domains').reply(200, {
api.get('/v4/domains').reply(200, {
items: domains
});

Expand All @@ -75,13 +82,18 @@ describe('DomainsClient', function () {
spam_action: 'disabled',
state: 'unverified',
type: 'custom',
wildcard: true
wildcard: true,
id: 'test_id',
is_disabled: false,
use_automatic_sender_security: false,
web_prefix: 'web_prefix_value',
web_scheme: 'https'
});
});
});

it('returns empty array if items property is empty', async () => {
api.get('/v3/domains').reply(200, {
api.get('/v4/domains').reply(200, {
items: null
});
const res :TDomain[] = await client.list();
Expand All @@ -106,10 +118,11 @@ describe('DomainsClient', function () {
id: 'test_id',
is_disabled: false,
web_prefix: 'email',
web_scheme: 'https'
web_scheme: 'https',
use_automatic_sender_security: false,
};

api.get('/v3/domains/testing.example.com').reply(200, {
api.get('/v4/domains/testing.example.com').reply(200, {
domain: domainData,
receiving_dns_records: [],
sending_dns_records: []
Expand All @@ -133,7 +146,8 @@ describe('DomainsClient', function () {
id: 'test_id',
is_disabled: false,
web_prefix: 'email',
web_scheme: 'https'
web_scheme: 'https',
use_automatic_sender_security: false,
});
});
});
Expand All @@ -156,10 +170,11 @@ describe('DomainsClient', function () {
id: 'test_id',
is_disabled: false,
web_prefix: 'email',
web_scheme: 'https'
web_scheme: 'https',
use_automatic_sender_security: false,
};

api.post('/v3/domains').reply(200, {
api.post('/v4/domains').reply(200, {
domain: domainData,
receiving_dns_records: [],
sending_dns_records: []
Expand Down Expand Up @@ -187,13 +202,14 @@ describe('DomainsClient', function () {
web_prefix: 'email',
web_scheme: 'https',
id: 'test_id',
use_automatic_sender_security: false,
});
});
});

it('converts boolean true for force_dkim_authority and wildcard to string', async () => {
it('converts boolean TRUE values to string', async () => {
let requestObject;
api.post('/v3/domains').reply(200, function (_uri, requestBody) {
api.post('/v4/domains').reply(200, function (_uri, requestBody) {
requestObject = requestBody as formData;
return {
domain: {
Expand All @@ -209,14 +225,20 @@ describe('DomainsClient', function () {
web_scheme: 'https',
force_dkim_authority: true,
wildcard: true,
encrypt_incoming_message: true,
force_root_dkim_host: true,
use_automatic_sender_security: true,
});
expect(requestObject).to.have.string('name="force_dkim_authority"\r\n\r\ntrue\r\n----------------------------');
expect(requestObject).to.have.string('name="wildcard"\r\n\r\ntrue\r\n----------------------------');
expect(requestObject).to.have.string('name="encrypt_incoming_message"\r\n\r\ntrue\r\n----------------------------');
expect(requestObject).to.have.string('name="force_root_dkim_host"\r\n\r\ntrue\r\n----------------------------');
expect(requestObject).to.have.string('name="use_automatic_sender_security"\r\n\r\ntrue\r\n----------------------------');
});

it('converts boolean false for force_dkim_authority and wildcard to string', async () => {
it('converts boolean FALSE values to string', async () => {
let requestObject;
api.post('/v3/domains').reply(200, function (_uri, requestBody) {
api.post('/v4/domains').reply(200, function (_uri, requestBody) {
requestObject = requestBody as formData;
return {
domain: {
Expand All @@ -232,9 +254,15 @@ describe('DomainsClient', function () {
web_scheme: 'https',
force_dkim_authority: false,
wildcard: false,
encrypt_incoming_message: false,
force_root_dkim_host: false,
use_automatic_sender_security: false,
});
expect(requestObject).to.have.string('name="force_dkim_authority"\r\n\r\nfalse\r\n----------------------------');
expect(requestObject).to.have.string('name="wildcard"\r\n\r\nfalse\r\n----------------------------');
expect(requestObject).to.have.string('name="encrypt_incoming_message"\r\n\r\nfalse\r\n----------------------------');
expect(requestObject).to.have.string('name="force_root_dkim_host"\r\n\r\nfalse\r\n----------------------------');
expect(requestObject).to.have.string('name="use_automatic_sender_security"\r\n\r\nfalse\r\n----------------------------');
});
});
describe('update', function () {
Expand All @@ -255,9 +283,10 @@ describe('DomainsClient', function () {
is_disabled: false,
web_prefix: 'email',
web_scheme: 'http',
use_automatic_sender_security: false,
};

api.put('/v3/domains/testing.example.com').reply(200, {
api.put('/v4/domains/testing.example.com').reply(200, {
domain: domainData,
receiving_dns_records: [],
sending_dns_records: []
Expand Down Expand Up @@ -286,12 +315,13 @@ describe('DomainsClient', function () {
is_disabled: false,
web_prefix: 'email',
web_scheme: 'http',
use_automatic_sender_security: false,
});
});

it('converts boolean true for wildcard to string', async () => {
it('converts boolean TRUE values to string', async () => {
let requestObject;
api.put('/v3/domains/testing.example.com').reply(200, function (_uri, requestBody) {
api.put('/v4/domains/testing.example.com').reply(200, function (_uri, requestBody) {
requestObject = requestBody as formData;
return {
domain: {
Expand All @@ -304,14 +334,16 @@ describe('DomainsClient', function () {
await client.update('testing.example.com', {
wildcard: true,
web_scheme: 'http',
spam_action: 'disabled'
spam_action: 'disabled',
use_automatic_sender_security: true,
});
expect(requestObject).to.have.string('name="wildcard"\r\n\r\ntrue\r\n----------------------------');
expect(requestObject).to.have.string('name="use_automatic_sender_security"\r\n\r\ntrue\r\n----------------------------');
});

it('converts boolean false for wildcard to string', async () => {
it('converts boolean FALSE values to string', async () => {
let requestObject;
api.put('/v3/domains/testing.example.com').reply(200, function (_uri, requestBody) {
api.put('/v4/domains/testing.example.com').reply(200, function (_uri, requestBody) {
requestObject = requestBody as formData;
return {
domain: {
Expand All @@ -324,9 +356,11 @@ describe('DomainsClient', function () {
await client.update('testing.example.com', {
wildcard: false,
web_scheme: 'http',
spam_action: 'disabled'
spam_action: 'disabled',
use_automatic_sender_security: false,
});
expect(requestObject).to.have.string('name="wildcard"\r\n\r\nfalse\r\n----------------------------');
expect(requestObject).to.have.string('name="use_automatic_sender_security"\r\n\r\nfalse\r\n----------------------------');
});
});

Expand All @@ -342,10 +376,15 @@ describe('DomainsClient', function () {
type: 'custom',
wildcard: true,
skip_verification: true,
require_tls: true
require_tls: true,
id: 'test_id',
is_disabled: false,
use_automatic_sender_security: false,
web_prefix: 'web_prefix_value',
web_scheme: 'https'
};

api.put('/v3/domains/test.example.com/verify').reply(200, {
api.put('/v4/domains/test.example.com/verify').reply(200, {
domain: domainData,
receiving_dns_records: [
{
Expand Down Expand Up @@ -396,7 +435,12 @@ describe('DomainsClient', function () {
spam_action: 'disabled',
state: 'active',
type: 'custom',
wildcard: true
wildcard: true,
id: 'test_id',
is_disabled: false,
use_automatic_sender_security: false,
web_prefix: 'web_prefix_value',
web_scheme: 'https'
});
});
});
Expand All @@ -419,7 +463,7 @@ describe('DomainsClient', function () {
describe('getConnection', function () {
it('returns connection settings for the defined domain', function () {
api.get('/v3/domains/test.example.com/connection').reply(200, {
connection: { require_tls: false, skip_verification: false }
require_tls: false, skip_verification: false
});

return client.getConnection('test.example.com').then(function (data: ConnectionSettings) {
Expand Down Expand Up @@ -487,18 +531,46 @@ describe('DomainsClient', function () {
});
});

it('checks input parameter', async function () {
try {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
await client.updateTracking('domain.com', 'open', { active: true });
} catch (error) {
expect(error).to.include({
status: 400,
details: 'Property "active" must contain string value.',
message: 'Received boolean value for active property'
it('converts boolean TRUE values to string (OPEN)', async () => {
let requestObject;
api.put('/v3/domains/domain.com/tracking/open').reply(200,
function (_uri, requestBody) {
requestObject = requestBody as formData;
return {
message: 'message_value',
open: { active: true }
};
});
}
await client.updateTracking('domain.com', 'open', { active: true });
expect(requestObject).to.have.string('name="active"\r\n\r\nyes\r\n----------------------------');
});

it('converts boolean TRUE values to string (CLICK)', async () => {
let requestObject;
api.put('/v3/domains/domain.com/tracking/click').reply(200,
function (_uri, requestBody) {
requestObject = requestBody as formData;
return {
message: 'message_value',
click: { active: true }
};
});
await client.updateTracking('domain.com', 'click', { active: true });
expect(requestObject).to.have.string('name="active"\r\n\r\nyes\r\n----------------------------');
});

it('converts boolean TRUE values to string (UNSUBSCRIBE)', async () => {
let requestObject;
api.put('/v3/domains/domain.com/tracking/unsubscribe').reply(200,
function (_uri, requestBody) {
requestObject = requestBody as formData;
return {
message: 'message_value',
unsubscribe: { active: true }
};
});
await client.updateTracking('domain.com', 'unsubscribe', { active: true });
expect(requestObject).to.have.string('name="active"\r\n\r\nyes\r\n----------------------------');
});
});

Expand Down

0 comments on commit 77a0966

Please sign in to comment.