From acb6c96901ac4a5168900d6c01d5c46f41dc2466 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Sun, 4 Oct 2020 22:43:21 +0530 Subject: [PATCH] Removes case for preserving existing records --- tests/domain-service.test.js | 27 --------------------------- utils/domain-service.js | 16 ++-------------- 2 files changed, 2 insertions(+), 41 deletions(-) diff --git a/tests/domain-service.test.js b/tests/domain-service.test.js index c9280df13..7b62be8bd 100644 --- a/tests/domain-service.test.js +++ b/tests/domain-service.test.js @@ -115,33 +115,6 @@ describe('Domain service', () => { { HostName: 'b', RecordType: 'CNAME', Address: 'farboo' }, ]); }); - - xit('should maintain existing entries on the server', async () => { - const records = [ - { HostId: 1, Name: 'a', Type: 'CNAME', Address: 'boo' }, - { HostId: 2, Name: 'b', Type: 'CNAME', Address: 'goo' }, - { HostId: 3, Name: 'c', Type: 'A', Address: '12.131321.213' }, - ]; - - const onGet = () => Promise.resolve({ hosts: records }); - const onSet = jest.fn(async () => ({})); - - const mockDomainService = getDomainService({ Namecheap: getNcClass({ onSet, onGet }) }); - await mockDomainService.updateHosts([ - { HostName: 'a', RecordType: 'CNAME', Address: 'boo' }, - { HostName: 'b', RecordType: 'CNAME', Address: 'goo' }, - ]); - - const [hosts] = onSet.mock.calls[0]; - - expect(hosts.map(R.pick(['HostName', 'RecordType', 'Address']))).toEqual([ - { HostName: 'a', RecordType: 'CNAME', Address: 'boo' }, - { HostName: 'b', RecordType: 'CNAME', Address: 'goo' }, - { HostName: 'c', RecordType: 'A', Address: '12.131321.213' }, - ]); - expect(); - // expect(onSet).toBeCalledTimes(1); - }); }); }); diff --git a/utils/domain-service.js b/utils/domain-service.js index 1cda12989..4f768ebf1 100644 --- a/utils/domain-service.js +++ b/utils/domain-service.js @@ -43,6 +43,7 @@ const getDomainService = ({ Namecheap }) => { const key = getHostKey(host); return { ...acc, [key]: [ ...(acc[key] || []), host ] }; }, {}); + const updateHosts = async hosts => { const hostList = await getHosts(); const remoteHostMap = toHostMap(hostList); @@ -58,7 +59,7 @@ const getDomainService = ({ Namecheap }) => { return [...acc, ...local]; }, []); - await setHosts(newHostList); + return setHosts(newHostList); }; return { getHosts, setHosts, updateHosts }; @@ -69,16 +70,3 @@ module.exports = { domainService: getDomainService({ Namecheap }), }; -//getDomainService({ Namecheap }).setHosts([ - //{ HostName: 'fuck', RecordType: 'CNAME', Address: 'google.com', TTL }, - //{ HostName: 'fuck.booboo.xyz', RecordType: 'URL', Address: 'https://fuck.booboo.xyz' }, - //{ HostName: 'foobar', RecordType: 'CNAME', Address: 'duckduckgo.com', TTL }, - //{ HostName: 'hello', RecordType: 'A', Address: '103.130.211.123', TTL }, -//]).then(console.log).catch(console.error); - -//getDomainService({ Namecheap }).getHosts() - //.then(console.log) - //.catch(console.error); - -//getDomainService({ Namecheap }).hasHost({ HostName: 'fuck', RecordType: 'CNAME', Address: 'duckduckgo.com' }); -