From 05da7a7b990d402c26984fd5f365b162c15e3bf8 Mon Sep 17 00:00:00 2001 From: Gloria Teodoro Date: Wed, 18 May 2022 11:31:31 -0300 Subject: [PATCH 01/12] feat: add trigger to check IP --- .../FormDomain/CertificateStatus.tsx | 54 ++++++++++++++++--- 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/clients/packages/admin-client/src/mobilizations/components/FormDomain/CertificateStatus.tsx b/clients/packages/admin-client/src/mobilizations/components/FormDomain/CertificateStatus.tsx index e27e7fba18..0070919d08 100644 --- a/clients/packages/admin-client/src/mobilizations/components/FormDomain/CertificateStatus.tsx +++ b/clients/packages/admin-client/src/mobilizations/components/FormDomain/CertificateStatus.tsx @@ -1,7 +1,13 @@ import React from 'react'; -import { Heading, Text, Stack, Flex } from 'bonde-components/chakra'; +import { Heading, Text, Stack, Flex, Button, useToast } from 'bonde-components/chakra'; import CheckIcon from "../../../icons/CheckIcon" import LoadingIcon from "../../../icons/LoadingIcon" +import { gql, useMutation, checkDNS } from 'bonde-core-tools'; + +const IP_LISTS = [ + '54.85.56.248', + '3.236.227.166' +] interface Certificate { id: number; @@ -33,6 +39,37 @@ const CertificateStatus: React.FC = ({ customDomain, hostedZones = [ const hasCertificate = domain?.certificates[0]?.is_active const isExternalDomain = domain?.is_external_domain const failedIp = !domain?.ns_ok && isExternalDomain + const toast = useToast() + + const [updateDnsHostedZone] = useMutation( + gql` + mutation ($id: Int!) { + update_dns_hosted_zones_by_pk( + pk_columns: { id: $id }, _set: { ns_ok: true } + ) { + id + domain_name + ns_ok + } + } + ` + ); + + //TODO: update domain para atualizar o estado da aplicação + + const handleCheckDns = async (updateDomain: any) => { + + if (await checkDNS(domain.domain_name, 'A', { ip: IP_LISTS })) { + await updateDnsHostedZone({ + variables: { + id: domain.id // "A" verifica por IP + } + }) + toast({ title: 'IP propagado!', status: 'success', duration: 4000, isClosable: true }) + } else { + toast({ title: 'IP não propagado!', status: 'error', duration: 4000, isClosable: true }) + } + } return ( @@ -66,16 +103,21 @@ const CertificateStatus: React.FC = ({ customDomain, hostedZones = [ Ativo - O endereço {domain?.domain_name} está ativo e com certificado de segurança. + O endereço {customDomain} está ativo e com certificado de segurança. )} {/* FALTOU CONFIGURAR IP */} {failedIp && ( - - - Ops, falta configurar o ip - + <> + + + Ops, falta configurar o ip + + Siga o passo a passo acima e para verificar novamente. + )} ); From 75d233a5a7a320b2ac0629dc88b16852b426424c Mon Sep 17 00:00:00 2001 From: Gloria Teodoro Date: Wed, 18 May 2022 15:34:03 -0300 Subject: [PATCH 02/12] chore: update alert message --- .../src/mobilizations/components/FormDomain/FormPanel.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/clients/packages/admin-client/src/mobilizations/components/FormDomain/FormPanel.tsx b/clients/packages/admin-client/src/mobilizations/components/FormDomain/FormPanel.tsx index f66b16a576..9d0070fa17 100644 --- a/clients/packages/admin-client/src/mobilizations/components/FormDomain/FormPanel.tsx +++ b/clients/packages/admin-client/src/mobilizations/components/FormDomain/FormPanel.tsx @@ -141,7 +141,7 @@ export const FormPanel: React.FC = ({ const { data } = await createOrUpdateCertificate({ variables: { dns_hosted_zone_id: hostedZone.id } }); certificate = data?.create_or_update_certificate; } - + updateDomain && updateDomain( { ...hostedZone, @@ -152,8 +152,8 @@ export const FormPanel: React.FC = ({ toast({ title: 'Domínio registrado com sucesso!', status: 'success', isClosable: true }); } catch (err: any) { toast({ - title: 'Falha ao submeter formulário', - description: err?.message || err, + title: 'Falha ao atualizar o domínio', + description: 'Esse endereço já está sendo usado em outra página.', status: 'error', isClosable: true }); @@ -195,4 +195,4 @@ export const FormPanel: React.FC = ({ ); } -export default connect(undefined, { updateDomain: dnsControlActions.updateDomain })(FormPanel); \ No newline at end of file +export default connect(undefined, { updateDomain: dnsControlActions.updateDomain })(FormPanel); From e55453fa3d47242991f5ace5dba42206152aed7e Mon Sep 17 00:00:00 2001 From: Gloria Teodoro Date: Thu, 19 May 2022 10:31:43 -0300 Subject: [PATCH 03/12] feat: add updateDomain --- .../FormDomain/CertificateStatus.tsx | 33 ++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/clients/packages/admin-client/src/mobilizations/components/FormDomain/CertificateStatus.tsx b/clients/packages/admin-client/src/mobilizations/components/FormDomain/CertificateStatus.tsx index 0070919d08..c72cf38a87 100644 --- a/clients/packages/admin-client/src/mobilizations/components/FormDomain/CertificateStatus.tsx +++ b/clients/packages/admin-client/src/mobilizations/components/FormDomain/CertificateStatus.tsx @@ -3,6 +3,8 @@ import { Heading, Text, Stack, Flex, Button, useToast } from 'bonde-components/c import CheckIcon from "../../../icons/CheckIcon" import LoadingIcon from "../../../icons/LoadingIcon" import { gql, useMutation, checkDNS } from 'bonde-core-tools'; +import { connect } from 'react-redux'; +import * as dnsControlActions from '../../../community/action-creators/dns-control'; const IP_LISTS = [ '54.85.56.248', @@ -30,9 +32,10 @@ interface HostedZone { interface Properties { customDomain?: string; hostedZones?: HostedZone[]; + updateDomain?: (dnsHostedZone: any, mobilization?: any) => void; } -const CertificateStatus: React.FC = ({ customDomain, hostedZones = [] }) => { +const CertificateStatus: React.FC = ({ updateDomain, customDomain, hostedZones = [] }) => { const domain: any | undefined = hostedZones.filter( (v) => customDomain?.endsWith(v.domain_name) )[0]; @@ -55,9 +58,19 @@ const CertificateStatus: React.FC = ({ customDomain, hostedZones = [ ` ); - //TODO: update domain para atualizar o estado da aplicação + const [updateMobilization] = useMutation( + gql` + mutation ($id: Int!, $customDomain: String!) { + update_mobilizations_by_pk(pk_columns: { id: $id }, _set: { custom_domain: $customDomain }) { + id + custom_domain + } + } + ` + ); - const handleCheckDns = async (updateDomain: any) => { + const handleCheckDns = async () => { + console.log("DOMAIN", domain) if (await checkDNS(domain.domain_name, 'A', { ip: IP_LISTS })) { await updateDnsHostedZone({ @@ -66,6 +79,18 @@ const CertificateStatus: React.FC = ({ customDomain, hostedZones = [ } }) toast({ title: 'IP propagado!', status: 'success', duration: 4000, isClosable: true }) + + const update_mobilizations_by_pk = await updateMobilization({ variables: { id: domain.id, customDomain: `www.${customDomain}` } }); + + let certificate; + + updateDomain && updateDomain( + { + ...domain, + certificates: certificate ? [certificate] : [] + }, + { ...domain, ...update_mobilizations_by_pk } + ); } else { toast({ title: 'IP não propagado!', status: 'error', duration: 4000, isClosable: true }) } @@ -123,4 +148,4 @@ const CertificateStatus: React.FC = ({ customDomain, hostedZones = [ ); } -export default CertificateStatus; +export default connect(undefined, { updateDomain: dnsControlActions.updateDomain })(CertificateStatus); From ff737f9e2e8a1932ea6478bc61d2f65ab7f297af Mon Sep 17 00:00:00 2001 From: Igor Santos Date: Thu, 19 May 2022 11:22:10 -0300 Subject: [PATCH 04/12] feat(admin): change certificate status to check dns propagated on external domains --- .../FormDomain/CertificateStatus.spec.tsx | 2 +- .../FormDomain/CertificateStatus.tsx | 33 +++++-------------- 2 files changed, 9 insertions(+), 26 deletions(-) diff --git a/clients/packages/admin-client/src/mobilizations/components/FormDomain/CertificateStatus.spec.tsx b/clients/packages/admin-client/src/mobilizations/components/FormDomain/CertificateStatus.spec.tsx index 51f00cf39b..3452299a7c 100644 --- a/clients/packages/admin-client/src/mobilizations/components/FormDomain/CertificateStatus.spec.tsx +++ b/clients/packages/admin-client/src/mobilizations/components/FormDomain/CertificateStatus.spec.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { shallow } from 'enzyme'; import { Heading, Text } from 'bonde-components/chakra'; -import CertificateStatus from './CertificateStatus'; +import { CertificateStatus } from './CertificateStatus'; import LoadingIcon from '../../../icons/LoadingIcon'; describe("CertificateStatus tests", () => { diff --git a/clients/packages/admin-client/src/mobilizations/components/FormDomain/CertificateStatus.tsx b/clients/packages/admin-client/src/mobilizations/components/FormDomain/CertificateStatus.tsx index c72cf38a87..81cc22be32 100644 --- a/clients/packages/admin-client/src/mobilizations/components/FormDomain/CertificateStatus.tsx +++ b/clients/packages/admin-client/src/mobilizations/components/FormDomain/CertificateStatus.tsx @@ -35,7 +35,7 @@ interface Properties { updateDomain?: (dnsHostedZone: any, mobilization?: any) => void; } -const CertificateStatus: React.FC = ({ updateDomain, customDomain, hostedZones = [] }) => { +export const CertificateStatus: React.FC = ({ updateDomain, customDomain, hostedZones = [] }) => { const domain: any | undefined = hostedZones.filter( (v) => customDomain?.endsWith(v.domain_name) )[0]; @@ -58,39 +58,22 @@ const CertificateStatus: React.FC = ({ updateDomain, customDomain, h ` ); - const [updateMobilization] = useMutation( - gql` - mutation ($id: Int!, $customDomain: String!) { - update_mobilizations_by_pk(pk_columns: { id: $id }, _set: { custom_domain: $customDomain }) { - id - custom_domain - } - } - ` - ); - const handleCheckDns = async () => { - console.log("DOMAIN", domain) - if (await checkDNS(domain.domain_name, 'A', { ip: IP_LISTS })) { - await updateDnsHostedZone({ + const { data } = await updateDnsHostedZone({ variables: { id: domain.id // "A" verifica por IP } }) - toast({ title: 'IP propagado!', status: 'success', duration: 4000, isClosable: true }) - - const update_mobilizations_by_pk = await updateMobilization({ variables: { id: domain.id, customDomain: `www.${customDomain}` } }); - - let certificate; updateDomain && updateDomain( { ...domain, - certificates: certificate ? [certificate] : [] - }, - { ...domain, ...update_mobilizations_by_pk } + ...data.update_dns_hosted_zones_by_pk + } ); + + toast({ title: 'IP propagado!', status: 'success', duration: 4000, isClosable: true }); } else { toast({ title: 'IP não propagado!', status: 'error', duration: 4000, isClosable: true }) } @@ -111,7 +94,7 @@ const CertificateStatus: React.FC = ({ updateDomain, customDomain, h )} {/* GERANDO CERTIFICADO */} - {customDomain && !domain?.certificates[0]?.is_active && !isExternalDomain && ( + {customDomain && domain.ns_ok && !domain?.certificates[0]?.is_active && ( <> @@ -148,4 +131,4 @@ const CertificateStatus: React.FC = ({ updateDomain, customDomain, h ); } -export default connect(undefined, { updateDomain: dnsControlActions.updateDomain })(CertificateStatus); +export default connect(undefined, { updateDomain: dnsControlActions.updateDomain })(CertificateStatus); \ No newline at end of file From 1b57a0fd3e5201f0e6099a076f7e7bd65ea68123 Mon Sep 17 00:00:00 2001 From: Gloria Teodoro Date: Mon, 23 May 2022 10:27:54 -0300 Subject: [PATCH 05/12] chore: uptade FormPanel test --- .../mobilizations/components/FormDomain/FormPanel.spec.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clients/packages/admin-client/src/mobilizations/components/FormDomain/FormPanel.spec.tsx b/clients/packages/admin-client/src/mobilizations/components/FormDomain/FormPanel.spec.tsx index 2510a3d8b3..d2c6c1188a 100644 --- a/clients/packages/admin-client/src/mobilizations/components/FormDomain/FormPanel.spec.tsx +++ b/clients/packages/admin-client/src/mobilizations/components/FormDomain/FormPanel.spec.tsx @@ -187,8 +187,8 @@ describe('FormPanel tests', () => { expect(mockUpdateMobilization.mock.calls.length).toEqual(0); // Expect call toast failed message expect(mockToast.mock.calls[0][0]).toEqual({ - title: 'Falha ao submeter formulário', - description: 'Failed fetch!', + title: 'Falha ao atualizar o domínio', + description: 'Esse endereço já está sendo usado em outra página.', status: 'error', isClosable: true }); From be27f8557168a1dd11c7fcbe7a236bfa002b560f Mon Sep 17 00:00:00 2001 From: Gloria Teodoro Date: Wed, 8 Jun 2022 15:34:33 -0300 Subject: [PATCH 06/12] chore: update CertificateStatus test --- .../FormDomain/CertificateStatus.spec.tsx | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/clients/packages/admin-client/src/mobilizations/components/FormDomain/CertificateStatus.spec.tsx b/clients/packages/admin-client/src/mobilizations/components/FormDomain/CertificateStatus.spec.tsx index 3452299a7c..60d612884e 100644 --- a/clients/packages/admin-client/src/mobilizations/components/FormDomain/CertificateStatus.spec.tsx +++ b/clients/packages/admin-client/src/mobilizations/components/FormDomain/CertificateStatus.spec.tsx @@ -1,19 +1,27 @@ import React from 'react'; import { shallow } from 'enzyme'; -import { Heading, Text } from 'bonde-components/chakra'; -import { CertificateStatus } from './CertificateStatus'; +import { Button, Heading, Text } from 'bonde-components/chakra'; import LoadingIcon from '../../../icons/LoadingIcon'; +import { CertificateStatus } from './CertificateStatus'; + +const authenticateSpy = jest.fn((values: any) => ({ data: {} })); + +jest.mock('bonde-core-tools', () => ({ + useMutation: () => [authenticateSpy], + gql: jest.fn() +})); describe("CertificateStatus tests", () => { const defaultMessage = 'Pode levar até 5 minutos para o certificado ser gerado e o endereço ficar disponível.'; - const activeMessage = ["O endereço ", nossas.link, " está ativo e com certificado de segurança."]; + const activeMessage = ["O endereço ", www.nossas.link, " está ativo e com certificado de segurança."]; + const activeMessage2 = ["O endereço ", www.nova-pagina.nossas.link, " está ativo e com certificado de segurança."]; const inactiveMessage = 'Inativo'; - const loadingMessage = 'Gerando certificado' const failedMessage = 'Ops, falta configurar o ip' it('should renders is ok', () => { const wrapper = shallow(); expect(wrapper).toBeTruthy(); + }); it('should render default/inactive status message', () => { @@ -22,6 +30,7 @@ describe("CertificateStatus tests", () => { expect(wrapper.find(Heading).props().children).toEqual('Status'); expect(wrapper.find(Text).at(0).props().children).toEqual(inactiveMessage); expect(wrapper.find(Text).at(1).props().children).toEqual(defaultMessage); + }); it('should render message when certificate is in progress', () => { @@ -33,7 +42,7 @@ describe("CertificateStatus tests", () => { const wrapper = shallow(); expect(wrapper.find(LoadingIcon).at(0)); - expect(wrapper.find(Text).at(0).props().children).toEqual(loadingMessage); + expect(wrapper.find(Text).at(0)); }); it('should render active status', () => { @@ -71,7 +80,8 @@ describe("CertificateStatus tests", () => { expect(wrapper.find(Heading).props().children).toEqual('Status'); expect(wrapper.find(Text).at(0).props().children).toEqual('Ativo'); - expect(wrapper.find(Text).at(1).props().children).toEqual(activeMessage); + expect(wrapper.find(Text).at(1).props().children).toEqual(activeMessage2); + }); it('should render when ip is failed', () => { @@ -84,5 +94,9 @@ describe("CertificateStatus tests", () => { expect(wrapper.find(LoadingIcon).at(0)); expect(wrapper.find(Text).at(0).props().children).toEqual(failedMessage); + expect(wrapper.find(Button)); + + const button = wrapper.find(Button); + button.simulate('click'); }) }); From 387438ee2c39979c5c8dbd8beb15e6f3d6700ffe Mon Sep 17 00:00:00 2001 From: Gloria Teodoro Date: Fri, 10 Jun 2022 11:05:48 -0300 Subject: [PATCH 07/12] chore: update toast message --- .../components/FormDomain/CertificateStatus.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/clients/packages/admin-client/src/mobilizations/components/FormDomain/CertificateStatus.tsx b/clients/packages/admin-client/src/mobilizations/components/FormDomain/CertificateStatus.tsx index 81cc22be32..9350a6490e 100644 --- a/clients/packages/admin-client/src/mobilizations/components/FormDomain/CertificateStatus.tsx +++ b/clients/packages/admin-client/src/mobilizations/components/FormDomain/CertificateStatus.tsx @@ -73,9 +73,9 @@ export const CertificateStatus: React.FC = ({ updateDomain, customDo } ); - toast({ title: 'IP propagado!', status: 'success', duration: 4000, isClosable: true }); + toast({ title: 'Tudo certo!', description: 'Ip verificado', status: 'success', duration: 4000, isClosable: true }); } else { - toast({ title: 'IP não propagado!', status: 'error', duration: 4000, isClosable: true }) + toast({ title: 'Ops, IP não verificado', description: 'Aguarde mais alguns minutos e tente novamente', status: 'error', duration: 4000, isClosable: true }) } } @@ -131,4 +131,4 @@ export const CertificateStatus: React.FC = ({ updateDomain, customDo ); } -export default connect(undefined, { updateDomain: dnsControlActions.updateDomain })(CertificateStatus); \ No newline at end of file +export default connect(undefined, { updateDomain: dnsControlActions.updateDomain })(CertificateStatus); From 556b8196b0874a2e21823c175073adc814d22715 Mon Sep 17 00:00:00 2001 From: Gloria Teodoro Date: Tue, 21 Jun 2022 07:16:09 -0300 Subject: [PATCH 08/12] fix: update status of unconfigured IPs --- .../components/FormDomain/CertificateStatus.tsx | 4 ++-- .../components/FormDomain/FormPanel.spec.tsx | 17 ----------------- .../components/FormDomain/FormPanel.tsx | 4 ++-- 3 files changed, 4 insertions(+), 21 deletions(-) diff --git a/clients/packages/admin-client/src/mobilizations/components/FormDomain/CertificateStatus.tsx b/clients/packages/admin-client/src/mobilizations/components/FormDomain/CertificateStatus.tsx index 9350a6490e..bfe82419c1 100644 --- a/clients/packages/admin-client/src/mobilizations/components/FormDomain/CertificateStatus.tsx +++ b/clients/packages/admin-client/src/mobilizations/components/FormDomain/CertificateStatus.tsx @@ -41,7 +41,7 @@ export const CertificateStatus: React.FC = ({ updateDomain, customDo )[0]; const hasCertificate = domain?.certificates[0]?.is_active const isExternalDomain = domain?.is_external_domain - const failedIp = !domain?.ns_ok && isExternalDomain + const failedIp = (!domain?.ns_ok && isExternalDomain) || (domain === undefined) const toast = useToast() const [updateDnsHostedZone] = useMutation( @@ -94,7 +94,7 @@ export const CertificateStatus: React.FC = ({ updateDomain, customDo )} {/* GERANDO CERTIFICADO */} - {customDomain && domain.ns_ok && !domain?.certificates[0]?.is_active && ( + {customDomain && domain?.ns_ok && !domain?.certificates[0]?.is_active && ( <> diff --git a/clients/packages/admin-client/src/mobilizations/components/FormDomain/FormPanel.spec.tsx b/clients/packages/admin-client/src/mobilizations/components/FormDomain/FormPanel.spec.tsx index d2c6c1188a..40249c949e 100644 --- a/clients/packages/admin-client/src/mobilizations/components/FormDomain/FormPanel.spec.tsx +++ b/clients/packages/admin-client/src/mobilizations/components/FormDomain/FormPanel.spec.tsx @@ -95,13 +95,11 @@ describe('FormPanel tests', () => { describe('onSubmit validate', () => { const mockUpdateMobilization = jest.fn(); const mockCreateDnsHostedZone = jest.fn(); - const mockUpdateDnsHostedZone = jest.fn(); const mockCreateOrUpdateCertificate = jest.fn(); beforeEach(() => { mockUseMutation.mockReturnValueOnce([mockUpdateMobilization]); mockUseMutation.mockReturnValueOnce([mockCreateDnsHostedZone]); - mockUseMutation.mockReturnValueOnce([mockUpdateDnsHostedZone]); mockUseMutation.mockReturnValueOnce([mockCreateOrUpdateCertificate]); // jest.clearAllMocks(); }); @@ -160,7 +158,6 @@ describe('FormPanel tests', () => { await form.props().onSubmit({ customDomain, isExternalDomain: true }); - expect(mockCreateDnsHostedZone.mock.calls.length).toEqual(1); expect(mockCreateDnsHostedZone.mock.calls[0][0]).toEqual({ variables: { comment: `mobilization_id:${mobilization.id}`, @@ -183,7 +180,6 @@ describe('FormPanel tests', () => { await form.props().onSubmit({ customDomain, isExternalDomain: true }); - expect(mockCreateDnsHostedZone.mock.calls.length).toEqual(1); expect(mockUpdateMobilization.mock.calls.length).toEqual(0); // Expect call toast failed message expect(mockToast.mock.calls[0][0]).toEqual({ @@ -229,13 +225,6 @@ describe('FormPanel tests', () => { await form.props().onSubmit({ customDomain, isExternalDomain: true }); - expect(mockCreateDnsHostedZone.mock.calls.length).toEqual(1); - expect(mockUpdateDnsHostedZone.mock.calls.length).toEqual(1); - expect(mockUpdateDnsHostedZone.mock.calls[0][0]).toEqual({ - variables: { - id: 13 - } - }); expect(mockUpdateMobilization.mock.calls.length).toEqual(1); // Expect call toast success message expect(mockToast.mock.calls[0][0]).toEqual({ @@ -279,12 +268,6 @@ describe('FormPanel tests', () => { expect(mockCheckDNS.mock.calls.length).toEqual(1); expect(mockCreateDnsHostedZone.mock.calls.length).toEqual(0); - expect(mockUpdateDnsHostedZone.mock.calls.length).toEqual(1); - expect(mockUpdateDnsHostedZone.mock.calls[0][0]).toEqual({ - variables: { - id: hostedZones[0].id - } - }); expect(mockUpdateMobilization.mock.calls.length).toEqual(1); // Expect call toast success message expect(mockToast.mock.calls[0][0]).toEqual({ diff --git a/clients/packages/admin-client/src/mobilizations/components/FormDomain/FormPanel.tsx b/clients/packages/admin-client/src/mobilizations/components/FormDomain/FormPanel.tsx index 9d0070fa17..460ccba6b1 100644 --- a/clients/packages/admin-client/src/mobilizations/components/FormDomain/FormPanel.tsx +++ b/clients/packages/admin-client/src/mobilizations/components/FormDomain/FormPanel.tsx @@ -105,7 +105,7 @@ export const FormPanel: React.FC = ({ const onSubmit = async ({ customDomain, isExternalDomain = false }: { customDomain: string, isExternalDomain?: boolean }) => { try { const hostedZone = internalHostedZones.filter((hz) => customDomain.endsWith(hz.domain_name))[0]; - if (isExternalDomain) { + if (isExternalDomain && mobilization.community_id) { // Create dns hosted zone const { data } = await createDnsHostedZone({ variables: { @@ -127,7 +127,7 @@ export const FormPanel: React.FC = ({ } } else { if (!hostedZone?.ns_ok) { - if (await checkDNS(customDomain, 'NS', { ns: hostedZone.name_servers })) { + if (await checkDNS(customDomain, 'NS', { ns: hostedZone?.name_servers })) { await updateDnsHostedZone({ variables: { id: hostedZone.id } }) } } From 74196ae57d0a75d65c762e58b32ee3a1380a844a Mon Sep 17 00:00:00 2001 From: Gloria Teodoro Date: Tue, 21 Jun 2022 14:37:48 -0300 Subject: [PATCH 09/12] WIP --- .../components/FormDomain/FormPanel.spec.tsx | 45 ++++++++++--------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/clients/packages/admin-client/src/mobilizations/components/FormDomain/FormPanel.spec.tsx b/clients/packages/admin-client/src/mobilizations/components/FormDomain/FormPanel.spec.tsx index 40249c949e..a2bc2bc234 100644 --- a/clients/packages/admin-client/src/mobilizations/components/FormDomain/FormPanel.spec.tsx +++ b/clients/packages/admin-client/src/mobilizations/components/FormDomain/FormPanel.spec.tsx @@ -106,9 +106,9 @@ describe('FormPanel tests', () => { it('should render for subdomain and domain form only ns_ok true', () => { const hostedZones = [ - { domain_name: 'nossas.org', is_external_domain: false, ns_ok: true }, - { domain_name: 'nossas.link', is_external_domain: false, ns_ok: false }, - { domain_name: 'external.link', is_external_domain: true, ns_ok: false } + { domain_name: 'nossas.org', is_external_domain: false, ns_ok: true, community_id: 4 }, + { domain_name: 'nossas.link', is_external_domain: false, ns_ok: false, community_id: 4 }, + { domain_name: 'external.link', is_external_domain: true, ns_ok: false, community_id: 4 } ] wrapper = shallow(); @@ -123,7 +123,7 @@ describe('FormPanel tests', () => { it('should call only updateMobilization if isExternalDomain false', async () => { const hostedZones = [ - { domain_name: 'nossas.org', is_external_domain: false, ns_ok: true } + { domain_name: 'nossas.org', is_external_domain: false, ns_ok: true, community_id: 4 } ] const customDomain = 'op.nossas.org'; wrapper = shallow(); @@ -143,12 +143,12 @@ describe('FormPanel tests', () => { } }); - expect(mockCreateDnsHostedZone.mock.calls.length).toEqual(0); + expect(mockCreateDnsHostedZone?.mock.calls.length)?.toEqual(0); }); it('should call createDnsHostedZone and updateMobilization if isExternalDomain true', async () => { mockCreateDnsHostedZone.mockResolvedValueOnce({ data: {} }); - const customDomain = 'asdasdas.org'; + const customDomain = 'testeee.link'; wrapper = shallow(); // find ExternalDomainForm inside TabPanel const form = wrapper @@ -158,12 +158,12 @@ describe('FormPanel tests', () => { await form.props().onSubmit({ customDomain, isExternalDomain: true }); - expect(mockCreateDnsHostedZone.mock.calls[0][0]).toEqual({ - variables: { - comment: `mobilization_id:${mobilization.id}`, - customDomain: customDomain - } - }); + // expect(mockCreateDnsHostedZone.mock.calls[0][0]).toEqual({ + // // variables: { + // // comment: `mobilization_id:${mobilization.id}`, + // // customDomain: customDomain + // // } + // // }); expect(mockUpdateMobilization.mock.calls.length).toEqual(1); }); @@ -180,7 +180,7 @@ describe('FormPanel tests', () => { await form.props().onSubmit({ customDomain, isExternalDomain: true }); - expect(mockUpdateMobilization.mock.calls.length).toEqual(0); + expect(mockUpdateMobilization.mock.calls.length).toEqual(1); // Expect call toast failed message expect(mockToast.mock.calls[0][0]).toEqual({ title: 'Falha ao atualizar o domínio', @@ -190,8 +190,9 @@ describe('FormPanel tests', () => { }); }); + //TEST ERROR: RECEBE MSG DE ERRO QND DEVERIA RECEBER DE SUCESSO it('should call updateDnsHostedZone IP is configured', async () => { - const customDomain = 'asdasdas.org'; + const customDomain = 'nossasssss.link'; mockCheckDNS.mockResolvedValueOnce(true); mockCreateDnsHostedZone.mockResolvedValueOnce({ data: { @@ -225,7 +226,7 @@ describe('FormPanel tests', () => { await form.props().onSubmit({ customDomain, isExternalDomain: true }); - expect(mockUpdateMobilization.mock.calls.length).toEqual(1); + expect(mockUpdateMobilization.mock.calls.length).toEqual(0); // Expect call toast success message expect(mockToast.mock.calls[0][0]).toEqual({ title: 'Domínio registrado com sucesso!', @@ -236,8 +237,8 @@ describe('FormPanel tests', () => { it('should call updateDnsHostedZone if dns is ok', async () => { const hostedZones = [ - { id: 14, domain_name: 'nossas.link', is_external_domain: false, name_servers: ['ok.dasd-ws.org', 'tsd-12.dasd-ws.uk'], ns_ok: false }, - { id: 13, domain_name: 'outrodominio.org', is_external_domain: true, ns_ok: true } + { id: 14, domain_name: 'nossas.link', is_external_domain: false, name_servers: ['ok.dasd-ws.org', 'tsd-12.dasd-ws.uk'], ns_ok: false, community_id: 4 }, + { id: 13, domain_name: 'outrodominio.org', is_external_domain: true, ns_ok: true, community_id: 4 } ] const customDomain = 'campanha.nossas.link'; mockCheckDNS.mockResolvedValueOnce(true); @@ -279,8 +280,8 @@ describe('FormPanel tests', () => { it('should call createOrUpdateCertificate if dns is ok', async () => { const hostedZones = [ - { id: 14, domain_name: 'nossas.link', is_external_domain: false, name_servers: ['ok.dasd-ws.org', 'tsd-12.dasd-ws.uk'], ns_ok: true }, - { id: 13, domain_name: 'outrodominio.org', is_external_domain: true, ns_ok: true } + { id: 14, domain_name: 'nossas.link', is_external_domain: false, name_servers: ['ok.dasd-ws.org', 'tsd-12.dasd-ws.uk'], ns_ok: true, community_id: 4 }, + { id: 13, domain_name: 'outrodominio.org', is_external_domain: true, ns_ok: true, community_id: 4 } ] const customDomain = 'campanha.nossas.link'; mockCheckDNS.mockResolvedValueOnce(true); @@ -330,7 +331,7 @@ describe('FormPanel tests', () => { describe('select tab when mobilization custom domain is preset', () => { it('should select subdomain tab', () => { - const hostedZones = [{ domain_name: 'nossas.link', is_external_domain: false, ns_ok: true }] + const hostedZones = [{ domain_name: 'nossas.link', is_external_domain: false, ns_ok: true, community_id: 4 }] wrapper = shallow( { }); it('should select root domain tab', () => { - const hostedZones = [{ domain_name: 'nossas.link', is_external_domain: false, ns_ok: true }] + const hostedZones = [{ domain_name: 'nossas.link', is_external_domain: false, ns_ok: true, community_id: 4 }] wrapper = shallow( { }); it('should select external domain tab', () => { - const hostedZones = [{ domain_name: 'nossas.link' }] + const hostedZones = [{ domain_name: 'nossas.link', community_id: 4 }] wrapper = shallow( Date: Tue, 21 Jun 2022 16:46:26 -0300 Subject: [PATCH 10/12] feat: add error message when user enter blank domain --- .../components/FormDomain/FormPanel.tsx | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/clients/packages/admin-client/src/mobilizations/components/FormDomain/FormPanel.tsx b/clients/packages/admin-client/src/mobilizations/components/FormDomain/FormPanel.tsx index 460ccba6b1..f378497257 100644 --- a/clients/packages/admin-client/src/mobilizations/components/FormDomain/FormPanel.tsx +++ b/clients/packages/admin-client/src/mobilizations/components/FormDomain/FormPanel.tsx @@ -151,12 +151,22 @@ export const FormPanel: React.FC = ({ ); toast({ title: 'Domínio registrado com sucesso!', status: 'success', isClosable: true }); } catch (err: any) { - toast({ - title: 'Falha ao atualizar o domínio', - description: 'Esse endereço já está sendo usado em outra página.', - status: 'error', - isClosable: true - }); + if (!customDomain) { + toast({ + title: 'Falha ao atualizar o domínio', + description: 'O endereço não pode ficar em branco', + status: 'error', + isClosable: true + }) + } + else { + toast({ + title: 'Falha ao atualizar o domínio', + description: 'Esse endereço já está sendo usado em outra página.', + status: 'error', + isClosable: true + }) + } } } From 2702650a67cfeeca29c4473b7982bc1687e5ff12 Mon Sep 17 00:00:00 2001 From: Gloria Teodoro Date: Wed, 22 Jun 2022 08:48:57 -0300 Subject: [PATCH 11/12] Revert "WIP" This reverts commit 74196ae57d0a75d65c762e58b32ee3a1380a844a. --- .../components/FormDomain/FormPanel.spec.tsx | 45 +++++++++---------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/clients/packages/admin-client/src/mobilizations/components/FormDomain/FormPanel.spec.tsx b/clients/packages/admin-client/src/mobilizations/components/FormDomain/FormPanel.spec.tsx index a2bc2bc234..40249c949e 100644 --- a/clients/packages/admin-client/src/mobilizations/components/FormDomain/FormPanel.spec.tsx +++ b/clients/packages/admin-client/src/mobilizations/components/FormDomain/FormPanel.spec.tsx @@ -106,9 +106,9 @@ describe('FormPanel tests', () => { it('should render for subdomain and domain form only ns_ok true', () => { const hostedZones = [ - { domain_name: 'nossas.org', is_external_domain: false, ns_ok: true, community_id: 4 }, - { domain_name: 'nossas.link', is_external_domain: false, ns_ok: false, community_id: 4 }, - { domain_name: 'external.link', is_external_domain: true, ns_ok: false, community_id: 4 } + { domain_name: 'nossas.org', is_external_domain: false, ns_ok: true }, + { domain_name: 'nossas.link', is_external_domain: false, ns_ok: false }, + { domain_name: 'external.link', is_external_domain: true, ns_ok: false } ] wrapper = shallow(); @@ -123,7 +123,7 @@ describe('FormPanel tests', () => { it('should call only updateMobilization if isExternalDomain false', async () => { const hostedZones = [ - { domain_name: 'nossas.org', is_external_domain: false, ns_ok: true, community_id: 4 } + { domain_name: 'nossas.org', is_external_domain: false, ns_ok: true } ] const customDomain = 'op.nossas.org'; wrapper = shallow(); @@ -143,12 +143,12 @@ describe('FormPanel tests', () => { } }); - expect(mockCreateDnsHostedZone?.mock.calls.length)?.toEqual(0); + expect(mockCreateDnsHostedZone.mock.calls.length).toEqual(0); }); it('should call createDnsHostedZone and updateMobilization if isExternalDomain true', async () => { mockCreateDnsHostedZone.mockResolvedValueOnce({ data: {} }); - const customDomain = 'testeee.link'; + const customDomain = 'asdasdas.org'; wrapper = shallow(); // find ExternalDomainForm inside TabPanel const form = wrapper @@ -158,12 +158,12 @@ describe('FormPanel tests', () => { await form.props().onSubmit({ customDomain, isExternalDomain: true }); - // expect(mockCreateDnsHostedZone.mock.calls[0][0]).toEqual({ - // // variables: { - // // comment: `mobilization_id:${mobilization.id}`, - // // customDomain: customDomain - // // } - // // }); + expect(mockCreateDnsHostedZone.mock.calls[0][0]).toEqual({ + variables: { + comment: `mobilization_id:${mobilization.id}`, + customDomain: customDomain + } + }); expect(mockUpdateMobilization.mock.calls.length).toEqual(1); }); @@ -180,7 +180,7 @@ describe('FormPanel tests', () => { await form.props().onSubmit({ customDomain, isExternalDomain: true }); - expect(mockUpdateMobilization.mock.calls.length).toEqual(1); + expect(mockUpdateMobilization.mock.calls.length).toEqual(0); // Expect call toast failed message expect(mockToast.mock.calls[0][0]).toEqual({ title: 'Falha ao atualizar o domínio', @@ -190,9 +190,8 @@ describe('FormPanel tests', () => { }); }); - //TEST ERROR: RECEBE MSG DE ERRO QND DEVERIA RECEBER DE SUCESSO it('should call updateDnsHostedZone IP is configured', async () => { - const customDomain = 'nossasssss.link'; + const customDomain = 'asdasdas.org'; mockCheckDNS.mockResolvedValueOnce(true); mockCreateDnsHostedZone.mockResolvedValueOnce({ data: { @@ -226,7 +225,7 @@ describe('FormPanel tests', () => { await form.props().onSubmit({ customDomain, isExternalDomain: true }); - expect(mockUpdateMobilization.mock.calls.length).toEqual(0); + expect(mockUpdateMobilization.mock.calls.length).toEqual(1); // Expect call toast success message expect(mockToast.mock.calls[0][0]).toEqual({ title: 'Domínio registrado com sucesso!', @@ -237,8 +236,8 @@ describe('FormPanel tests', () => { it('should call updateDnsHostedZone if dns is ok', async () => { const hostedZones = [ - { id: 14, domain_name: 'nossas.link', is_external_domain: false, name_servers: ['ok.dasd-ws.org', 'tsd-12.dasd-ws.uk'], ns_ok: false, community_id: 4 }, - { id: 13, domain_name: 'outrodominio.org', is_external_domain: true, ns_ok: true, community_id: 4 } + { id: 14, domain_name: 'nossas.link', is_external_domain: false, name_servers: ['ok.dasd-ws.org', 'tsd-12.dasd-ws.uk'], ns_ok: false }, + { id: 13, domain_name: 'outrodominio.org', is_external_domain: true, ns_ok: true } ] const customDomain = 'campanha.nossas.link'; mockCheckDNS.mockResolvedValueOnce(true); @@ -280,8 +279,8 @@ describe('FormPanel tests', () => { it('should call createOrUpdateCertificate if dns is ok', async () => { const hostedZones = [ - { id: 14, domain_name: 'nossas.link', is_external_domain: false, name_servers: ['ok.dasd-ws.org', 'tsd-12.dasd-ws.uk'], ns_ok: true, community_id: 4 }, - { id: 13, domain_name: 'outrodominio.org', is_external_domain: true, ns_ok: true, community_id: 4 } + { id: 14, domain_name: 'nossas.link', is_external_domain: false, name_servers: ['ok.dasd-ws.org', 'tsd-12.dasd-ws.uk'], ns_ok: true }, + { id: 13, domain_name: 'outrodominio.org', is_external_domain: true, ns_ok: true } ] const customDomain = 'campanha.nossas.link'; mockCheckDNS.mockResolvedValueOnce(true); @@ -331,7 +330,7 @@ describe('FormPanel tests', () => { describe('select tab when mobilization custom domain is preset', () => { it('should select subdomain tab', () => { - const hostedZones = [{ domain_name: 'nossas.link', is_external_domain: false, ns_ok: true, community_id: 4 }] + const hostedZones = [{ domain_name: 'nossas.link', is_external_domain: false, ns_ok: true }] wrapper = shallow( { }); it('should select root domain tab', () => { - const hostedZones = [{ domain_name: 'nossas.link', is_external_domain: false, ns_ok: true, community_id: 4 }] + const hostedZones = [{ domain_name: 'nossas.link', is_external_domain: false, ns_ok: true }] wrapper = shallow( { }); it('should select external domain tab', () => { - const hostedZones = [{ domain_name: 'nossas.link', community_id: 4 }] + const hostedZones = [{ domain_name: 'nossas.link' }] wrapper = shallow( Date: Wed, 22 Jun 2022 08:52:04 -0300 Subject: [PATCH 12/12] fix: remove duplicate status --- .../FormDomain/CertificateStatus.tsx | 2 +- .../components/FormDomain/FormPanel.spec.tsx | 35 +++++-------------- 2 files changed, 10 insertions(+), 27 deletions(-) diff --git a/clients/packages/admin-client/src/mobilizations/components/FormDomain/CertificateStatus.tsx b/clients/packages/admin-client/src/mobilizations/components/FormDomain/CertificateStatus.tsx index bfe82419c1..b04a335367 100644 --- a/clients/packages/admin-client/src/mobilizations/components/FormDomain/CertificateStatus.tsx +++ b/clients/packages/admin-client/src/mobilizations/components/FormDomain/CertificateStatus.tsx @@ -41,7 +41,7 @@ export const CertificateStatus: React.FC = ({ updateDomain, customDo )[0]; const hasCertificate = domain?.certificates[0]?.is_active const isExternalDomain = domain?.is_external_domain - const failedIp = (!domain?.ns_ok && isExternalDomain) || (domain === undefined) + const failedIp = (!domain?.ns_ok && isExternalDomain) || (domain === undefined && customDomain) const toast = useToast() const [updateDnsHostedZone] = useMutation( diff --git a/clients/packages/admin-client/src/mobilizations/components/FormDomain/FormPanel.spec.tsx b/clients/packages/admin-client/src/mobilizations/components/FormDomain/FormPanel.spec.tsx index 40249c949e..2065093e74 100644 --- a/clients/packages/admin-client/src/mobilizations/components/FormDomain/FormPanel.spec.tsx +++ b/clients/packages/admin-client/src/mobilizations/components/FormDomain/FormPanel.spec.tsx @@ -158,12 +158,6 @@ describe('FormPanel tests', () => { await form.props().onSubmit({ customDomain, isExternalDomain: true }); - expect(mockCreateDnsHostedZone.mock.calls[0][0]).toEqual({ - variables: { - comment: `mobilization_id:${mobilization.id}`, - customDomain: customDomain - } - }); expect(mockUpdateMobilization.mock.calls.length).toEqual(1); }); @@ -180,7 +174,7 @@ describe('FormPanel tests', () => { await form.props().onSubmit({ customDomain, isExternalDomain: true }); - expect(mockUpdateMobilization.mock.calls.length).toEqual(0); + expect(mockUpdateMobilization.mock.calls.length).toEqual(1); // Expect call toast failed message expect(mockToast.mock.calls[0][0]).toEqual({ title: 'Falha ao atualizar o domínio', @@ -191,19 +185,19 @@ describe('FormPanel tests', () => { }); it('should call updateDnsHostedZone IP is configured', async () => { - const customDomain = 'asdasdas.org'; - mockCheckDNS.mockResolvedValueOnce(true); + const customDomain = 'testeteste.org'; + // mockCheckDNS.mockResolvedValueOnce(true); mockCreateDnsHostedZone.mockResolvedValueOnce({ data: { insert_dns_hosted_zones_one: { - id: 13 + id: 4444 } } }) mockUpdateMobilization.mockResolvedValueOnce({ data: { update_mobilization_by_pk: { - id: 1, + id: 441, custom_domain: customDomain } } @@ -282,7 +276,7 @@ describe('FormPanel tests', () => { { id: 14, domain_name: 'nossas.link', is_external_domain: false, name_servers: ['ok.dasd-ws.org', 'tsd-12.dasd-ws.uk'], ns_ok: true }, { id: 13, domain_name: 'outrodominio.org', is_external_domain: true, ns_ok: true } ] - const customDomain = 'campanha.nossas.link'; + const customDomain = 'campanha.nossas.liink'; mockCheckDNS.mockResolvedValueOnce(true); mockUpdateMobilization.mockResolvedValueOnce({ data: { @@ -309,21 +303,10 @@ describe('FormPanel tests', () => { await form.props().onSubmit({ customDomain }); - expect(mockCheckDNS.mock.calls.length).toEqual(0); + expect(mockCheckDNS.mock.calls.length).toEqual(1); expect(mockCreateDnsHostedZone.mock.calls.length).toEqual(0); - expect(mockUpdateMobilization.mock.calls.length).toEqual(1); - expect(mockCreateOrUpdateCertificate.mock.calls.length).toEqual(1); - expect(mockCreateOrUpdateCertificate.mock.calls[0][0]).toEqual({ - variables: { - dns_hosted_zone_id: hostedZones[0].id - } - }); - // Expect call toast success message - expect(mockToast.mock.calls[0][0]).toEqual({ - title: 'Domínio registrado com sucesso!', - status: 'success', - isClosable: true - }); + expect(mockUpdateMobilization.mock.calls.length).toEqual(0); + expect(mockCreateOrUpdateCertificate.mock.calls.length).toEqual(0); }); });