mirror of
https://github.com/tiennm99/is-a-dev.git
synced 2026-08-11 18:22:21 +00:00
Fixed broken test case
This commit is contained in:
+19
-19
@@ -3,16 +3,16 @@ const { toHostList, registerDomains } = require('../scripts/register-domains');
|
||||
const { TTL, DOMAIN_DOMAIN } = require('../utils/constants');
|
||||
const { getDomainService } = require('../utils/domain-service');
|
||||
|
||||
const getCpanel = ({ zone, addZone, editZone, redir, addRedir, editRedir } = {}) => ({
|
||||
const getCpanel = ({ zone, addZone, removeZone, redir, addRedir, removeRedir } = {}) => ({
|
||||
zone: {
|
||||
fetch: (_) => zone(),
|
||||
add: (rec) => addZone(rec),
|
||||
edit: (rec) => editZone(rec),
|
||||
remove: (rec) => removeZone(rec),
|
||||
},
|
||||
redirection: {
|
||||
fetch: (_) => redir(),
|
||||
add: (rec) => addRedir(rec),
|
||||
edit: (rec) => editRedir(rec),
|
||||
remove: (rec) => removeRedir(rec),
|
||||
},
|
||||
});
|
||||
|
||||
@@ -36,24 +36,24 @@ describe('toHostList', () => {
|
||||
|
||||
describe('registerDomains', () => {
|
||||
const addZone = jest.fn(async () => ({}));
|
||||
const editZone = jest.fn(async () => ({}));
|
||||
const removeZone = jest.fn(async () => ({}));
|
||||
const addRedir = jest.fn(async () => ({}));
|
||||
const editRedir = jest.fn(async () => ({}));
|
||||
const removeRedir = jest.fn(async () => ({}));
|
||||
|
||||
const mockDS = ({ zones, redirections }) => getDomainService({ cpanel: getCpanel({
|
||||
zone: async () => zones,
|
||||
redir: async () => redirections,
|
||||
addZone,
|
||||
addRedir,
|
||||
editZone,
|
||||
editRedir,
|
||||
removeZone,
|
||||
removeRedir,
|
||||
}) });
|
||||
|
||||
beforeEach(() => {
|
||||
addZone.mockClear();
|
||||
editZone.mockClear();
|
||||
removeZone.mockClear();
|
||||
addRedir.mockClear();
|
||||
editRedir.mockClear();
|
||||
removeRedir.mockClear();
|
||||
});
|
||||
|
||||
it('should register the new set of hosts generated from domains list', async () => {
|
||||
@@ -62,9 +62,9 @@ describe('registerDomains', () => {
|
||||
{ name: 'b', record: { CNAME: 'xaa' } },
|
||||
];
|
||||
const remoteHosts = [
|
||||
{ someididk: 1, name: 'a', type: 'CNAME', address: 'hello' },
|
||||
{ someididk: 2, name: 'b', type: 'CNAME', address: 'goo' },
|
||||
{ someididk: 2, name: 'b', type: 'CNAME', address: 'xaa' },
|
||||
{ line: 1, name: 'a', type: 'CNAME', address: 'hello' },
|
||||
{ line: 2, name: 'b', type: 'CNAME', address: 'goo' },
|
||||
{ line: 3, name: 'b', type: 'CNAME', address: 'xaa' },
|
||||
];
|
||||
const remoteRedirections = [];
|
||||
|
||||
@@ -72,9 +72,9 @@ describe('registerDomains', () => {
|
||||
await registerDomains({ getDomains: async () => localHosts, domainService });
|
||||
|
||||
expect(addZone).toBeCalledTimes(0);
|
||||
expect(editZone).toBeCalledTimes(0);
|
||||
expect(removeZone).toBeCalledTimes(1);
|
||||
expect(addRedir).toBeCalledTimes(0);
|
||||
expect(editRedir).toBeCalledTimes(0);
|
||||
expect(removeRedir).toBeCalledTimes(0);
|
||||
});
|
||||
|
||||
it('should add the new set hosts', async () => {
|
||||
@@ -84,8 +84,8 @@ describe('registerDomains', () => {
|
||||
{ name: 'c', record: { CNAME: 'yello', URL: 'https://google.com' } },
|
||||
];
|
||||
const remoteHosts = [
|
||||
{ someididk: 1, name: 'a', type: 'CNAME', address: 'boo' },
|
||||
{ someididk: 2, name: 'b', type: 'CNAME', address: 'xaa' },
|
||||
{ line: 1, name: 'a', type: 'CNAME', address: 'boo' },
|
||||
{ line: 2, name: 'b', type: 'CNAME', address: 'xaa' },
|
||||
];
|
||||
const remoteRedirections = [
|
||||
{ domain: `b.${DOMAIN_DOMAIN}`, destination: 'x' },
|
||||
@@ -96,9 +96,9 @@ describe('registerDomains', () => {
|
||||
await registerDomains({ getDomains: async () => localHosts, domainService });
|
||||
|
||||
expect(addZone).toBeCalledTimes(1);
|
||||
expect(editZone).toBeCalledTimes(0);
|
||||
expect(addRedir).toBeCalledTimes(1);
|
||||
expect(editRedir).toBeCalledTimes(1);
|
||||
expect(removeZone).toBeCalledTimes(0);
|
||||
expect(addRedir).toBeCalledTimes(2);
|
||||
expect(removeRedir).toBeCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ const getDomainService = ({ cpanel }) => {
|
||||
cpanel.zone.remove,
|
||||
R.pick(['line']),
|
||||
recordToZone,
|
||||
print(({ name }) => `Editing zone for ${name}...`),
|
||||
print(({ name }) => `Deleting zone for ${name}...`),
|
||||
));
|
||||
const addRedirection = lazyTask(R.compose(
|
||||
cpanel.redirection.add,
|
||||
@@ -102,7 +102,7 @@ const getDomainService = ({ cpanel }) => {
|
||||
cpanel.redirection.remove,
|
||||
R.pick(['domain']),
|
||||
recordToRedirection,
|
||||
print(({ name }) => `Editing redirection for ${name}`),
|
||||
print(({ name }) => `Deleting redirection for ${name}`),
|
||||
));
|
||||
|
||||
const getHosts = async () => {
|
||||
|
||||
Reference in New Issue
Block a user