mirror of
https://github.com/tiennm99/is-a-dev.git
synced 2026-10-16 12:15:25 +00:00
Adds complicated test case
This commit is contained in:
1 parent
281f88ea5f
commit
3cdad9b28d
1 file changed
+49
-4
@@ -11,12 +11,11 @@ const getCpanel = ({ zone, addZone, editZone, redir, addRedir, editRedir } = {})
|
|||||||
redirection: {
|
redirection: {
|
||||||
fetch: (_) => redir(),
|
fetch: (_) => redir(),
|
||||||
add: (rec) => addRedir(rec),
|
add: (rec) => addRedir(rec),
|
||||||
edit: (rec) => editZone(rec),
|
edit: (rec) => editRedir(rec),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('diffRecords', () => {
|
describe('diffRecords', () => {
|
||||||
return;
|
|
||||||
it('should show added record', () => {
|
it('should show added record', () => {
|
||||||
const oldRecords = [
|
const oldRecords = [
|
||||||
{ name: 'xx', type: 'CNAME', address: 'fck.com.' },
|
{ name: 'xx', type: 'CNAME', address: 'fck.com.' },
|
||||||
@@ -92,8 +91,7 @@ describe('Domain service', () => {
|
|||||||
editRedir,
|
editRedir,
|
||||||
}) });
|
}) });
|
||||||
|
|
||||||
const getRecordCalls = recfn => recfn.mock.calls.map(R.head).map(R.pick(['name', 'type', 'address']));
|
const getRecordCalls = recfn => recfn.mock.calls.map(R.head).map(R.pick(['name', 'type', 'address', 'redirect', 'domain']));
|
||||||
const getZoneCalls = () => getRecordCalls(addZone);
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
addZone.mockClear();
|
addZone.mockClear();
|
||||||
@@ -247,6 +245,53 @@ describe('Domain service', () => {
|
|||||||
{ name: 'b', type: 'CNAME', address: 'farboo' },
|
{ name: 'b', type: 'CNAME', address: 'farboo' },
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should workout this complex example', async () => {
|
||||||
|
const zones = [
|
||||||
|
{ someid: 1, name: 'a', type: 'CNAME', address: 'world' },
|
||||||
|
{ someid: 2, name: 'b', type: 'A', address: '1' },
|
||||||
|
{ someid: 2, name: 'b', type: 'A', address: '2' },
|
||||||
|
{ someid: 2, name: 'c', type: 'CNAME', address: 'hello.com' },
|
||||||
|
];
|
||||||
|
const redirections = [
|
||||||
|
{ domain: `b.${DOMAIN_DOMAIN}`, destination: 'https://foobar.com' },
|
||||||
|
{ domain: `c.${DOMAIN_DOMAIN}`, destination: 'https://goobar.com' },
|
||||||
|
{ domain: `x.${DOMAIN_DOMAIN}`, destination: 'https://example.com' },
|
||||||
|
];
|
||||||
|
|
||||||
|
const mockDomainService = mockDS({ zones, redirections });
|
||||||
|
await mockDomainService.updateHosts([
|
||||||
|
{ name: 'a', type: 'CNAME', address: 'boo' },
|
||||||
|
{ name: 'b', type: 'A', address: '1' },
|
||||||
|
{ name: 'b', type: 'A', address: '2' },
|
||||||
|
{ name: 'b', type: 'A', address: '3' },
|
||||||
|
{ name: 'b', type: 'URL', address: 'https://wowow.com' },
|
||||||
|
{ name: 'c', type: 'CNAME', address: 'hello.com' },
|
||||||
|
{ name: 'c', type: 'URL', address: 'https://goobar.com' },
|
||||||
|
{ name: 'd', type: 'CNAME', address: 'helo.com' },
|
||||||
|
{ name: 'd', type: 'URL', address: 'https://hhh.com' },
|
||||||
|
{ name: 'x', type: 'URL', address: 'https://example69.com' },
|
||||||
|
]);
|
||||||
|
|
||||||
|
expect(addZone).toBeCalledTimes(2);
|
||||||
|
expect(editZone).toBeCalledTimes(1);
|
||||||
|
expect(addRedir).toBeCalledTimes(1);
|
||||||
|
expect(editRedir).toBeCalledTimes(2);
|
||||||
|
expect(getRecordCalls(addZone)).toEqual([
|
||||||
|
{ name: 'b', type: 'A', address: '3' },
|
||||||
|
{ name: 'd', type: 'CNAME', address: 'helo.com' }
|
||||||
|
]);
|
||||||
|
expect(getRecordCalls(editZone)).toEqual([
|
||||||
|
{ name: 'a', type: 'CNAME', address: 'boo' },
|
||||||
|
]);
|
||||||
|
expect(getRecordCalls(addRedir)).toEqual([
|
||||||
|
{ domain: `d.${DOMAIN_DOMAIN}`, type: 'permanent', redirect: 'https://hhh.com' },
|
||||||
|
]);
|
||||||
|
expect(getRecordCalls(editRedir)).toEqual([
|
||||||
|
{ domain: `b.${DOMAIN_DOMAIN}`, type: 'permanent', redirect: 'https://wowow.com' },
|
||||||
|
{ domain: `x.${DOMAIN_DOMAIN}`, type: 'permanent', redirect: 'https://example69.com' },
|
||||||
|
]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
Reference in new issue
Block a user