mirror of
https://github.com/google/nomulus.git
synced 2025-08-06 01:35:17 +02:00
Delete all Braintree code
We never launched this, don't planning on launching it now anyway, and it's rotted over the past two years anyway. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=202993577
This commit is contained in:
parent
7023b818b7
commit
32b3563126
67 changed files with 28 additions and 3352 deletions
|
@ -1,97 +0,0 @@
|
|||
// Copyright 2017 The Nomulus Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
goog.setTestOnly();
|
||||
|
||||
goog.require('goog.dispose');
|
||||
goog.require('goog.dom');
|
||||
goog.require('goog.style');
|
||||
goog.require('goog.testing.MockControl');
|
||||
goog.require('goog.testing.asserts');
|
||||
goog.require('goog.testing.jsunit');
|
||||
goog.require('registry.registrar.BrainFrame');
|
||||
goog.require('registry.testing');
|
||||
|
||||
|
||||
var mocks = new goog.testing.MockControl();
|
||||
|
||||
var brainframe;
|
||||
var mockPostMessage;
|
||||
|
||||
|
||||
function setUp() {
|
||||
registry.testing.addToDocument('<form><div id="bf"></div></form>');
|
||||
brainframe = new registry.registrar.BrainFrame('omg', 'bf');
|
||||
mockPostMessage =
|
||||
mocks.createMethodMock(registry.registrar.BrainFrame, 'postMessage_');
|
||||
}
|
||||
|
||||
|
||||
function tearDown() {
|
||||
goog.dispose(brainframe);
|
||||
mocks.$tearDown();
|
||||
}
|
||||
|
||||
|
||||
function testRun_sendsTokenRequestToParent() {
|
||||
mockPostMessage('{"type":"token_request"}', 'omg');
|
||||
mocks.$replayAll();
|
||||
brainframe.run();
|
||||
mocks.$verifyAll();
|
||||
}
|
||||
|
||||
|
||||
function testTokenResponseMessage_callsSetup() {
|
||||
var called = false;
|
||||
goog.global.braintree = {};
|
||||
goog.global.braintree.setup = function(token, mode, args) {
|
||||
called = true;
|
||||
assertEquals('imatoken', token);
|
||||
assertEquals('dropin', mode);
|
||||
assertEquals('bf', args.container.id);
|
||||
};
|
||||
brainframe.onMessage_({
|
||||
getBrowserEvent: function() {
|
||||
return {
|
||||
source: window.parent,
|
||||
origin: 'omg',
|
||||
data: '{"type": "token_response", "token": "imatoken"}'
|
||||
};
|
||||
}
|
||||
});
|
||||
assertTrue(called);
|
||||
}
|
||||
|
||||
|
||||
function testPaymentMethodMessage_sendsInfo() {
|
||||
mockPostMessage('{"type":"payment_method","submit":false,"method":"hi"}',
|
||||
'omg');
|
||||
mocks.$replayAll();
|
||||
brainframe.onPaymentMethod_('hi');
|
||||
mocks.$verifyAll();
|
||||
}
|
||||
|
||||
|
||||
function testOnResizeTimer_sendsHeight() {
|
||||
mockPostMessage('{"type":"resize_request","height":123}', 'omg');
|
||||
mocks.$replayAll();
|
||||
goog.style.setHeight(goog.dom.getElement('bf'), 123);
|
||||
brainframe.onResizeTimer_();
|
||||
mocks.$verifyAll();
|
||||
|
||||
// But does not send height if size hasn't changed.
|
||||
mocks.$replayAll();
|
||||
brainframe.onResizeTimer_();
|
||||
mocks.$verifyAll();
|
||||
}
|
|
@ -51,7 +51,6 @@ function setUp() {
|
|||
logoutUrl: 'omg',
|
||||
isAdmin: true,
|
||||
clientId: test.testClientId,
|
||||
showPaymentLink: false,
|
||||
logoFilename: 'logo.png',
|
||||
productName: 'Nomulus',
|
||||
integrationEmail: 'integration@example.com',
|
||||
|
|
|
@ -50,7 +50,6 @@ function setUp() {
|
|||
logoutUrl: 'omg',
|
||||
isAdmin: true,
|
||||
clientId: test.testClientId,
|
||||
showPaymentLink: false,
|
||||
logoFilename: 'logo.png',
|
||||
productName: 'Nomulus',
|
||||
integrationEmail: 'integration@google.com',
|
||||
|
|
|
@ -41,7 +41,6 @@ function setUp() {
|
|||
logoutUrl: 'omg',
|
||||
isAdmin: true,
|
||||
clientId: 'daddy',
|
||||
showPaymentLink: false,
|
||||
logoFilename: 'logo.png',
|
||||
productName: 'Nomulus',
|
||||
integrationEmail: 'integration@example.com',
|
||||
|
|
|
@ -47,7 +47,6 @@ function setUp() {
|
|||
logoutUrl: 'https://justinetunney.com',
|
||||
isAdmin: true,
|
||||
clientId: 'ignore',
|
||||
showPaymentLink: false,
|
||||
logoFilename: 'logo.png',
|
||||
productName: 'Nomulus',
|
||||
integrationEmail: 'integration@example.com',
|
||||
|
|
|
@ -47,7 +47,6 @@ function setUp() {
|
|||
logoutUrl: 'https://example.com',
|
||||
isAdmin: true,
|
||||
clientId: 'ignore',
|
||||
showPaymentLink: false,
|
||||
logoFilename: 'logo.png',
|
||||
productName: 'Nomulus',
|
||||
integrationEmail: 'integration@example.com',
|
||||
|
|
|
@ -1,208 +0,0 @@
|
|||
// Copyright 2017 The Nomulus Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
goog.setTestOnly();
|
||||
|
||||
goog.require('goog.dispose');
|
||||
goog.require('goog.dom');
|
||||
goog.require('goog.dom.classlist');
|
||||
goog.require('goog.events.EventType');
|
||||
goog.require('goog.json');
|
||||
goog.require('goog.testing.PropertyReplacer');
|
||||
goog.require('goog.testing.asserts');
|
||||
goog.require('goog.testing.events');
|
||||
goog.require('goog.testing.events.Event');
|
||||
goog.require('goog.testing.jsunit');
|
||||
goog.require('goog.testing.net.XhrIo');
|
||||
goog.require('registry.registrar.Payment');
|
||||
goog.require('registry.testing');
|
||||
|
||||
|
||||
var $ = goog.dom.getRequiredElement;
|
||||
var $$ = goog.dom.getRequiredElementByClass;
|
||||
var stubs = new goog.testing.PropertyReplacer();
|
||||
|
||||
var page;
|
||||
|
||||
|
||||
function setUp() {
|
||||
registry.testing.addToDocument('<div id="reg-content"></div>');
|
||||
registry.testing.addToDocument('<div class="kd-butterbar"></div>');
|
||||
registry.testing.addToDocument('<div class="kd-butterbar-text"></div>');
|
||||
stubs.setPath('goog.net.XhrIo', goog.testing.net.XhrIo);
|
||||
page = new registry.registrar.Payment(null, '?');
|
||||
page.bindToDom();
|
||||
}
|
||||
|
||||
|
||||
function tearDown() {
|
||||
goog.dispose(page);
|
||||
stubs.reset();
|
||||
goog.testing.net.XhrIo.cleanup();
|
||||
}
|
||||
|
||||
|
||||
function testRenderForm() {
|
||||
registry.testing.assertReqMockRsp(
|
||||
'?',
|
||||
'/registrar-payment-setup',
|
||||
{},
|
||||
{
|
||||
status: 'SUCCESS',
|
||||
results: [
|
||||
{
|
||||
token: 'omg-im-a-token',
|
||||
currencies: ['LOL', 'OMG'],
|
||||
brainframe: ''
|
||||
}
|
||||
]
|
||||
});
|
||||
assertEquals('', $('amount').value);
|
||||
assertEquals('LOL', goog.dom.getTextContent($$('selected', $('currency'))));
|
||||
assertTrue(
|
||||
goog.dom.classlist.contains($$('reg-payment-form-submit'), 'disabled'));
|
||||
}
|
||||
|
||||
|
||||
function testResize() {
|
||||
testRenderForm();
|
||||
send({
|
||||
type: 'resize_request',
|
||||
height: 123
|
||||
});
|
||||
assertEquals('123', $$('reg-payment-form-method').height);
|
||||
}
|
||||
|
||||
|
||||
function testReady() {
|
||||
testRenderForm();
|
||||
send({type: 'ready'});
|
||||
assertFalse(
|
||||
goog.dom.classlist.contains($$('reg-payment-form-submit'), 'disabled'));
|
||||
}
|
||||
|
||||
|
||||
function testPaymentMethodCard() {
|
||||
testRenderForm();
|
||||
send({
|
||||
type: 'payment_method',
|
||||
method: {
|
||||
type: 'CreditCard',
|
||||
nonce: 'omg-im-a-nonce',
|
||||
details: {
|
||||
cardType: 'Amex',
|
||||
lastTwo: '12'
|
||||
}
|
||||
}
|
||||
});
|
||||
assertEquals(
|
||||
'American Express: xxxx xxxxxx xxx12',
|
||||
goog.dom.getTextContent($$('reg-payment-form-method-info')));
|
||||
}
|
||||
|
||||
|
||||
function testPaymentMethodPaypal() {
|
||||
testRenderForm();
|
||||
send({
|
||||
type: 'payment_method',
|
||||
method: {
|
||||
type: 'PayPalAccount',
|
||||
nonce: 'omg-im-a-nonce',
|
||||
details: {
|
||||
email: 'sparrows@nightingales.example'
|
||||
}
|
||||
}
|
||||
});
|
||||
assertEquals(
|
||||
'PayPal: sparrows@nightingales.example',
|
||||
goog.dom.getTextContent($$('reg-payment-form-method-info')));
|
||||
}
|
||||
|
||||
|
||||
function testBadAmount_displaysError() {
|
||||
testPaymentMethodCard();
|
||||
$('amount').value = '3.14';
|
||||
submit();
|
||||
registry.testing.assertReqMockRsp(
|
||||
'?',
|
||||
'/registrar-payment',
|
||||
{
|
||||
amount: '3.14',
|
||||
currency: 'LOL',
|
||||
paymentMethodNonce: 'omg-im-a-nonce'
|
||||
},
|
||||
{
|
||||
status: 'ERROR',
|
||||
message: 'gimmeh moar money',
|
||||
field: 'amount'
|
||||
});
|
||||
assertTrue(goog.dom.classlist.contains($('amount'), 'kd-formerror'));
|
||||
assertEquals('gimmeh moar money',
|
||||
goog.dom.getTextContent($$('kd-errormessage')));
|
||||
}
|
||||
|
||||
|
||||
function testGoodPayment_displaysSuccessPage() {
|
||||
testPaymentMethodCard();
|
||||
$('amount').value = '314';
|
||||
submit();
|
||||
registry.testing.assertReqMockRsp(
|
||||
'?',
|
||||
'/registrar-payment',
|
||||
{
|
||||
amount: '314',
|
||||
currency: 'LOL',
|
||||
paymentMethodNonce: 'omg-im-a-nonce'
|
||||
},
|
||||
{
|
||||
status: 'SUCCESS',
|
||||
results: [
|
||||
{
|
||||
id: 'omg-im-an-id',
|
||||
formattedAmount: '$314'
|
||||
}
|
||||
]
|
||||
});
|
||||
assertContains('Payment Processed',
|
||||
goog.dom.getTextContent($$('reg-payment')));
|
||||
assertContains('omg-im-an-id',
|
||||
goog.dom.getTextContent($$('reg-payment')));
|
||||
assertContains('$314',
|
||||
goog.dom.getTextContent($$('reg-payment')));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sends message to page.
|
||||
* @param {string} message
|
||||
*/
|
||||
function send(message) {
|
||||
page.onMessage_({
|
||||
getBrowserEvent: function() {
|
||||
return {
|
||||
source: goog.dom.getFrameContentWindow($$('reg-payment-form-method')),
|
||||
data: goog.json.serialize(message)
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/** Submits payment form. */
|
||||
function submit() {
|
||||
goog.testing.events.fireBrowserEvent(
|
||||
new goog.testing.events.Event(
|
||||
goog.events.EventType.SUBMIT,
|
||||
$$('reg-payment-form')));
|
||||
}
|
|
@ -55,7 +55,6 @@ function setUp() {
|
|||
isAdmin: true,
|
||||
xsrfToken: test.testXsrfToken,
|
||||
clientId: test.testClientId,
|
||||
showPaymentLink: false,
|
||||
logoFilename: 'logo.png',
|
||||
productName: 'Nomulus',
|
||||
integrationEmail: 'integration@example.com',
|
||||
|
|
|
@ -49,7 +49,6 @@ function setUp() {
|
|||
logoutUrl: 'omg',
|
||||
isAdmin: true,
|
||||
clientId: test.testClientId,
|
||||
showPaymentLink: false,
|
||||
logoFilename: 'logo.png',
|
||||
productName: 'Nomulus',
|
||||
integrationEmail: 'integration@example.com',
|
||||
|
|
|
@ -12,7 +12,6 @@ java_library(
|
|||
srcs = glob(["*.java"]),
|
||||
resources = glob(["testdata/*"]),
|
||||
deps = [
|
||||
"//java/google/registry/braintree",
|
||||
"//java/google/registry/config",
|
||||
"//java/google/registry/export/sheet",
|
||||
"//java/google/registry/model",
|
||||
|
|
|
@ -1,445 +0,0 @@
|
|||
// Copyright 2017 The Nomulus Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package google.registry.ui.server.registrar;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.testing.DatastoreHelper.loadRegistrar;
|
||||
import static google.registry.testing.ReflectiveFieldExtractor.extractField;
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.braintreegateway.BraintreeGateway;
|
||||
import com.braintreegateway.Result;
|
||||
import com.braintreegateway.Transaction;
|
||||
import com.braintreegateway.Transaction.GatewayRejectionReason;
|
||||
import com.braintreegateway.TransactionGateway;
|
||||
import com.braintreegateway.TransactionRequest;
|
||||
import com.braintreegateway.ValidationError;
|
||||
import com.braintreegateway.ValidationErrorCode;
|
||||
import com.braintreegateway.ValidationErrors;
|
||||
import com.google.appengine.api.users.User;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import google.registry.request.auth.AuthLevel;
|
||||
import google.registry.request.auth.AuthResult;
|
||||
import google.registry.request.auth.UserAuthInfo;
|
||||
import google.registry.testing.AppEngineRule;
|
||||
import google.registry.testing.MockitoJUnitRule;
|
||||
import java.math.BigDecimal;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import org.joda.money.CurrencyUnit;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.Mock;
|
||||
|
||||
/** Tests for {@link RegistrarPaymentAction}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class RegistrarPaymentActionTest {
|
||||
|
||||
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
|
||||
@Rule public final MockitoJUnitRule mocks = MockitoJUnitRule.create();
|
||||
|
||||
@Mock private BraintreeGateway braintreeGateway;
|
||||
@Mock private TransactionGateway transactionGateway;
|
||||
@Mock private Result<Transaction> result;
|
||||
@Mock private Transaction transaction;
|
||||
@Mock private ValidationErrors validationErrors;
|
||||
@Captor private ArgumentCaptor<TransactionRequest> transactionRequestCaptor;
|
||||
|
||||
private final SessionUtils sessionUtils = mock(SessionUtils.class);
|
||||
private final User user = new User("marla.singer@example.com", "gmail.com", "12345");
|
||||
private final RegistrarPaymentAction paymentAction = new RegistrarPaymentAction();
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
paymentAction.sessionUtils = sessionUtils;
|
||||
paymentAction.authResult = AuthResult.create(AuthLevel.USER, UserAuthInfo.create(user, false));
|
||||
paymentAction.accountIds =
|
||||
ImmutableMap.of(
|
||||
CurrencyUnit.USD, "merchant-account-usd",
|
||||
CurrencyUnit.JPY, "merchant-account-jpy");
|
||||
paymentAction.braintreeGateway = braintreeGateway;
|
||||
when(braintreeGateway.transaction()).thenReturn(transactionGateway);
|
||||
when(transactionGateway.sale(any(TransactionRequest.class))).thenReturn(result);
|
||||
when(sessionUtils.getRegistrarForAuthResult(
|
||||
any(HttpServletRequest.class), any(AuthResult.class)))
|
||||
.thenReturn(loadRegistrar("TheRegistrar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCurrencyIsUsd_usesAmericanMerchantAccount() throws Exception {
|
||||
when(result.isSuccess()).thenReturn(true);
|
||||
when(result.getTarget()).thenReturn(transaction);
|
||||
when(transaction.getId()).thenReturn("omg-im-an-id");
|
||||
when(transaction.getAmount()).thenReturn(BigDecimal.valueOf(123.4));
|
||||
when(transaction.getCurrencyIsoCode()).thenReturn("USD");
|
||||
assertThat(
|
||||
paymentAction.handleJsonRequest(
|
||||
ImmutableMap.of(
|
||||
"amount", " 123.4 ",
|
||||
"currency", "USD",
|
||||
"paymentMethodNonce", "abc-123")))
|
||||
.containsExactly(
|
||||
"status", "SUCCESS",
|
||||
"message", "Payment processed successfully",
|
||||
"results", asList(
|
||||
ImmutableMap.of(
|
||||
"id", "omg-im-an-id",
|
||||
"formattedAmount", "$123.40")));
|
||||
verify(transactionGateway).sale(transactionRequestCaptor.capture());
|
||||
TransactionRequest transactionRequest = transactionRequestCaptor.getAllValues().get(0);
|
||||
assertThat(extractField(BigDecimal.class, transactionRequest, "amount"))
|
||||
.isEqualTo(BigDecimal.valueOf(123.4).setScale(2));
|
||||
assertThat(extractField(String.class, transactionRequest, "merchantAccountId"))
|
||||
.isEqualTo("merchant-account-usd");
|
||||
assertThat(extractField(String.class, transactionRequest, "customerId"))
|
||||
.isEqualTo("TheRegistrar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCurrencyIsJpy_usesJapaneseMerchantAccount() throws Exception {
|
||||
when(result.isSuccess()).thenReturn(true);
|
||||
when(result.getTarget()).thenReturn(transaction);
|
||||
when(transaction.getId()).thenReturn("omg-im-an-id");
|
||||
when(transaction.getAmount()).thenReturn(BigDecimal.valueOf(123));
|
||||
when(transaction.getCurrencyIsoCode()).thenReturn("JPY");
|
||||
assertThat(
|
||||
paymentAction.handleJsonRequest(
|
||||
ImmutableMap.of(
|
||||
"amount", "123",
|
||||
"currency", "JPY",
|
||||
"paymentMethodNonce", "abc-123")))
|
||||
.containsExactly(
|
||||
"status", "SUCCESS",
|
||||
"message", "Payment processed successfully",
|
||||
"results", asList(
|
||||
ImmutableMap.of(
|
||||
"id", "omg-im-an-id",
|
||||
"formattedAmount", "JPY 123")));
|
||||
verify(transactionGateway).sale(transactionRequestCaptor.capture());
|
||||
TransactionRequest transactionRequest = transactionRequestCaptor.getAllValues().get(0);
|
||||
assertThat(extractField(BigDecimal.class, transactionRequest, "amount"))
|
||||
.isEqualTo(BigDecimal.valueOf(123));
|
||||
assertThat(extractField(String.class, transactionRequest, "merchantAccountId"))
|
||||
.isEqualTo("merchant-account-jpy");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAmountNotPresent_returnsErrorOnAmountField() {
|
||||
assertThat(
|
||||
paymentAction.handleJsonRequest(
|
||||
ImmutableMap.of(
|
||||
"currency", "JPY",
|
||||
"paymentMethodNonce", "abc-123")))
|
||||
.containsExactly(
|
||||
"status", "ERROR",
|
||||
"message", "This field is required.",
|
||||
"field", "amount",
|
||||
"results", asList());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAmountNotNumber_returnsErrorOnAmountField() {
|
||||
assertThat(
|
||||
paymentAction.handleJsonRequest(
|
||||
ImmutableMap.of(
|
||||
"amount", "abc",
|
||||
"currency", "JPY",
|
||||
"paymentMethodNonce", "abc-123")))
|
||||
.containsExactly(
|
||||
"status", "ERROR",
|
||||
"message", "Invalid number.",
|
||||
"field", "amount",
|
||||
"results", asList());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNegativeAmount_returnsErrorOnAmountField() {
|
||||
assertThat(
|
||||
paymentAction.handleJsonRequest(
|
||||
ImmutableMap.of(
|
||||
"amount", "-10",
|
||||
"currency", "JPY",
|
||||
"paymentMethodNonce", "abc-123")))
|
||||
.containsExactly(
|
||||
"status", "ERROR",
|
||||
"message", "Must be a positive number.",
|
||||
"field", "amount",
|
||||
"results", asList());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZeroAmount_returnsErrorOnAmountField() {
|
||||
assertThat(
|
||||
paymentAction.handleJsonRequest(
|
||||
ImmutableMap.of(
|
||||
"amount", "0",
|
||||
"currency", "JPY",
|
||||
"paymentMethodNonce", "abc-123")))
|
||||
.containsExactly(
|
||||
"status", "ERROR",
|
||||
"message", "Must be a positive number.",
|
||||
"field", "amount",
|
||||
"results", asList());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAmountHasMorePrecisionThanUsdCurrencyAllows_returnsError() {
|
||||
assertThat(
|
||||
paymentAction.handleJsonRequest(
|
||||
ImmutableMap.of(
|
||||
"amount", "123.456",
|
||||
"currency", "USD",
|
||||
"paymentMethodNonce", "abc-123")))
|
||||
.containsExactly(
|
||||
"status", "ERROR",
|
||||
"message", "Scale of amount 123.456 is greater than the scale of the currency USD",
|
||||
"field", "amount",
|
||||
"results", asList());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAmountHasMorePrecisionThanJpyCurrencyAllows_returnsError() {
|
||||
assertThat(
|
||||
paymentAction.handleJsonRequest(
|
||||
ImmutableMap.of(
|
||||
"amount", "1.1",
|
||||
"currency", "JPY",
|
||||
"paymentMethodNonce", "abc-123")))
|
||||
.containsExactly(
|
||||
"status", "ERROR",
|
||||
"message", "Scale of amount 1.1 is greater than the scale of the currency JPY",
|
||||
"field", "amount",
|
||||
"results", asList());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCurrencyValidButNotSupported_returnsErrorOnCurrencyField() {
|
||||
assertThat(
|
||||
paymentAction.handleJsonRequest(
|
||||
ImmutableMap.of(
|
||||
"amount", "123",
|
||||
"currency", "EUR",
|
||||
"paymentMethodNonce", "abc-123")))
|
||||
.containsExactly(
|
||||
"status", "ERROR",
|
||||
"message", "Unsupported currency.",
|
||||
"field", "currency",
|
||||
"results", asList());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCurrencyBogus_returnsErrorOnCurrencyField() {
|
||||
assertThat(
|
||||
paymentAction.handleJsonRequest(
|
||||
ImmutableMap.of(
|
||||
"amount", "123",
|
||||
"currency", "rm -rf /etc/passwd",
|
||||
"paymentMethodNonce", "abc-123")))
|
||||
.containsExactly(
|
||||
"status", "ERROR",
|
||||
"message", "Invalid currency code.",
|
||||
"field", "currency",
|
||||
"results", asList());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCurrencyCodeNotAssigned_returnsErrorOnCurrencyField() {
|
||||
assertThat(
|
||||
paymentAction.handleJsonRequest(
|
||||
ImmutableMap.of(
|
||||
"amount", "123",
|
||||
"currency", "ZZZ",
|
||||
"paymentMethodNonce", "abc-123")))
|
||||
.containsExactly(
|
||||
"status", "ERROR",
|
||||
"message", "Unknown ISO currency code.",
|
||||
"field", "currency",
|
||||
"results", asList());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCurrencyMissing_returnsErrorOnCurrencyField() {
|
||||
assertThat(
|
||||
paymentAction.handleJsonRequest(
|
||||
ImmutableMap.of(
|
||||
"amount", "123",
|
||||
"paymentMethodNonce", "omg")))
|
||||
.containsExactly(
|
||||
"status", "ERROR",
|
||||
"message", "This field is required.",
|
||||
"field", "currency",
|
||||
"results", asList());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPaymentMethodMissing_returnsErrorOnPaymentMethodField() {
|
||||
assertThat(
|
||||
paymentAction.handleJsonRequest(
|
||||
ImmutableMap.of(
|
||||
"amount", "123",
|
||||
"currency", "JPY")))
|
||||
.containsExactly(
|
||||
"status", "ERROR",
|
||||
"message", "This field is required.",
|
||||
"field", "paymentMethodNonce",
|
||||
"results", asList());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcessorDeclined_returnsErrorResponse() {
|
||||
when(result.isSuccess()).thenReturn(false);
|
||||
when(result.getTransaction()).thenReturn(transaction);
|
||||
when(transaction.getStatus()).thenReturn(Transaction.Status.PROCESSOR_DECLINED);
|
||||
when(transaction.getProcessorResponseText())
|
||||
.thenReturn("You don't know the power of the dark side");
|
||||
assertThat(
|
||||
paymentAction.handleJsonRequest(
|
||||
ImmutableMap.of(
|
||||
"amount", "123",
|
||||
"currency", "USD",
|
||||
"paymentMethodNonce", "abc-123")))
|
||||
.containsExactly(
|
||||
"status", "ERROR",
|
||||
"message", "Payment declined: You don't know the power of the dark side",
|
||||
"results", asList());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGatewayRejectedDueToCvv_returnsErrorResponse() {
|
||||
when(result.isSuccess()).thenReturn(false);
|
||||
when(result.getTransaction()).thenReturn(transaction);
|
||||
when(transaction.getStatus()).thenReturn(Transaction.Status.GATEWAY_REJECTED);
|
||||
when(transaction.getGatewayRejectionReason()).thenReturn(GatewayRejectionReason.CVV);
|
||||
assertThat(
|
||||
paymentAction.handleJsonRequest(
|
||||
ImmutableMap.of(
|
||||
"amount", "123",
|
||||
"currency", "USD",
|
||||
"paymentMethodNonce", "abc-123")))
|
||||
.containsExactly(
|
||||
"status", "ERROR",
|
||||
"message", "Payment rejected: Invalid CVV code.",
|
||||
"results", asList());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGatewayRejectedDueToAddress_returnsErrorResponse() {
|
||||
when(result.isSuccess()).thenReturn(false);
|
||||
when(result.getTransaction()).thenReturn(transaction);
|
||||
when(transaction.getStatus()).thenReturn(Transaction.Status.GATEWAY_REJECTED);
|
||||
when(transaction.getGatewayRejectionReason()).thenReturn(GatewayRejectionReason.AVS);
|
||||
assertThat(
|
||||
paymentAction.handleJsonRequest(
|
||||
ImmutableMap.of(
|
||||
"amount", "123",
|
||||
"currency", "USD",
|
||||
"paymentMethodNonce", "abc-123")))
|
||||
.containsExactly(
|
||||
"status", "ERROR",
|
||||
"message", "Payment rejected: Invalid address.",
|
||||
"results", asList());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSettlementDeclined_returnsErrorResponse() {
|
||||
when(result.isSuccess()).thenReturn(false);
|
||||
when(result.getTransaction()).thenReturn(transaction);
|
||||
when(transaction.getStatus()).thenReturn(Transaction.Status.SETTLEMENT_DECLINED);
|
||||
when(transaction.getProcessorSettlementResponseText())
|
||||
.thenReturn("mine eyes have seen the glory of the coming of the borg");
|
||||
assertThat(
|
||||
paymentAction.handleJsonRequest(
|
||||
ImmutableMap.of(
|
||||
"amount", "123",
|
||||
"currency", "USD",
|
||||
"paymentMethodNonce", "abc-123")))
|
||||
.containsExactly(
|
||||
"status", "ERROR",
|
||||
"message", "Payment declined: mine eyes have seen the glory of the coming of the borg",
|
||||
"results", asList());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHasTransactionObjectWithWeirdStatus_returnsErrorResponse() {
|
||||
when(result.isSuccess()).thenReturn(false);
|
||||
when(result.getTransaction()).thenReturn(transaction);
|
||||
when(transaction.getStatus()).thenReturn(Transaction.Status.UNRECOGNIZED);
|
||||
when(transaction.getProcessorResponseText())
|
||||
.thenReturn("he is preempting the instance where the deadlocked shards are stored");
|
||||
assertThat(
|
||||
paymentAction.handleJsonRequest(
|
||||
ImmutableMap.of(
|
||||
"amount", "123",
|
||||
"currency", "USD",
|
||||
"paymentMethodNonce", "abc-123")))
|
||||
.containsExactly(
|
||||
"status", "ERROR",
|
||||
"message", "Payment failure: "
|
||||
+ "he is preempting the instance where the deadlocked shards are stored",
|
||||
"results", asList());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailedWithWeirdStatusButNoHelpfulText_usesWeirdStatusAsMsg() {
|
||||
when(result.isSuccess()).thenReturn(false);
|
||||
when(result.getTransaction()).thenReturn(transaction);
|
||||
when(transaction.getStatus()).thenReturn(Transaction.Status.FAILED);
|
||||
assertThat(
|
||||
paymentAction.handleJsonRequest(
|
||||
ImmutableMap.of(
|
||||
"amount", "123",
|
||||
"currency", "USD",
|
||||
"paymentMethodNonce", "abc-123")))
|
||||
.containsExactly(
|
||||
"status", "ERROR",
|
||||
"message", "Payment failure: FAILED",
|
||||
"results", asList());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoteValidationError_showsErrorOnlyOnFirstFormField() {
|
||||
when(result.isSuccess()).thenReturn(false);
|
||||
when(result.getErrors()).thenReturn(validationErrors);
|
||||
when(validationErrors.getAllDeepValidationErrors())
|
||||
.thenReturn(asList(
|
||||
new ValidationError(
|
||||
"amount",
|
||||
ValidationErrorCode.TRANSACTION_SETTLEMENT_AMOUNT_IS_LESS_THAN_SERVICE_FEE_AMOUNT,
|
||||
"Gimmeh moar moneys"),
|
||||
new ValidationError(
|
||||
"fax",
|
||||
ValidationErrorCode.CUSTOMER_FAX_IS_TOO_LONG,
|
||||
"Fax is too long")));
|
||||
assertThat(
|
||||
paymentAction.handleJsonRequest(
|
||||
ImmutableMap.of(
|
||||
"amount", "123",
|
||||
"currency", "USD",
|
||||
"paymentMethodNonce", "abc-123")))
|
||||
.containsExactly(
|
||||
"status", "ERROR",
|
||||
"message", "Gimmeh moar moneys",
|
||||
"field", "amount",
|
||||
"results", asList());
|
||||
}
|
||||
}
|
|
@ -1,122 +0,0 @@
|
|||
// Copyright 2017 The Nomulus Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package google.registry.ui.server.registrar;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.testing.DatastoreHelper.loadRegistrar;
|
||||
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.braintreegateway.BraintreeGateway;
|
||||
import com.braintreegateway.ClientTokenGateway;
|
||||
import com.google.appengine.api.users.User;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import google.registry.braintree.BraintreeRegistrarSyncer;
|
||||
import google.registry.model.registrar.Registrar;
|
||||
import google.registry.request.auth.AuthLevel;
|
||||
import google.registry.request.auth.AuthResult;
|
||||
import google.registry.request.auth.UserAuthInfo;
|
||||
import google.registry.testing.AppEngineRule;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import org.joda.money.CurrencyUnit;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
/** Tests for {@link RegistrarPaymentSetupAction}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class RegistrarPaymentSetupActionTest {
|
||||
|
||||
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
|
||||
|
||||
private final BraintreeGateway braintreeGateway = mock(BraintreeGateway.class);
|
||||
private final ClientTokenGateway clientTokenGateway = mock(ClientTokenGateway.class);
|
||||
private final BraintreeRegistrarSyncer customerSyncer = mock(BraintreeRegistrarSyncer.class);
|
||||
private final SessionUtils sessionUtils = mock(SessionUtils.class);
|
||||
|
||||
private final User user = new User("marla.singer@example.com", "gmail.com", "12345");
|
||||
private final RegistrarPaymentSetupAction action = new RegistrarPaymentSetupAction();
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
action.sessionUtils = sessionUtils;
|
||||
action.authResult = AuthResult.create(AuthLevel.USER, UserAuthInfo.create(user, false));
|
||||
action.braintreeGateway = braintreeGateway;
|
||||
action.customerSyncer = customerSyncer;
|
||||
Registrar registrar = persistResource(
|
||||
loadRegistrar("TheRegistrar")
|
||||
.asBuilder()
|
||||
.setBillingMethod(Registrar.BillingMethod.BRAINTREE)
|
||||
.build());
|
||||
when(sessionUtils.getRegistrarForAuthResult(
|
||||
any(HttpServletRequest.class), any(AuthResult.class)))
|
||||
.thenReturn(registrar);
|
||||
when(braintreeGateway.clientToken()).thenReturn(clientTokenGateway);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTokenGeneration() {
|
||||
action.brainframe = "/doodle";
|
||||
action.accountIds =
|
||||
ImmutableMap.of(
|
||||
CurrencyUnit.USD, "sorrow",
|
||||
CurrencyUnit.JPY, "torment");
|
||||
String blanketsOfSadness = "our hearts are beating, but no one is breathing";
|
||||
when(clientTokenGateway.generate()).thenReturn(blanketsOfSadness);
|
||||
assertThat(action.handleJsonRequest(ImmutableMap.of()))
|
||||
.containsExactly(
|
||||
"status", "SUCCESS",
|
||||
"message", "Success",
|
||||
"results", asList(
|
||||
ImmutableMap.of(
|
||||
"token", blanketsOfSadness,
|
||||
"currencies", asList("USD", "JPY"),
|
||||
"brainframe", "/doodle")));
|
||||
verify(customerSyncer).sync(eq(loadRegistrar("TheRegistrar")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonEmptyRequestObject_returnsError() {
|
||||
assertThat(action.handleJsonRequest(ImmutableMap.of("oh", "no")))
|
||||
.containsExactly(
|
||||
"status", "ERROR",
|
||||
"message", "JSON request object must be empty",
|
||||
"results", asList());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotOnCreditCardBillingTerms_showsErrorPage() {
|
||||
Registrar registrar = persistResource(
|
||||
loadRegistrar("TheRegistrar")
|
||||
.asBuilder()
|
||||
.setBillingMethod(Registrar.BillingMethod.EXTERNAL)
|
||||
.build());
|
||||
when(sessionUtils.getRegistrarForAuthResult(
|
||||
any(HttpServletRequest.class), any(AuthResult.class)))
|
||||
.thenReturn(registrar);
|
||||
assertThat(action.handleJsonRequest(ImmutableMap.of()))
|
||||
.containsExactly(
|
||||
"status", "ERROR",
|
||||
"message", "not-using-cc-billing",
|
||||
"results", asList());
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue