Skip to content

Commit 7da91e3

Browse files
committed
✅[#287] test djadyen styles settings
1 parent 123c9a6 commit 7da91e3

6 files changed

Lines changed: 102 additions & 2 deletions

File tree

djadyen/static/djadyen/djadyen.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

djadyen/templates/adyen/advanced_component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<div
55
id="djadyen-config"
66
data-amount="{{ amount | safe }}"
7-
data-client-key="{{ client_key }}"l
7+
data-client-key="{{ client_key }}"
88
data-country-code="{{ country_code }}"
99
data-csrf-token="{{ csrf_token }}"
1010
data-currency="{{ currency }}"

djadyen/templates/adyen/component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
data-session-id="{{ session_id }}"
77
data-session-data="{{ session_data }}"
88
data-client-key="{{ client_key }}"
9+
data-country-code="{{ country_code }}"
910
data-environment="{{ environment }}"
1011
data-redirect-url="{{ redirect_url }}"
1112
data-language="{{ language }}"

javascript/djadyen.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ document.addEventListener('DOMContentLoaded', async () => {
1313
environment: config.dataset.environment,
1414
clientKey: config.dataset.clientKey,
1515
locale: config.dataset.language,
16+
countryCode: config.dataset.countryCode,
1617
showPayButton: true,
1718
analytics: {
1819
enabled: false,

tests/conftest.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,30 @@ def mock_successful_payment_details_api(requests_mock):
7676

7777
requests_mock.post(matcher, json=success_response)
7878
return requests_mock
79+
80+
81+
@pytest.fixture
82+
def mock_sessions_api_success(requests_mock):
83+
"""
84+
Example Sessions api response v71 base on the adyen docs:
85+
https://docs.adyen.com/api-explorer/Checkout/71/post/sessions
86+
:param requests_mock:
87+
:return: requests_mock
88+
"""
89+
90+
matcher = re.compile(r"https://checkout-test\.adyen\.com/v[0-9]{2}/sessions")
91+
92+
# TODO: update with real /sessions success example
93+
success_response = {
94+
"amount": {"currency": "EUR", "value": 100},
95+
"countryCode": "NL",
96+
"expiresAt": "2022-01-11T13:53:18+01:00",
97+
"id": "CS451F2AB1ED897A94",
98+
"merchantAccount": "YOUR_MERCHANT_ACCOUNT",
99+
"reference": "YOUR_PAYMENT_REFERENCE",
100+
"returnUrl": "https://your-company.example.com/checkout?shopperOrder=12xy..",
101+
"sessionData": "Ab02b4c0!BQABAgBfYI29...",
102+
}
103+
104+
requests_mock.post(matcher, json=success_response, status_code=201)
105+
return requests_mock
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
from json import dumps
2+
3+
from django.template import Context, Template
4+
from django.utils.html import escape
5+
6+
from djadyen.settings import get_setting
7+
from tests.factories import OrderFactory
8+
9+
10+
def test_adyen_advanced_payment_component_no_styles(settings) -> None:
11+
"""
12+
Test donation component with a valid campaign
13+
:param donation_campaign_example: Example Donation Campaign
14+
"""
15+
16+
settings.DJADYEN_STYLES = None
17+
order = OrderFactory.build()
18+
19+
out = Template(
20+
"{% load adyen_tags %}"
21+
"{% adyen_advanced_payment_component language=adyen_language order=order %}" # noqa
22+
).render(
23+
Context(
24+
{
25+
"adyen_language": "en-US",
26+
"order": order,
27+
}
28+
)
29+
)
30+
31+
assert "data-styles=" not in out
32+
assert get_setting("DJADYEN_DEFAULT_COUNTRY_CODE") in out
33+
34+
35+
def test_adyen_advanced_payment_component_with_styles(settings) -> None:
36+
"""
37+
Test donation component with a valid campaign
38+
:param donation_campaign_example: Example Donation Campaign
39+
"""
40+
41+
settings.DJADYEN_STYLES = {
42+
"base": {
43+
"color": "#000000",
44+
"fontSize": "16px",
45+
"fontFamily": "Arial, sans-serif",
46+
},
47+
"placeholder": {
48+
"color": "#999999",
49+
},
50+
"error": {
51+
"color": "#ff0000",
52+
},
53+
}
54+
55+
order = OrderFactory.build()
56+
57+
out = Template(
58+
"{% load adyen_tags %}"
59+
"{% adyen_advanced_payment_component language=adyen_language order=order %}" # noqa
60+
).render(
61+
Context(
62+
{
63+
"adyen_language": "en-US",
64+
"order": order,
65+
}
66+
)
67+
)
68+
69+
assert "data-styles=" in out
70+
assert escape(dumps(settings.DJADYEN_STYLES)) in out
71+
assert get_setting("DJADYEN_DEFAULT_COUNTRY_CODE") in out

0 commit comments

Comments
 (0)