mirror of
https://github.com/tiennm99/is-a-dev.git
synced 2026-10-12 22:14:49 +00:00
45 lines
1.3 KiB
JavaScript
45 lines
1.3 KiB
JavaScript
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);
|
|
});
|
|
});
|
|
});
|
|
|