From bd3a5a5043230d8bf23e769bf6c956584ea2d82b Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Sun, 11 Oct 2020 22:22:28 +0530 Subject: [PATCH] Adds req test cases for redirection fetch --- tests/cpanel.test.js | 58 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 3 deletions(-) diff --git a/tests/cpanel.test.js b/tests/cpanel.test.js index a32c562cf..f92ce51d3 100644 --- a/tests/cpanel.test.js +++ b/tests/cpanel.test.js @@ -30,7 +30,7 @@ describe('Cpanel client', () => { dependencies: { fetch }, }); - await cpanel.fetchZoneRecords(); + await cpanel.zone.fetch(); }); it('should make the correct request with query', async () => { @@ -53,7 +53,7 @@ describe('Cpanel client', () => { dependencies: { fetch }, }); - await cpanel.fetchZoneRecords({ domain: 'foobar.boeey' }); + await cpanel.zone.fetch({ domain: 'foobar.boeey' }); }); }); @@ -78,7 +78,7 @@ describe('Cpanel client', () => { dependencies: { fetch }, }); - await cpanel.addZoneRecord({ + await cpanel.zone.add({ name: 'googo', type: 'boyee', cname: 'beey', @@ -87,5 +87,57 @@ describe('Cpanel client', () => { }); }); }); + + describe('fetchredirections', () => { + it('should make the correct request', async () => { + const fetch = mockFetch((url, request) => { + expect(url).toBe('https://example.com:2000/execute/Mime/list_redirects?cpanel_jsonapi_user=boy&cpanel_jsonapi_module=Mime&cpanel_jsonapi_func=list_redirects&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.fetch(); + }); + }); + describe('addredirection', () => { + it('should make the correct request', async () => { + const fetch = mockFetch((url, request) => { + expect(url).toBe('https://example.com:2000/execute/Mime/add_redirect?domain=googo&destination=https%3A%2F%2Foodf.com&cpanel_jsonapi_user=boy&cpanel_jsonapi_module=Mime&cpanel_jsonapi_func=add_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.add({ + domain: 'googo', + destination: 'https://oodf.com' + }); + }); + }); });