summaryrefslogtreecommitdiffstats
path: root/dom/payments/test/head.js
blob: 3a377e09ae0300fc98d26325b2fa8eae309f7ecc (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
const kTestRoot = getRootDirectory(gTestPath).replace(
  "chrome://mochitests/content",
  "https://example.com"
);

function checkSimplePayment(aSimplePayment) {
  // checking the passed PaymentMethods parameter
  is(
    aSimplePayment.paymentMethods.length,
    1,
    "paymentMethods' length should be 1."
  );

  const methodData = aSimplePayment.paymentMethods.queryElementAt(
    0,
    Ci.nsIPaymentMethodData
  );
  ok(methodData, "Fail to get payment methodData.");
  is(
    methodData.supportedMethods,
    "basic-card",
    "supported method should be 'basic-card'."
  );
  ok(!methodData.data, "methodData.data should not exist.");

  // checking the passed PaymentDetails parameter
  const details = aSimplePayment.paymentDetails;
  is(details.id, "simple details", "details.id should be 'simple details'.");
  is(
    details.totalItem.label,
    "Donation",
    "total item's label should be 'Donation'."
  );
  is(
    details.totalItem.amount.currency,
    "USD",
    "total item's currency should be 'USD'."
  );
  is(
    details.totalItem.amount.value,
    "55.00",
    "total item's value should be '55.00'."
  );

  is(
    details.displayItems.length,
    0,
    "details.displayItems should be a zero length array."
  );
  is(
    details.modifiers.length,
    0,
    "details.modifiers should be a zero length array."
  );
  is(
    details.shippingOptions.length,
    0,
    "details.shippingOptions should be a zero length array."
  );

  // checking the default generated PaymentOptions parameter
  const paymentOptions = aSimplePayment.paymentOptions;
  ok(!paymentOptions.requestPayerName, "payerName option should be false");
  ok(!paymentOptions.requestPayerEmail, "payerEmail option should be false");
  ok(!paymentOptions.requestPayerPhone, "payerPhone option should be false");
  ok(!paymentOptions.requestShipping, "requestShipping option should be false");
  is(
    paymentOptions.shippingType,
    "shipping",
    "shippingType option should be 'shipping'"
  );
}

function checkDupShippingOptionsPayment(aPayment) {
  // checking the passed PaymentMethods parameter
  is(aPayment.paymentMethods.length, 1, "paymentMethods' length should be 1.");

  const methodData = aPayment.paymentMethods.queryElementAt(
    0,
    Ci.nsIPaymentMethodData
  );
  ok(methodData, "Fail to get payment methodData.");
  is(
    methodData.supportedMethods,
    "basic-card",
    "methodData.supportedMethod name should be 'basic-card'."
  );
  ok(!methodData.data, "methodData.data should not exist.");

  // checking the passed PaymentDetails parameter
  const details = aPayment.paymentDetails;
  is(
    details.id,
    "duplicate shipping options details",
    "details.id should be 'duplicate shipping options details'."
  );
  is(
    details.totalItem.label,
    "Donation",
    "total item's label should be 'Donation'."
  );
  is(
    details.totalItem.amount.currency,
    "USD",
    "total item's currency should be 'USD'."
  );
  is(
    details.totalItem.amount.value,
    "55.00",
    "total item's value should be '55.00'."
  );

  const shippingOptions = details.shippingOptions;
  is(shippingOptions.length, 0, "shippingOptions' length should be 0.");

  // checking the passed PaymentOptions parameter
  const paymentOptions = aPayment.paymentOptions;
  ok(paymentOptions.requestPayerName, "payerName option should be true");
  ok(paymentOptions.requestPayerEmail, "payerEmail option should be true");
  ok(paymentOptions.requestPayerPhone, "payerPhone option should be true");
  ok(paymentOptions.requestShipping, "requestShipping option should be true");
  is(
    paymentOptions.shippingType,
    "shipping",
    "shippingType option should be 'shipping'"
  );
}