mirror of
https://github.com/tiennm99/is-a-dev.git
synced 2026-10-03 07:13:09 +00:00
Adds namecheap api calls + test (with sandbox debug code)
This commit is contained in:
1 parent
e8203c73f5
commit
d01aba314b
7 files changed
+145
No files matched your search
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user