summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/payment-method-basic-card/empty-data-manual.https.html
blob: ba881ee2366c49aa15799767892c5ed847e41ac3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<!doctype html>
<meta charset="utf8">
<title>Payment Method Basic Card - test passing empty BasicCardRequest members</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
setup({ explicit_done: true, explicit_timeout: true });

const amount = { value: "1.0", currency: "USD" };
const details = {
  total: {
    label: "Total",
    amount,
  },
};
const method = {
  supportedMethods: "basic-card",
};

const defaultBillingAddress = {
  country: 'AF',
  addressLine: '1 wpt street',
  region: '',
  city: 'Kabul',
  dependentLocality: '',
  postalCode: '1001',
  sortingCode: '',
  organization: 'w3c',
  recipient: 'web platform test',
  phone: '+93555555555',
};

const visaCredit = {
  cardNumber: "4111111111111111",
  cardSecurityCode: "123",
  cardholderName: "web platform test",
  expiryMonth: "01",
  expiryYear: "2026",
};

async function getCardResponse(data) {
  const payMethod = Object.assign({ data }, method);
  const response = await new PaymentRequest([payMethod], details).show();
  await response.complete("success");
  return response.details;
}

/**
 * All tests expect the same return data, so we can just check the
 * same result over and over again.
 */
function runPromiseTest(button, data, expectedCard = visaCredit, expectedAddress = defaultBillingAddress ) {
  button.disabled = true;
  promise_test(async () => {
    const card = await getCardResponse(data);
    for (const [member, expectedValue] of Object.entries(expectedCard)) {
      const msg = `Expected "card.${member}" to equal "${expectedValue}".`;
      assert_equals(card[member], expectedValue, msg);
    }
    const { billingAddress } = card;
    for (const [member, expectedValue] of Object.entries(expectedAddress)) {
      const msg = `billingAddress.${member} to equal ${expectedValue}.`;
      assert_equals(billingAddress[member], expectedValue);
    }
  }, button.textContent.trim());
}
</script>
<h2>
  Payment Method Basic Card - test passing empty BasicCardRequest values
</h2>
<p>
  This test checks that the Basic Card payment handler can accept any card.
</p>
<p>
  Click on each button in sequence from top to bottom without refreshing the page.
  Each button will bring up the Payment Request UI window.
  The test expects the following credit card.
</p>
<ol>
  <li>Add card:
    <dl>
      <dt>Cardholder name:</dt>
      <dd>web platform test</dd>
      <dt>Card number:</dt>
      <dd>4111111111111111</dd>
      <dt>Security code (CVV):</dt>
      <dd>123</dd>
      <dt>Expiry month:</dt>
      <dd>01</dd>
      <dt>Expiry year:</dt>
      <dd>2026</dd>
    </dl>
  </li>
  <li>Add billing address:
    <dl>
      <dt>Recipient:</dt>
      <dd>web platform test</dd>
      <dt>Address:</dt>
      <dd>1 web st</dd>
      <dt>Post code:</dt>
      <dd>1234</dd>
      <dt>Country:</dt>
      <dd>Afghanistan</dd>
      <dt>City:</dt>
      <dd>w3c</dd>
      <dt>Phone</dt>
      <dd>+12345678910</dd>
    </dl>
  </li>
</ol>
<hr>
<ol>
  <li>
    <button onclick="runPromiseTest(this, {});">
      When passed BasicCardRequest without members, allow the user to input a card on any network.
    </button>
  </li>
  <li>
    <button onclick="runPromiseTest(this, { supportedNetworks: [] });">
      Returns a card on any network, because zero length supportedNetworks.
    </button>
  </li>
  <li>
    <button onclick="done();">
      Done!
    </button>
  </li>
</ol>

<small>
  If you find a buggy test, please <a href="https://github.com/web-platform-tests/wpt/issues">file a bug</a>
  and tag one of the <a href="https://github.com/web-platform-tests/wpt/blob/master/payment-request/META.yml">suggested reviewers</a>.
</small>