diff --git a/asaas/account_test.go b/asaas/account_test.go index a2971d9..dd51883 100644 --- a/asaas/account_test.go +++ b/asaas/account_test.go @@ -7,7 +7,7 @@ import ( "time" ) -func TestAccountSaveInvoiceCustomizationSuccess(t *testing.T) { +func TestAccountSaveInvoiceCustomization(t *testing.T) { accessToken := getEnvValue(EnvAccessTokenSecondary) assertFatalStringBlank(t, accessToken) f, err := os.Open(getEnvValue(EnvImageName)) @@ -25,13 +25,7 @@ func TestAccountSaveInvoiceCustomizationSuccess(t *testing.T) { assertResponseSuccess(t, resp, errAsaas) } -func TestAccountSaveInvoiceCustomizationError(t *testing.T) { - nAccount := NewAccount(EnvSandbox, "") - resp, err := nAccount.SaveInvoiceCustomization(context.TODO(), SaveInvoiceCustomizationRequest{}) - assertResponseFailure(t, resp, err) -} - -func TestAccountUpdateSuccess(t *testing.T) { +func TestAccountUpdate(t *testing.T) { accessToken := getEnvValue(EnvAccessTokenSecondary) assertFatalStringBlank(t, accessToken) ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second) @@ -55,13 +49,7 @@ func TestAccountUpdateSuccess(t *testing.T) { assertResponseSuccess(t, resp, errAsaas) } -func TestAccountUpdateError(t *testing.T) { - nAccount := NewAccount(EnvSandbox, "") - resp, err := nAccount.Update(context.TODO(), UpdateAccountRequest{}) - assertResponseFailure(t, resp, err) -} - -func TestAccountDeleteWhiteLabelSubaccountSuccess(t *testing.T) { +func TestAccountDeleteWhiteLabelSubaccount(t *testing.T) { accessToken := getEnvValue(EnvAccessTokenSecondary) assertFatalStringBlank(t, accessToken) ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second) @@ -73,13 +61,7 @@ func TestAccountDeleteWhiteLabelSubaccountSuccess(t *testing.T) { assertResponseSuccess(t, resp, errAsaas) } -func TestAccountDeleteWhiteLabelSubaccountError(t *testing.T) { - nAccount := NewAccount(EnvSandbox, "") - resp, err := nAccount.DeleteWhiteLabelSubaccount(context.TODO(), DeleteWhiteLabelSubaccountRequest{}) - assertResponseFailure(t, resp, err) -} - -func TestAccountGetSuccess(t *testing.T) { +func TestAccountGet(t *testing.T) { accessToken := getEnvValue(EnvAccessTokenSecondary) assertFatalStringBlank(t, accessToken) ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second) @@ -89,13 +71,7 @@ func TestAccountGetSuccess(t *testing.T) { assertResponseSuccess(t, resp, errAsaas) } -func TestAccountGetError(t *testing.T) { - nAccount := NewAccount(EnvSandbox, "") - resp, errAsaas := nAccount.Get(context.TODO()) - assertResponseFailure(t, resp, errAsaas) -} - -func TestAccountGetRegistrationStatusSuccess(t *testing.T) { +func TestAccountGetRegistrationStatus(t *testing.T) { accessToken := getEnvValue(EnvAccessTokenSecondary) assertFatalStringBlank(t, accessToken) ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second) @@ -105,13 +81,7 @@ func TestAccountGetRegistrationStatusSuccess(t *testing.T) { assertResponseSuccess(t, resp, errAsaas) } -func TestAccountGetRegistrationStatusError(t *testing.T) { - nAccount := NewAccount(EnvSandbox, "") - resp, errAsaas := nAccount.Get(context.TODO()) - assertResponseFailure(t, resp, errAsaas) -} - -func TestAccountGetBankInfoSuccess(t *testing.T) { +func TestAccountGetBankInfo(t *testing.T) { accessToken := getEnvValue(EnvAccessTokenSecondary) assertFatalStringBlank(t, accessToken) ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second) @@ -121,13 +91,7 @@ func TestAccountGetBankInfoSuccess(t *testing.T) { assertResponseSuccess(t, resp, errAsaas) } -func TestAccountGetBankInfoError(t *testing.T) { - nAccount := NewAccount(EnvSandbox, "") - resp, errAsaas := nAccount.GetBankInfo(context.TODO()) - assertResponseFailure(t, resp, errAsaas) -} - -func TestAccountGetFeesSuccess(t *testing.T) { +func TestAccountGetFees(t *testing.T) { accessToken := getEnvValue(EnvAccessTokenSecondary) assertFatalStringBlank(t, accessToken) ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second) @@ -137,13 +101,7 @@ func TestAccountGetFeesSuccess(t *testing.T) { assertResponseSuccess(t, resp, errAsaas) } -func TestAccountGetFeesError(t *testing.T) { - nAccount := NewAccount(EnvSandbox, "") - resp, errAsaas := nAccount.GetFees(context.TODO()) - assertResponseFailure(t, resp, errAsaas) -} - -func TestAccountGetWalletsSuccess(t *testing.T) { +func TestAccountGetWallets(t *testing.T) { accessToken := getEnvValue(EnvAccessTokenSecondary) assertFatalStringBlank(t, accessToken) ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second) @@ -153,13 +111,7 @@ func TestAccountGetWalletsSuccess(t *testing.T) { assertResponseSuccess(t, resp, errAsaas) } -func TestAccountGetWalletsError(t *testing.T) { - nAccount := NewAccount(EnvSandbox, "") - resp, errAsaas := nAccount.GetWallets(context.TODO()) - assertResponseFailure(t, resp, errAsaas) -} - -func TestAccountGetBalanceSuccess(t *testing.T) { +func TestAccountGetBalance(t *testing.T) { accessToken := getEnvValue(EnvAccessTokenSecondary) assertFatalStringBlank(t, accessToken) ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second) @@ -169,13 +121,7 @@ func TestAccountGetBalanceSuccess(t *testing.T) { assertResponseSuccess(t, resp, errAsaas) } -func TestAccountGetBalanceError(t *testing.T) { - nAccount := NewAccount(EnvSandbox, "") - resp, errAsaas := nAccount.GetWallets(context.TODO()) - assertResponseFailure(t, resp, errAsaas) -} - -func TestAccountGetAccountStatementSuccess(t *testing.T) { +func TestAccountGetAccountStatement(t *testing.T) { accessToken := getEnvValue(EnvAccessTokenSecondary) assertFatalStringBlank(t, accessToken) ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second) @@ -191,13 +137,7 @@ func TestAccountGetAccountStatementSuccess(t *testing.T) { assertResponseSuccess(t, resp, errAsaas) } -func TestAccountGetAccountStatementError(t *testing.T) { - nAccount := NewAccount(EnvSandbox, "") - resp, errAsaas := nAccount.GetAccountStatement(context.TODO(), GetAccountStatementRequest{}) - assertResponseFailure(t, resp, errAsaas) -} - -func TestAccountGetPaymentStatisticSuccess(t *testing.T) { +func TestAccountGetPaymentStatistic(t *testing.T) { accessToken := getEnvValue(EnvAccessTokenSecondary) assertFatalStringBlank(t, accessToken) ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second) @@ -219,13 +159,7 @@ func TestAccountGetPaymentStatisticSuccess(t *testing.T) { assertResponseSuccess(t, resp, errAsaas) } -func TestAccountGetPaymentStatisticError(t *testing.T) { - nAccount := NewAccount(EnvSandbox, "") - resp, errAsaas := nAccount.GetPaymentStatistic(context.TODO(), GetPaymentStatisticRequest{}) - assertResponseFailure(t, resp, errAsaas) -} - -func TestAccountGetSplitStatisticSuccess(t *testing.T) { +func TestAccountGetSplitStatistic(t *testing.T) { accessToken := getEnvValue(EnvAccessTokenSecondary) assertFatalStringBlank(t, accessToken) ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second) @@ -235,13 +169,7 @@ func TestAccountGetSplitStatisticSuccess(t *testing.T) { assertResponseSuccess(t, resp, errAsaas) } -func TestAccountGetSplitStatisticError(t *testing.T) { - nAccount := NewAccount(EnvSandbox, "") - resp, errAsaas := nAccount.GetSplitStatistic(context.TODO()) - assertResponseFailure(t, resp, errAsaas) -} - -func TestAccountGetInvoiceCustomizationSuccess(t *testing.T) { +func TestAccountGetInvoiceCustomization(t *testing.T) { accessToken := getEnvValue(EnvAccessTokenSecondary) assertFatalStringBlank(t, accessToken) ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second) @@ -250,9 +178,3 @@ func TestAccountGetInvoiceCustomizationSuccess(t *testing.T) { resp, errAsaas := nAccount.GetInvoiceCustomization(ctx) assertResponseSuccess(t, resp, errAsaas) } - -func TestAccountGetInvoiceCustomizationError(t *testing.T) { - nAccount := NewAccount(EnvSandbox, "") - resp, errAsaas := nAccount.GetInvoiceCustomization(context.TODO()) - assertResponseFailure(t, resp, errAsaas) -} diff --git a/asaas/anticipation_test.go b/asaas/anticipation_test.go index 84163d2..c1d0217 100644 --- a/asaas/anticipation_test.go +++ b/asaas/anticipation_test.go @@ -6,7 +6,7 @@ import ( "time" ) -func TestAnticipationSimulateSuccess(t *testing.T) { +func TestAnticipationSimulate(t *testing.T) { accessToken := getEnvValue(EnvAccessToken) assertFatalStringBlank(t, accessToken) initCreditCardCharge(true, false) @@ -22,13 +22,7 @@ func TestAnticipationSimulateSuccess(t *testing.T) { assertResponseSuccess(t, resp, errAsaas) } -func TestAnticipationSimulateError(t *testing.T) { - nAnticipation := NewAnticipation(EnvSandbox, "") - resp, err := nAnticipation.Simulate(context.TODO(), AnticipationSimulateRequest{}) - assertResponseFailure(t, resp, err) -} - -func TestAnticipationRequestSuccess(t *testing.T) { +func TestAnticipationRequest(t *testing.T) { accessToken := getEnvValue(EnvAccessToken) assertFatalStringBlank(t, accessToken) initCreditCardCharge(true, false) @@ -45,13 +39,7 @@ func TestAnticipationRequestSuccess(t *testing.T) { assertResponseSuccess(t, resp, errAsaas) } -func TestAnticipationRequestError(t *testing.T) { - nAnticipation := NewAnticipation(EnvSandbox, "") - resp, err := nAnticipation.Request(context.TODO(), AnticipationRequest{}) - assertResponseFailure(t, resp, err) -} - -func TestAnticipationAgreementSignSuccess(t *testing.T) { +func TestAnticipationAgreementSign(t *testing.T) { accessToken := getEnvValue(EnvAccessToken) assertFatalStringBlank(t, accessToken) ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second) @@ -63,13 +51,7 @@ func TestAnticipationAgreementSignSuccess(t *testing.T) { assertResponseSuccess(t, resp, errAsaas) } -func TestAnticipationAgreementSignError(t *testing.T) { - nAnticipation := NewAnticipation(EnvSandbox, "") - resp, err := nAnticipation.AgreementSign(context.TODO(), AgreementSignRequest{}) - assertResponseFailure(t, resp, err) -} - -func TestAnticipationGetByIdSuccess(t *testing.T) { +func TestAnticipationGetById(t *testing.T) { accessToken := getEnvValue(EnvAccessToken) assertFatalStringBlank(t, accessToken) initAnticipation() @@ -81,13 +63,7 @@ func TestAnticipationGetByIdSuccess(t *testing.T) { assertResponseSuccess(t, resp, errAsaas) } -func TestAnticipationGetByIdError(t *testing.T) { - nAnticipation := NewAnticipation(EnvSandbox, "") - resp, err := nAnticipation.GetById(context.TODO(), "") - assertResponseFailure(t, resp, err) -} - -func TestAnticipationGetLimitsSuccess(t *testing.T) { +func TestAnticipationGetLimits(t *testing.T) { accessToken := getEnvValue(EnvAccessToken) assertFatalStringBlank(t, accessToken) ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second) @@ -97,13 +73,7 @@ func TestAnticipationGetLimitsSuccess(t *testing.T) { assertResponseSuccess(t, resp, errAsaas) } -func TestAnticipationGetLimitsError(t *testing.T) { - nAnticipation := NewAnticipation(EnvSandbox, "") - resp, errAsaas := nAnticipation.GetLimits(context.TODO()) - assertResponseFailure(t, resp, errAsaas) -} - -func TestAnticipationGetAllSuccess(t *testing.T) { +func TestAnticipationGetAll(t *testing.T) { accessToken := getEnvValue(EnvAccessToken) assertFatalStringBlank(t, accessToken) ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second) @@ -118,9 +88,3 @@ func TestAnticipationGetAllSuccess(t *testing.T) { }) assertResponseSuccess(t, resp, errAsaas) } - -func TestAnticipationGetAllError(t *testing.T) { - nAnticipation := NewAnticipation(EnvSandbox, "") - resp, errAsaas := nAnticipation.GetAll(context.TODO(), GetAllAnticipationsRequest{}) - assertResponseFailure(t, resp, errAsaas) -} diff --git a/asaas/bill_payment_test.go b/asaas/bill_payment_test.go index 622c87c..71cd26e 100644 --- a/asaas/bill_payment_test.go +++ b/asaas/bill_payment_test.go @@ -6,7 +6,7 @@ import ( "time" ) -func TestBillPaymentSimulateSuccess(t *testing.T) { +func TestBillPaymentSimulate(t *testing.T) { accessToken := getEnvValue(EnvAccessToken) assertFatalStringBlank(t, accessToken) identificationField := getEnvValue(EnvChargeIdentificationField) @@ -21,13 +21,7 @@ func TestBillPaymentSimulateSuccess(t *testing.T) { assertResponseSuccess(t, resp, errAsaas) } -func TestBillPaymentSimulateError(t *testing.T) { - nBillPayment := NewBillPayment(EnvSandbox, "") - resp, err := nBillPayment.Create(context.TODO(), CreateBillPaymentRequest{}) - assertResponseFailure(t, resp, err) -} - -func TestBillPaymentCreateSuccess(t *testing.T) { +func TestBillPaymentCreate(t *testing.T) { accessToken := getEnvValue(EnvAccessToken) assertFatalStringBlank(t, accessToken) identificationField := getEnvValue(EnvChargeIdentificationField) @@ -48,13 +42,7 @@ func TestBillPaymentCreateSuccess(t *testing.T) { assertResponseSuccess(t, resp, errAsaas) } -func TestBillPaymentCreateError(t *testing.T) { - nBillPayment := NewBillPayment(EnvSandbox, "") - resp, err := nBillPayment.Create(context.TODO(), CreateBillPaymentRequest{}) - assertResponseFailure(t, resp, err) -} - -func TestBillPaymentCancelByIdSuccess(t *testing.T) { +func TestBillPaymentCancelById(t *testing.T) { accessToken := getEnvValue(EnvAccessToken) assertFatalStringBlank(t, accessToken) initBillPayment() @@ -67,13 +55,7 @@ func TestBillPaymentCancelByIdSuccess(t *testing.T) { assertResponseSuccess(t, resp, errAsaas) } -func TestBillPaymentCancelByIdError(t *testing.T) { - nBillPayment := NewBillPayment(EnvSandbox, "") - resp, errAsaas := nBillPayment.CancelById(context.TODO(), "") - assertResponseFailure(t, resp, errAsaas) -} - -func TestBillPaymentGetByIdSuccess(t *testing.T) { +func TestBillPaymentGetById(t *testing.T) { accessToken := getEnvValue(EnvAccessToken) assertFatalStringBlank(t, accessToken) initBillPayment() @@ -86,13 +68,7 @@ func TestBillPaymentGetByIdSuccess(t *testing.T) { assertResponseSuccess(t, resp, errAsaas) } -func TestBillPaymentGetIdError(t *testing.T) { - nBillPayment := NewBillPayment(EnvSandbox, "") - resp, errAsaas := nBillPayment.GetById(context.TODO(), "") - assertResponseFailure(t, resp, errAsaas) -} - -func TestBillPaymentGetAllSuccess(t *testing.T) { +func TestBillPaymentGetAll(t *testing.T) { accessToken := getEnvValue(EnvAccessToken) assertFatalStringBlank(t, accessToken) initBillPayment() @@ -102,9 +78,3 @@ func TestBillPaymentGetAllSuccess(t *testing.T) { resp, errAsaas := nBillPayment.GetAll(ctx, PageableDefaultRequest{}) assertResponseSuccess(t, resp, errAsaas) } - -func TestBillPaymentGetAllError(t *testing.T) { - nBillPayment := NewBillPayment(EnvSandbox, "") - resp, errAsaas := nBillPayment.GetAll(context.TODO(), PageableDefaultRequest{}) - assertResponseFailure(t, resp, errAsaas) -} diff --git a/asaas/charge_test.go b/asaas/charge_test.go index ef92db4..8981e42 100644 --- a/asaas/charge_test.go +++ b/asaas/charge_test.go @@ -7,7 +7,7 @@ import ( "time" ) -func TestChangeCreateSuccess(t *testing.T) { +func TestChangeCreate(t *testing.T) { accessToken := getEnvValue(EnvAccessToken) assertFatalStringBlank(t, accessToken) initCustomer() @@ -40,13 +40,7 @@ func TestChangeCreateSuccess(t *testing.T) { assertResponseSuccess(t, resp, err) } -func TestChargeCreateError(t *testing.T) { - nCharge := NewCharge(EnvSandbox, "") - resp, err := nCharge.Create(context.TODO(), CreateChargeRequest{}) - assertResponseFailure(t, resp, err) -} - -func TestChangePayWithCreditCardSuccess(t *testing.T) { +func TestChangePayWithCreditCard(t *testing.T) { accessToken := getEnvValue(EnvAccessToken) assertFatalStringBlank(t, accessToken) initUndefinedCharge() @@ -65,13 +59,7 @@ func TestChangePayWithCreditCardSuccess(t *testing.T) { assertResponseSuccess(t, resp, err) } -func TestChargePayWithCreditCardError(t *testing.T) { - nCharge := NewCharge(EnvSandbox, "") - resp, err := nCharge.PayWithCreditCard(context.TODO(), "", CreditCardRequest{}) - assertResponseFailure(t, resp, err) -} - -func TestChangeUpdateByIdSuccess(t *testing.T) { +func TestChangeUpdateById(t *testing.T) { accessToken := getEnvValue(EnvAccessToken) assertFatalStringBlank(t, accessToken) initUndefinedCharge() @@ -90,13 +78,7 @@ func TestChangeUpdateByIdSuccess(t *testing.T) { assertResponseSuccess(t, resp, err) } -func TestChargeUpdateByIdError(t *testing.T) { - nCharge := NewCharge(EnvSandbox, "") - resp, err := nCharge.UpdateById(context.TODO(), "", UpdateChargeRequest{}) - assertResponseFailure(t, resp, err) -} - -func TestChangeDeleteByIdSuccess(t *testing.T) { +func TestChangeDeleteById(t *testing.T) { accessToken := getEnvValue(EnvAccessToken) assertFatalStringBlank(t, accessToken) initUndefinedCharge() @@ -109,13 +91,7 @@ func TestChangeDeleteByIdSuccess(t *testing.T) { assertResponseSuccess(t, resp, err) } -func TestChargeDeleteByIdError(t *testing.T) { - nCharge := NewCharge(EnvSandbox, "") - resp, err := nCharge.DeleteById(context.TODO(), "") - assertResponseFailure(t, resp, err) -} - -func TestChangeRestoreByIdSuccess(t *testing.T) { +func TestChangeRestoreById(t *testing.T) { accessToken := getEnvValue(EnvAccessToken) assertFatalStringBlank(t, accessToken) initChargeDeleted() @@ -128,13 +104,7 @@ func TestChangeRestoreByIdSuccess(t *testing.T) { assertResponseSuccess(t, resp, err) } -func TestChargeRestoreByIdError(t *testing.T) { - nCharge := NewCharge(EnvSandbox, "") - resp, err := nCharge.RestoreById(context.TODO(), "") - assertResponseFailure(t, resp, err) -} - -func TestChangeRefundByIdSuccess(t *testing.T) { +func TestChangeRefundById(t *testing.T) { accessToken := getEnvValue(EnvAccessToken) assertFatalStringBlank(t, accessToken) initCreditCardCharge(true, false) @@ -150,13 +120,7 @@ func TestChangeRefundByIdSuccess(t *testing.T) { assertResponseSuccess(t, resp, err) } -func TestChargeRefundByIdError(t *testing.T) { - nCharge := NewCharge(EnvSandbox, "") - resp, err := nCharge.RefundById(context.TODO(), "", RefundRequest{}) - assertResponseFailure(t, resp, err) -} - -func TestChangeReceiveInCashByIdSuccess(t *testing.T) { +func TestChangeReceiveInCashById(t *testing.T) { accessToken := getEnvValue(EnvAccessToken) assertFatalStringBlank(t, accessToken) initUndefinedCharge() @@ -174,13 +138,7 @@ func TestChangeReceiveInCashByIdSuccess(t *testing.T) { assertResponseSuccess(t, resp, err) } -func TestChargeReceiveInCashByIdError(t *testing.T) { - nCharge := NewCharge(EnvSandbox, "") - resp, err := nCharge.ReceiveInCashById(context.TODO(), "", ChargeReceiveInCashRequest{}) - assertResponseFailure(t, resp, err) -} - -func TestChangeUndoReceivedInCashByIdSuccess(t *testing.T) { +func TestChangeUndoReceivedInCashById(t *testing.T) { accessToken := getEnvValue(EnvAccessToken) assertFatalStringBlank(t, accessToken) initChargeReceivedInCash() @@ -193,13 +151,7 @@ func TestChangeUndoReceivedInCashByIdSuccess(t *testing.T) { assertResponseSuccess(t, resp, err) } -func TestChargeUndoReceivedInCashByIdError(t *testing.T) { - nCharge := NewCharge(EnvSandbox, "") - resp, err := nCharge.UndoReceivedInCashById(context.TODO(), "") - assertResponseFailure(t, resp, err) -} - -func TestChargeUploadDocumentByIdSuccess(t *testing.T) { +func TestChargeUploadDocumentById(t *testing.T) { accessToken := getEnvValue(EnvAccessToken) assertFatalStringBlank(t, accessToken) initUndefinedCharge() @@ -218,13 +170,7 @@ func TestChargeUploadDocumentByIdSuccess(t *testing.T) { assertResponseSuccess(t, resp, err) } -func TestChargeUploadDocumentByIdError(t *testing.T) { - nCharge := NewCharge(EnvSandbox, "") - resp, err := nCharge.UploadDocumentById(context.TODO(), "", UploadChargeDocumentRequest{}) - assertResponseFailure(t, resp, err) -} - -func TestChargeUpdateDocumentDefinitionsByIdSuccess(t *testing.T) { +func TestChargeUpdateDocumentDefinitionsById(t *testing.T) { accessToken := getEnvValue(EnvAccessToken) assertFatalStringBlank(t, accessToken) initChargeDocumentId() @@ -242,14 +188,7 @@ func TestChargeUpdateDocumentDefinitionsByIdSuccess(t *testing.T) { assertResponseSuccess(t, resp, err) } -func TestChargeUpdateDocumentDefinitionsByIdError(t *testing.T) { - nCharge := NewCharge(EnvSandbox, "") - ctx := context.TODO() - resp, err := nCharge.UpdateDocumentDefinitionsById(ctx, "", "", UpdateChargeDocumentDefinitionsRequest{}) - assertResponseFailure(t, resp, err) -} - -func TestChargeDeleteDocumentByIdSuccess(t *testing.T) { +func TestChargeDeleteDocumentById(t *testing.T) { accessToken := getEnvValue(EnvAccessToken) assertFatalStringBlank(t, accessToken) initChargeDocumentId() @@ -264,14 +203,7 @@ func TestChargeDeleteDocumentByIdSuccess(t *testing.T) { assertResponseSuccess(t, resp, err) } -func TestChargeDeleteDocumentByIdError(t *testing.T) { - nCharge := NewCharge(EnvSandbox, "") - ctx := context.TODO() - resp, err := nCharge.DeleteDocumentById(ctx, "", "") - assertResponseFailure(t, resp, err) -} - -func TestChargeGetByIdSuccess(t *testing.T) { +func TestChargeGetById(t *testing.T) { accessToken := getEnvValue(EnvAccessToken) assertFatalStringBlank(t, accessToken) initUndefinedCharge() @@ -284,13 +216,7 @@ func TestChargeGetByIdSuccess(t *testing.T) { assertResponseSuccess(t, resp, err) } -func TestChargeGetByIdError(t *testing.T) { - nCharge := NewCharge(EnvSandbox, "") - resp, err := nCharge.GetDocumentById(context.TODO(), "", "") - assertResponseFailure(t, resp, err) -} - -func TestChargeGetCreationLimitSuccess(t *testing.T) { +func TestChargeGetCreationLimit(t *testing.T) { accessToken := getEnvValue(EnvAccessToken) assertFatalStringBlank(t, accessToken) ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second) @@ -300,13 +226,7 @@ func TestChargeGetCreationLimitSuccess(t *testing.T) { assertResponseSuccess(t, resp, err) } -func TestChargeGetCreationLimitError(t *testing.T) { - nCharge := NewCharge(EnvSandbox, "") - resp, err := nCharge.GetCreationLimit(context.TODO()) - assertResponseSuccess(t, resp, err) -} - -func TestChargeGetStatusByIdSuccess(t *testing.T) { +func TestChargeGetStatusById(t *testing.T) { accessToken := getEnvValue(EnvAccessToken) assertFatalStringBlank(t, accessToken) initUndefinedCharge() @@ -319,16 +239,10 @@ func TestChargeGetStatusByIdSuccess(t *testing.T) { assertResponseSuccess(t, resp, err) } -func TestChargeGetStatusByIdError(t *testing.T) { - nCharge := NewCharge(EnvSandbox, "") - resp, err := nCharge.GetStatusById(context.TODO(), "") - assertResponseFailure(t, resp, err) -} - -func TestChargeGetIdentificationFieldByIdSuccess(t *testing.T) { +func TestChargeGetIdentificationFieldById(t *testing.T) { accessToken := getEnvValue(EnvAccessToken) assertFatalStringBlank(t, accessToken) - initBankSlipCharge() + initBankSlipCharge(false) chargeId := getEnvValue(EnvBankSlipChargeId) assertFatalStringBlank(t, chargeId) ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second) @@ -338,13 +252,7 @@ func TestChargeGetIdentificationFieldByIdSuccess(t *testing.T) { assertResponseSuccess(t, resp, err) } -func TestChargeGetIdentificationFieldByIdError(t *testing.T) { - nCharge := NewCharge(EnvSandbox, "") - resp, err := nCharge.GetIdentificationFieldById(context.TODO(), "") - assertResponseFailure(t, resp, err) -} - -func TestChargeGetPixQrCodeByIdSuccess(t *testing.T) { +func TestChargeGetPixQrCodeById(t *testing.T) { accessToken := getEnvValue(EnvAccessToken) assertFatalStringBlank(t, accessToken) initPixCharge() @@ -357,13 +265,7 @@ func TestChargeGetPixQrCodeByIdSuccess(t *testing.T) { assertResponseSuccess(t, resp, err) } -func TestChargeGetPixQrCodeByIdError(t *testing.T) { - nCharge := NewCharge(EnvSandbox, "") - resp, err := nCharge.GetPixQrCodeById(context.TODO(), "") - assertResponseFailure(t, resp, err) -} - -func TestChargeGetDocumentByIdSuccess(t *testing.T) { +func TestChargeGetDocumentById(t *testing.T) { accessToken := getEnvValue(EnvAccessToken) assertFatalStringBlank(t, accessToken) initChargeDocumentId() @@ -377,13 +279,7 @@ func TestChargeGetDocumentByIdSuccess(t *testing.T) { assertResponseSuccess(t, resp, err) } -func TestChargeGetDocumentByIdError(t *testing.T) { - nCharge := NewCharge(EnvSandbox, "") - resp, err := nCharge.GetDocumentById(context.TODO(), "", "") - assertResponseFailure(t, resp, err) -} - -func TestChargeGetAllSuccess(t *testing.T) { +func TestChargeGetAll(t *testing.T) { accessToken := getEnvValue(EnvAccessToken) assertFatalStringBlank(t, accessToken) initChargeDocumentId() @@ -418,13 +314,7 @@ func TestChargeGetAllSuccess(t *testing.T) { assertResponseSuccess(t, resp, err) } -func TestChargeGetAllError(t *testing.T) { - nCharge := NewCharge(EnvSandbox, "") - resp, err := nCharge.GetAll(context.TODO(), GetAllChargesRequest{}) - assertResponseFailure(t, resp, err) -} - -func TestChargeGetAllDocumentsByIdSuccess(t *testing.T) { +func TestChargeGetAllDocumentsById(t *testing.T) { accessToken := getEnvValue(EnvAccessToken) assertFatalStringBlank(t, accessToken) initChargeDocumentId() @@ -439,9 +329,3 @@ func TestChargeGetAllDocumentsByIdSuccess(t *testing.T) { }) assertResponseSuccess(t, resp, err) } - -func TestChargeGetAllDocumentsByIdError(t *testing.T) { - nCharge := NewCharge(EnvSandbox, "") - resp, err := nCharge.GetAllDocumentsById(context.TODO(), "", PageableDefaultRequest{}) - assertResponseFailure(t, resp, err) -} diff --git a/asaas/credit_bureau_test.go b/asaas/credit_bureau_test.go index 0d95d1f..cc8bf37 100644 --- a/asaas/credit_bureau_test.go +++ b/asaas/credit_bureau_test.go @@ -6,7 +6,7 @@ import ( "time" ) -func TestCreditBureauGetReportSuccess(t *testing.T) { +func TestCreditBureauGetReport(t *testing.T) { accessToken := getEnvValue(EnvAccessToken) assertFatalStringBlank(t, accessToken) initCustomer() @@ -23,13 +23,7 @@ func TestCreditBureauGetReportSuccess(t *testing.T) { assertResponseSuccess(t, resp, err) } -func TestCreditBureauGetReportError(t *testing.T) { - nCreditBureau := NewCreditBureau(EnvSandbox, "") - resp, err := nCreditBureau.GetReport(context.TODO(), GetReportRequest{}) - assertResponseFailure(t, resp, err) -} - -func TestCreditBureauGetReportByIdSuccess(t *testing.T) { +func TestCreditBureauGetReportById(t *testing.T) { accessToken := getEnvValue(EnvAccessToken) assertFatalStringBlank(t, accessToken) initCreditBureauReport() @@ -41,13 +35,7 @@ func TestCreditBureauGetReportByIdSuccess(t *testing.T) { assertResponseSuccess(t, resp, err) } -func TestCreditBureauGetReportByIdError(t *testing.T) { - nCreditBureau := NewCreditBureau(EnvSandbox, "") - resp, err := nCreditBureau.GetReportById(context.TODO(), "") - assertResponseFailure(t, resp, err) -} - -func TestCreditBureauGetAllReportsSuccess(t *testing.T) { +func TestCreditBureauGetAllReports(t *testing.T) { accessToken := getEnvValue(EnvAccessToken) assertFatalStringBlank(t, accessToken) initCreditBureauReport() @@ -62,9 +50,3 @@ func TestCreditBureauGetAllReportsSuccess(t *testing.T) { }) assertResponseNoContent(t, resp, err) } - -func TestCreditBureauGetAllReportsError(t *testing.T) { - nCreditBureau := NewCreditBureau(EnvSandbox, "") - resp, err := nCreditBureau.GetAllReports(context.TODO(), GetAllReportsRequest{}) - assertResponseFailure(t, resp, err) -} diff --git a/asaas/credit_card_test.go b/asaas/credit_card_test.go index eff3d88..3a79ffa 100644 --- a/asaas/credit_card_test.go +++ b/asaas/credit_card_test.go @@ -2,34 +2,38 @@ package asaas import ( "context" - "encoding/json" - "github.com/GabrielHCataldo/go-asaas/internal/test" "testing" "time" ) -func TestCreditCardTokenizeSuccess(t *testing.T) { +func TestCreditCardTokenize(t *testing.T) { accessToken := getEnvValue(EnvAccessToken) assertFatalStringBlank(t, accessToken) + initCustomer() + customerId := getEnvValue(EnvCustomerId) + assertFatalStringBlank(t, customerId) ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second) defer cancel() - req := &CreditCardTokenizeRequest{} - err := json.Unmarshal(test.GetCreditCardRequestDefault(), req) - assertFatalErrorNonnull(t, err) nCreditCard := NewCreditCard(EnvSandbox, accessToken) - resp, errAsaas := nCreditCard.Tokenize(ctx, *req) + resp, errAsaas := nCreditCard.Tokenize(ctx, CreditCardTokenizeRequest{ + Customer: customerId, + CreditCard: CreditCardRequest{ + HolderName: "unit test go", + Number: "4000000000000010", + ExpiryMonth: "05", + ExpiryYear: "2035", + Ccv: "318", + }, + CreditCardHolderInfo: CreditCardHolderInfoRequest{ + Name: "Unit Test Go", + CpfCnpj: "24971563792", + Email: "unittest@gmail.com", + Phone: "4738010919", + MobilePhone: "47998781877", + PostalCode: "89223-005", + AddressNumber: "277", + AddressComplement: "", + }, + }) assertResponseSuccess(t, resp, errAsaas) } - -func TestCreditCardTokenizeFailure(t *testing.T) { - accessToken := getEnvValue(EnvAccessToken) - assertFatalStringBlank(t, accessToken) - ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second) - defer cancel() - req := &CreditCardTokenizeRequest{} - err := json.Unmarshal(test.GetCreditCardFailureRequestDefault(), req) - assertFatalErrorNonnull(t, err) - nCreditCard := NewCreditCard(EnvSandbox, accessToken) - resp, errAsaas := nCreditCard.Tokenize(ctx, *req) - assertResponseFailure(t, resp, errAsaas) -} diff --git a/asaas/customer_test.go b/asaas/customer_test.go index a4cf5cd..2431914 100644 --- a/asaas/customer_test.go +++ b/asaas/customer_test.go @@ -2,27 +2,125 @@ package asaas import ( "context" - "encoding/json" - "github.com/GabrielHCataldo/go-asaas/internal/test" + "github.com/mvrilo/go-cpf" "testing" "time" ) -func TestCustomerCreateSuccess(t *testing.T) { +func TestCustomerCreate(t *testing.T) { accessToken := getEnvValue(EnvAccessToken) assertFatalStringBlank(t, accessToken) ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second) defer cancel() - req := &CreateCustomerRequest{} - err := json.Unmarshal(test.GetCreateCustomerRequestDefault(), req) - assertFatalErrorNonnull(t, err) nCustomer := NewCustomer(EnvSandbox, accessToken) - resp, errAsaas := nCustomer.Create(ctx, *req) - assertResponseSuccess(t, resp, errAsaas) + resp, err := nCustomer.Create(ctx, CreateCustomerRequest{ + Name: "Unit test go", + CpfCnpj: cpf.Generate(), + Email: "", + Phone: "", + MobilePhone: "", + Address: "", + AddressNumber: "", + Complement: "", + Province: "", + PostalCode: "", + ExternalReference: "", + NotificationDisabled: false, + AdditionalEmails: "", + MunicipalInscription: "", + StateInscription: "", + Observations: "", + GroupName: "", + Company: "", + }) + assertResponseSuccess(t, resp, err) } -func TestCustomerCreateError(t *testing.T) { - nCustomer := NewCustomer(EnvSandbox, "") - resp, err := nCustomer.Create(context.TODO(), CreateCustomerRequest{}) - assertResponseFailure(t, resp, err) +func TestCustomerUpdateById(t *testing.T) { + accessToken := getEnvValue(EnvAccessToken) + assertFatalStringBlank(t, accessToken) + initCustomer() + customerId := getEnvValue(EnvCustomerId) + assertFatalStringBlank(t, customerId) + ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second) + defer cancel() + nCustomer := NewCustomer(EnvSandbox, accessToken) + resp, err := nCustomer.UpdateById(ctx, customerId, UpdateCustomerRequest{ + Name: "Unit test go updated", + CpfCnpj: nil, + Email: nil, + Phone: nil, + MobilePhone: nil, + Address: nil, + AddressNumber: nil, + Complement: nil, + Province: nil, + PostalCode: nil, + ExternalReference: nil, + NotificationDisabled: nil, + AdditionalEmails: nil, + MunicipalInscription: nil, + StateInscription: nil, + Observations: nil, + GroupName: nil, + Company: nil, + }) + assertResponseSuccess(t, resp, err) +} + +func TestCustomerDeleteById(t *testing.T) { + accessToken := getEnvValue(EnvAccessToken) + assertFatalStringBlank(t, accessToken) + initCustomer() + customerId := getEnvValue(EnvCustomerId) + assertFatalStringBlank(t, customerId) + ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second) + defer cancel() + nCustomer := NewCustomer(EnvSandbox, accessToken) + resp, err := nCustomer.DeleteById(ctx, customerId) + assertResponseSuccess(t, resp, err) +} + +func TestCustomerRestoreById(t *testing.T) { + accessToken := getEnvValue(EnvAccessToken) + assertFatalStringBlank(t, accessToken) + initCustomerDeleted() + customerId := getEnvValue(EnvChargeDeletedId) + assertFatalStringBlank(t, customerId) + ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second) + defer cancel() + nCustomer := NewCustomer(EnvSandbox, accessToken) + resp, err := nCustomer.RestoreById(ctx, customerId) + assertResponseSuccess(t, resp, err) +} + +func TestCustomerGetById(t *testing.T) { + accessToken := getEnvValue(EnvAccessToken) + assertFatalStringBlank(t, accessToken) + initCustomer() + customerId := getEnvValue(EnvChargeDeletedId) + ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second) + defer cancel() + nCustomer := NewCustomer(EnvSandbox, accessToken) + resp, err := nCustomer.GetById(ctx, customerId) + assertResponseSuccess(t, resp, err) +} + +func TestCustomerGetAll(t *testing.T) { + accessToken := getEnvValue(EnvAccessToken) + assertFatalStringBlank(t, accessToken) + initCustomer() + ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second) + defer cancel() + nCustomer := NewCustomer(EnvSandbox, accessToken) + resp, err := nCustomer.GetAll(ctx, GetAllCustomersRequest{ + Name: "", + Email: "", + CpfCnpj: "", + GroupName: "", + ExternalReference: "", + Offset: 0, + Limit: 10, + }) + assertResponseSuccess(t, resp, err) } diff --git a/asaas/fiscal_info_test.go b/asaas/fiscal_info_test.go index 862f0f5..ed40fde 100644 --- a/asaas/fiscal_info_test.go +++ b/asaas/fiscal_info_test.go @@ -6,12 +6,62 @@ import ( "time" ) +func TestFiscalInfoSave(t *testing.T) { + accessToken := getEnvValue(EnvAccessToken) + assertFatalStringBlank(t, accessToken) + ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second) + defer cancel() + nFiscalInfo := NewFiscalInfo(EnvSandbox, accessToken) + resp, err := nFiscalInfo.Save(ctx, SaveFiscalInfoRequest{ + Email: "test@gmail.com", + MunicipalInscription: Pointer("15.54.74"), + SimplesNacional: Pointer(true), + CulturalProjectsPromoter: nil, + Cnae: Pointer("6201501"), + SpecialTaxRegime: nil, + ServiceListItem: nil, + RpsSerie: nil, + RpsNumber: Pointer(21), + LoteNumber: nil, + Username: nil, + Password: Pointer("test"), + AccessToken: nil, + CertificateFile: nil, + CertificatePassword: nil, + }) + assertResponseSuccess(t, resp, err) +} + +func TestFiscalInfoGet(t *testing.T) { + accessToken := getEnvValue(EnvAccessToken) + assertFatalStringBlank(t, accessToken) + ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second) + defer cancel() + nFiscalInfo := NewFiscalInfo(EnvSandbox, accessToken) + resp, err := nFiscalInfo.Get(ctx) + assertResponseSuccess(t, resp, err) +} + +func TestFiscalInfoGetMunicipalSettings(t *testing.T) { + accessToken := getEnvValue(EnvAccessToken) + assertFatalStringBlank(t, accessToken) + ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second) + defer cancel() + nFiscalInfo := NewFiscalInfo(EnvSandbox, accessToken) + resp, err := nFiscalInfo.GetMunicipalSettings(ctx) + assertResponseSuccess(t, resp, err) +} + func TestFiscalInfoGetAllServices(t *testing.T) { accessToken := getEnvValue(EnvAccessToken) assertFatalStringBlank(t, accessToken) ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second) defer cancel() nFiscalInfo := NewFiscalInfo(EnvSandbox, accessToken) - resp, errAsaas := nFiscalInfo.GetAllServices(ctx, GetAllServicesRequest{}) - assertResponseSuccess(t, resp, errAsaas) + resp, err := nFiscalInfo.GetAllServices(ctx, GetAllServicesRequest{ + Description: "", + Offset: 0, + Limit: 10, + }) + assertResponseSuccess(t, resp, err) } diff --git a/asaas/installment_test.go b/asaas/installment_test.go index b06cf4a..685bd62 100644 --- a/asaas/installment_test.go +++ b/asaas/installment_test.go @@ -6,9 +6,86 @@ import ( "time" ) -func TestInstallmentGetAllSuccess(t *testing.T) { +func TestInstallmentUpdateSplitsById(t *testing.T) { accessToken := getEnvValue(EnvAccessToken) assertFatalStringBlank(t, accessToken) + initBankSlipCharge(true) + installmentId := getEnvValue(EnvChargeInstallmentId) + assertFatalStringBlank(t, installmentId) + walletIdSecondary := getEnvValue(EnvWalletIdSecondary) + assertFatalStringBlank(t, walletIdSecondary) + ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second) + defer cancel() + nInstallment := NewInstallment(EnvSandbox, accessToken) + resp, err := nInstallment.UpdateSplitsById(ctx, installmentId, []SplitRequest{ + { + WalletId: walletIdSecondary, + FixedValue: 0, + PercentualValue: 50, + TotalFixedValue: 0, + }, + }) + assertResponseSuccess(t, resp, err) +} + +func TestInstallmentDeleteById(t *testing.T) { + accessToken := getEnvValue(EnvAccessToken) + assertFatalStringBlank(t, accessToken) + initBankSlipCharge(true) + installmentId := getEnvValue(EnvChargeInstallmentId) + assertFatalStringBlank(t, installmentId) + ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second) + defer cancel() + nInstallment := NewInstallment(EnvSandbox, accessToken) + resp, err := nInstallment.DeleteById(ctx, installmentId) + assertResponseSuccess(t, resp, err) +} + +func TestInstallmentRefundById(t *testing.T) { + accessToken := getEnvValue(EnvAccessToken) + assertFatalStringBlank(t, accessToken) + initCreditCardCharge(false, true) + installmentId := getEnvValue(EnvChargeInstallmentId) + assertFatalStringBlank(t, installmentId) + ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second) + defer cancel() + nInstallment := NewInstallment(EnvSandbox, accessToken) + resp, err := nInstallment.RefundById(ctx, installmentId) + assertResponseSuccess(t, resp, err) +} + +func TestInstallmentGetById(t *testing.T) { + accessToken := getEnvValue(EnvAccessToken) + assertFatalStringBlank(t, accessToken) + initBankSlipCharge(true) + installmentId := getEnvValue(EnvChargeInstallmentId) + ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second) + defer cancel() + nInstallment := NewInstallment(EnvSandbox, accessToken) + resp, err := nInstallment.GetById(ctx, installmentId) + assertResponseSuccess(t, resp, err) +} + +func TestInstallmentGetPaymentBookById(t *testing.T) { + accessToken := getEnvValue(EnvAccessToken) + assertFatalStringBlank(t, accessToken) + initBankSlipCharge(true) + installmentId := getEnvValue(EnvChargeInstallmentId) + assertFatalStringBlank(t, installmentId) + ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second) + defer cancel() + nInstallment := NewInstallment(EnvSandbox, accessToken) + resp, err := nInstallment.GetPaymentBookById(ctx, installmentId, InstallmentPaymentBookRequest{ + Sort: "", + Order: "", + }) + assertResponseFailure(t, resp, err) +} + +func TestInstallmentGetAll(t *testing.T) { + accessToken := getEnvValue(EnvAccessToken) + assertFatalStringBlank(t, accessToken) + initBankSlipCharge(true) ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second) defer cancel() nInstallment := NewInstallment(EnvSandbox, accessToken) diff --git a/asaas/main_test.go b/asaas/main_test.go index 8f9f433..223a110 100644 --- a/asaas/main_test.go +++ b/asaas/main_test.go @@ -12,11 +12,11 @@ import ( const EnvAccessToken = "ASAAS_ACCESS_TOKEN" const EnvAccessTokenSecondary = "ASAAS_ACCESS_TOKEN_SECONDARY" +const EnvWalletIdSecondary = "ASAAS_WALLET_ID_SECONDARY" const EnvFileName = "ASAAS_FILE_NAME" const EnvImageName = "ASAAS_IMAGE_NAME" const EnvCustomerId = "ASAAS_CUSTOMER_ID" - -// const EnvCustomerDeletedId = "ASAAS_CUSTOMER_DELETED_ID" +const EnvCustomerDeletedId = "ASAAS_CUSTOMER_DELETED_ID" const EnvCreditCardChargeId = "ASAAS_CREDIT_CARD_CHARGE_ID" const EnvPixChargeId = "ASAAS_PIX_CHARGE_ID" const EnvBankSlipChargeId = "ASAAS_BANK_SLIP_CHARGE_ID" @@ -34,7 +34,7 @@ const EnvCreditBureauReportId = "ASAAS_CREDIT_BUREAU_REPORT_ID" func init() { initFile() initImage() - //initFiscalInfo() + initFiscalInfo() } func TestMain(m *testing.M) { @@ -91,7 +91,28 @@ func initCustomer() { setEnv(EnvCustomerId, resp.Id) } -func initCreditCardCharge(authorizeOnly bool, withInstallment bool) { +func initCustomerDeleted() { + accessToken := getEnvValue(EnvAccessToken) + if util.IsBlank(&accessToken) { + return + } + initCustomer() + customerId := getEnvValue(EnvCustomerId) + if util.IsBlank(&customerId) { + return + } + ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second) + defer cancel() + customerAsaas := NewCustomer(EnvSandbox, accessToken) + resp, err := customerAsaas.DeleteById(ctx, customerId) + if err != nil || resp.IsFailure() { + logError("error resp:", resp, "err: ", err) + return + } + setEnv(EnvCustomerDeletedId, resp.Id) +} + +func initCreditCardCharge(capture bool, withInstallment bool) { accessToken := getEnvValue(EnvAccessToken) if util.IsBlank(&accessToken) { return @@ -105,7 +126,7 @@ func initCreditCardCharge(authorizeOnly bool, withInstallment bool) { ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second) defer cancel() now := time.Now() - cReq := &CreateChargeRequest{ + req := CreateChargeRequest{ Customer: customerId, BillingType: BillingTypeCreditCard, Value: 100, @@ -127,15 +148,15 @@ func initCreditCardCharge(authorizeOnly bool, withInstallment bool) { PostalCode: "89223-005", AddressNumber: "277", }, - AuthorizeOnly: authorizeOnly, + AuthorizeOnly: !capture, RemoteIp: "191.253.125.194", } if withInstallment { - cReq.InstallmentCount = 2 - cReq.InstallmentValue = cReq.Value / float64(cReq.InstallmentCount) + req.InstallmentCount = 2 + req.InstallmentValue = req.Value / float64(req.InstallmentCount) } chargeAsaas := NewCharge(EnvSandbox, accessToken) - resp, err := chargeAsaas.Create(ctx, *cReq) + resp, err := chargeAsaas.Create(ctx, req) if err != nil || resp.IsFailure() { logError("error resp:", resp, "err: ", err) return @@ -144,7 +165,9 @@ func initCreditCardCharge(authorizeOnly bool, withInstallment bool) { if !success { return } - setEnv(EnvChargeInstallmentId, resp.Installment) + if withInstallment { + setEnv(EnvChargeInstallmentId, resp.Installment) + } } func initPixCharge() { @@ -185,7 +208,7 @@ func initPixCharge() { setEnv(EnvChargePixQrCodePayload, pixQrCodeResp.Payload) } -func initBankSlipCharge() { +func initBankSlipCharge(withInstallment bool) { accessToken := getEnvValue(EnvAccessToken) if util.IsBlank(&accessToken) { @@ -200,13 +223,18 @@ func initBankSlipCharge() { ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second) defer cancel() now := time.Now() - chargeAsaas := NewCharge(EnvSandbox, accessToken) - resp, err := chargeAsaas.Create(ctx, CreateChargeRequest{ + req := CreateChargeRequest{ BillingType: BillingTypeBankSlip, DueDate: NewDate(now.Year(), now.Month(), now.Day(), now.Location()), Value: 100, Description: "Cobrança via teste unitário em Golang", - }) + } + if withInstallment { + req.InstallmentCount = 2 + req.InstallmentValue = req.Value / float64(req.InstallmentCount) + } + chargeAsaas := NewCharge(EnvSandbox, accessToken) + resp, err := chargeAsaas.Create(ctx, req) if err != nil || resp.IsFailure() { logError("error resp:", resp, "err: ", err) return @@ -221,6 +249,9 @@ func initBankSlipCharge() { return } setEnv(EnvChargeIdentificationField, identificationFieldResp.IdentificationField) + if withInstallment { + setEnv(EnvChargeInstallmentId, resp.Installment) + } } func initUndefinedCharge() { @@ -360,7 +391,7 @@ func initBillPayment() { return } clearBillPaymentId() - initBankSlipCharge() + initBankSlipCharge(false) chargeId := getEnvValue(EnvBankSlipChargeId) if util.IsBlank(&chargeId) { return @@ -428,6 +459,38 @@ func initCreditBureauReport() { setEnv(EnvCreditBureauReportId, resp.Id) } +func initFiscalInfo() { + accessToken := getEnvValue(EnvAccessToken) + if util.IsBlank(&accessToken) { + + return + } + ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second) + defer cancel() + nFiscalInfo := NewFiscalInfo(EnvSandbox, accessToken) + resp, err := nFiscalInfo.Save(ctx, SaveFiscalInfoRequest{ + Email: "test@gmail.com", + MunicipalInscription: Pointer("15.54.74"), + SimplesNacional: Pointer(true), + CulturalProjectsPromoter: nil, + Cnae: Pointer("6201501"), + SpecialTaxRegime: nil, + ServiceListItem: nil, + RpsSerie: nil, + RpsNumber: Pointer(21), + LoteNumber: nil, + Username: nil, + Password: Pointer("test"), + AccessToken: nil, + CertificateFile: nil, + CertificatePassword: nil, + }) + if err != nil || resp.IsFailure() { + logError("error resp:", resp, "err: ", err) + return + } +} + func clearCustomerId() { accessToken := getEnvValueWithoutLogger(EnvAccessToken) if util.IsBlank(&accessToken) { diff --git a/asaas/negativity_test.go b/asaas/negativity_test.go index 371c17f..962eabb 100644 --- a/asaas/negativity_test.go +++ b/asaas/negativity_test.go @@ -9,7 +9,7 @@ import ( "time" ) -func TestNegativityCreateSuccess(t *testing.T) { +func TestNegativityCreate(t *testing.T) { accessToken := getEnvValue(EnvAccessToken) assertFatalStringBlank(t, accessToken) f, err := os.Open(getEnvValue(EnvFileName)) diff --git a/asaas/notification_test.go b/asaas/notification_test.go index 046b371..1399120 100644 --- a/asaas/notification_test.go +++ b/asaas/notification_test.go @@ -7,7 +7,7 @@ import ( "time" ) -func TestNotificationGetAllByCustomerSuccess(t *testing.T) { +func TestNotificationGetAllByCustomer(t *testing.T) { accessToken := getEnvValue(EnvAccessToken) assertFatalStringBlank(t, accessToken) ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second) diff --git a/asaas/pix_test.go b/asaas/pix_test.go index a83903d..7fa855b 100644 --- a/asaas/pix_test.go +++ b/asaas/pix_test.go @@ -6,7 +6,7 @@ import ( "time" ) -func TestPixGetAllKeysSuccess(t *testing.T) { +func TestPixGetAllKeys(t *testing.T) { accessToken := getEnvValue(EnvAccessToken) assertFatalStringBlank(t, accessToken) ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second) diff --git a/asaas/transfer_test.go b/asaas/transfer_test.go index 44d185b..25d0ce7 100644 --- a/asaas/transfer_test.go +++ b/asaas/transfer_test.go @@ -8,7 +8,7 @@ import ( "time" ) -func TestTransferTransferToBankSuccess(t *testing.T) { +func TestTransferTransferToBank(t *testing.T) { accessToken := getEnvValue(EnvAccessToken) assertFatalStringBlank(t, accessToken) ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second) diff --git a/internal/test/dough.go b/internal/test/dough.go index 8a19b41..4a57bea 100644 --- a/internal/test/dough.go +++ b/internal/test/dough.go @@ -11,164 +11,10 @@ func GetCustomerIdDefault() string { return "cus_000005791749" } -func GetChargeIdDefault() string { - return "pay_9162542863222410" -} - func GetPaymentLinkIdDefault() string { return "le5jqxz8as7pgwn9" } -func GetCreatePixChargeRequestDefault() []byte { - return []byte(` - { - "billingType": "PIX", - "dueDate": "2099-11-26", - "value": 100, - "description": "Cobrança via teste unitário em Golang", - "remoteIp": "191.253.125.194" - } - `) -} - -func GetCreateBankSlipChargeRequestDefault() []byte { - return []byte(` - { - "billingType": "BOLETO", - "discount": { - "value": 10, - "dueDateLimitDays": 0, - "type": "FIXED" - }, - "interest": { - "value": 2 - }, - "fine": { - "value": 1 - }, - "dueDate": "2099-11-29", - "value": 100, - "description": "Cobrança via teste unitário em Golang", - "remoteIp": "191.253.125.194" - } - `) -} - -func GetCreateUndefinedChargeRequestDefault() []byte { - return []byte(` - { - "billingType": "UNDEFINED", - "dueDate": "2099-11-29", - "value": 100, - "description": "Cobrança via teste unitário em Golang" - } - `) -} - -func GetCreateCreditCardChargeRequestDefault() []byte { - return []byte(` - { - "billingType": "CREDIT_CARD", - "value": 10.0, - "dueDate": "2099-11-26", - "description": "Cobrança via teste unitário em Golang", - "creditCard": { - "holderName": "unit test go", - "number": "4000000000000010", - "expiryMonth": "05", - "expiryYear": "2035", - "ccv": "318" - }, - "creditCardHolderInfo": { - "name": "Unit Test Go", - "cpfCnpj": "24971563792", - "email": "unittest@gmail.com", - "phone": "4738010919", - "mobilePhone": "47998781877", - "postalCode": "89223-005", - "addressNumber": "277" - }, - "installmentCount": 2, - "installmentValue": 5, - "remoteIp": "191.253.125.194" - } - `) -} - -func GetCreateCreditCardChargeFailureRequestDefault() []byte { - return []byte(` - { - "billingType": "CREDIT_CARD", - "value": 10.0, - "dueDate": "2099-11-28", - "description": "Cobrança via teste unitário em Golang", - "creditCard": { - "holderName": "unit test go", - "number": "5184019740373151", - "expiryMonth": "05", - "expiryYear": "2035", - "ccv": "318" - }, - "creditCardHolderInfo": { - "name": "Unit Test Go", - "cpfCnpj": "24971563792", - "email": "unittest@gmail.com", - "phone": "4738010919", - "mobilePhone": "47998781877", - "postalCode": "89223-005", - "addressNumber": "277" - }, - "remoteIp": "191.253.125.194" - } - `) -} - -func GetCreditCardFailureRequestDefault() []byte { - return []byte(` - { - "creditCard": { - "holderName": "unit test go", - "number": "5184019740373151", - "expiryMonth": "05", - "expiryYear": "2035", - "ccv": "318" - }, - "creditCardHolderInfo": { - "name": "Unit Test Go", - "cpfCnpj": "24971563792", - "email": "unittest@gmail.com", - "phone": "4738010919", - "mobilePhone": "47998781877", - "postalCode": "89223-005", - "addressNumber": "277" - } - } - `) -} - -func GetCreditCardRequestDefault() []byte { - return []byte(` - { - "creditCard": { - "holderName": "unit test go", - "number": "4000000000000010", - "expiryMonth": "05", - "expiryYear": "2035", - "ccv": "318" - }, - "creditCardHolderInfo": { - "name": "Unit Test Go", - "cpfCnpj": "24971563792", - "email": "unittest@gmail.com", - "phone": "4738010919", - "mobilePhone": "47998781877", - "postalCode": "89223-005", - "addressNumber": "277" - } - } - `) -} - func GetSimpleFile() (*os.File, error) { randomKey := strconv.FormatInt(time.Now().Unix()+int64(time.Now().Nanosecond()), 10) nameFile := "test " + randomKey + ".txt" @@ -191,29 +37,6 @@ func GetSimpleImage() (*os.File, error) { return os.Open("../gopher-asaas.png") } -func GetCreateCustomerRequestDefault() []byte { - return []byte(` - { - "name": "Unit Test Golang", - "email": "unittestgolang@gmail.com", - "phone": "4738010920", - "mobilePhone": "47999376637", - "cpfCnpj": "07207283040", - "postalCode": "01310-000", - "address": "Av. Paulista", - "addressNumber": "150", - "complement": "Sala 201", - "province": "Centro", - "externalReference": "12987382", - "notificationDisabled": false, - "additionalEmails": "unittestgolang2@gmail.com,unittestgolang3@gmail.com", - "municipalInscription": "46683695908", - "stateInscription": "646681195275", - "observations": "unit test golang" - } - `) -} - func GetTransferToBankRequestDefault() []byte { return []byte(` {