Adds namecheap api calls + test (with sandbox debug code)

This commit is contained in:
Akshay Nair committed 2020-10-04 19:23:01 +05:30
1 parent e8203c73f5
commit d01aba314b
7 files changed
+145

No files matched your search

+44
View File
@@ -0,0 +1,44 @@
const R = require('ramda');
const { getDomainService } = require('../utils/domain-service');
const getNcClass = ({ onSet, onGet } = {}) => class Namecheap {
dns = {
setHosts: (_, list) => onSet(list),
getHosts: (_) => onGet(),
};
};
describe('Domain service', () => {
describe('getHosts', () => {
it('should resolve with a list of hosts', async () => {
const hosts = [
{ Name: 'xx', Type: 'CNAME', Address: 'fck.com.' },
{ Name: 'xx', Type: 'A', Address: '111.1.1212.1' },
];
const onGet = async () => ({ hosts })
const mockDomainService = getDomainService({ Namecheap: getNcClass({ onGet }) });
const list = await mockDomainService.getHosts();
expect(list).toEqual([
{ HostName: 'xx', RecordType: 'CNAME', Address: 'fck.com' },
{ HostName: 'xx', RecordType: 'A', Address: '111.1.1212.1' },
]);
});
});
describe('setHosts', () => {
it('should resolve with a list of hosts', async () => {
const records = [ { x: 'y' }, { z: 'a' } ];
const onSet = jest.fn((list) => {
expect(list).toBe(records);
return Promise.resolve(null);
});
const mockDomainService = getDomainService({ Namecheap: getNcClass({ onSet }) });
await mockDomainService.setHosts(records);
expect(onSet).toBeCalledTimes(1);
});
});
});