diff --git a/tests/cpanel.test.js b/tests/cpanel.test.js index f92ce51d3..d2fbd35a3 100644 --- a/tests/cpanel.test.js +++ b/tests/cpanel.test.js @@ -88,6 +88,33 @@ describe('Cpanel client', () => { }); }); + describe('addzonerecord', () => { + it('should make the correct request', async () => { + const fetch = mockFetch((url, request) => { + expect(url).toBe('https://example.com:2000/json-api/cpanel?domain=a.b&line=500&cpanel_jsonapi_user=boy&cpanel_jsonapi_module=ZoneEdit&cpanel_jsonapi_func=remove_zone_record&cpanel_jsonapi_apiversion=2'); + expect(request).toEqual({ + headers: { + Authorization: 'cpanel boy:boybyebye', + }, + rejectUnauthorized: false, + }); + }); + + const cpanel = CpanelClient({ + host: 'example.com', + port: 2000, + username: 'boy', + apiKey: 'boybyebye', + domain: 'a.b', + dependencies: { fetch }, + }); + + await cpanel.zone.remove({ + line: 500, + }); + }); + }); + describe('fetchredirections', () => { it('should make the correct request', async () => { const fetch = mockFetch((url, request) => { @@ -139,5 +166,30 @@ describe('Cpanel client', () => { }); }); }); + + describe('deleteredirection', () => { + it('should make the correct request', async () => { + const fetch = mockFetch((url, request) => { + expect(url).toBe('https://example.com:2000/execute/Mime/delete_redirect?domain=googo&cpanel_jsonapi_user=boy&cpanel_jsonapi_module=Mime&cpanel_jsonapi_func=delete_redirect&cpanel_jsonapi_apiversion=2'); + expect(request).toEqual({ + headers: { + Authorization: 'cpanel boy:boybyebye', + }, + rejectUnauthorized: false, + }); + }); + + const cpanel = CpanelClient({ + host: 'example.com', + port: 2000, + username: 'boy', + apiKey: 'boybyebye', + domain: 'a.b', + dependencies: { fetch }, + }); + + await cpanel.redirection.remove({ domain: 'googo' }); + }); + }); }); diff --git a/utils/lib/cpanel.js b/utils/lib/cpanel.js index c29c10145..397a677a7 100644 --- a/utils/lib/cpanel.js +++ b/utils/lib/cpanel.js @@ -45,10 +45,9 @@ const CpanelClient = (options) => { // { name, type(A|CNAME), cname, address, ttl } // -> {} add: api2('ZoneEdit', 'add_zone_record', { domain: options.domain }), - - // { name, type(A|CNAME), cname, address, ttl } + // { line } // -> {} - edit: api2('ZoneEdit', 'edit_zone_record', { domain: options.domain }), + remove: api2('ZoneEdit', 'remove_zone_record', { domain: options.domain }), }, redirection: { // {} @@ -61,7 +60,9 @@ const CpanelClient = (options) => { // { domain, redirect, type(permanent|tmp), redirect_wildcard(0|1), redirect(0|1|2) } // -> {} add: uapi('Mime', 'add_redirect'), - edit: uapi('Mime', 'add_redirect'), // NOTE: adding new updates exisiting + // { domain } + // -> {} + remove: uapi('Mime', 'delete_redirect'), }, }; };