Skip to content

Commit e65c348

Browse files
authored
[MPT-14923] Added e2e tests for commerce credit memos (#191)
Added e2e tests for commerce credit memos Data can't be seeded because it comes from Nav, but operations have data already there. Not ideal, but it's something. https://softwareone.atlassian.net/browse/MPT-14923 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> Closes [MPT-14923](https://softwareone.atlassian.net/browse/MPT-14923) - Add end-to-end tests for commerce credit memos in billing - Add async credit memo test module (tests/e2e/billing/credit_memo/test_async_credit_memo.py) with tests for: get by ID, 404 not-found, list (fetch_page), and filter + iterate using RQLQuery - Add sync credit memo test module (tests/e2e/billing/credit_memo/test_sync_credit_memo.py) with tests for: get by ID, 404 not-found, list (fetch_page), and filter + iterate using RQLQuery - Add fixture invalid_credit_memo_id in tests/e2e/billing/credit_memo/conftest.py returning "CRD-0000-0000-0000-0000" - Add fixtures credit_memos and credit_memo to fetch sample data for tests - Mark credit memo tests as flaky; tests rely on existing data present in the system (no seed data) <!-- end of auto-generated comment: release notes by coderabbit.ai --> [MPT-14923]: https://softwareone.atlassian.net/browse/MPT-14923?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
2 parents 9879263 + 644a970 commit e65c348

File tree

3 files changed

+124
-0
lines changed

3 files changed

+124
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import pytest
2+
3+
4+
@pytest.fixture
5+
def invalid_credit_memo_id():
6+
return "CRD-0000-0000-0000-0000"
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import pytest
2+
3+
from mpt_api_client.exceptions import MPTAPIError
4+
from mpt_api_client.rql.query_builder import RQLQuery
5+
6+
pytestmark = [pytest.mark.flaky]
7+
8+
9+
@pytest.fixture
10+
async def credit_memos(async_mpt_ops):
11+
limit = 1
12+
return await async_mpt_ops.billing.credit_memos.fetch_page(limit=limit)
13+
14+
15+
@pytest.fixture
16+
def credit_memo(credit_memos):
17+
if credit_memos:
18+
return credit_memos[0]
19+
return None
20+
21+
22+
async def test_get_credit_memo_by_id(async_mpt_ops, credit_memo):
23+
if credit_memo is None:
24+
pytest.skip("No credit memos available to test retrieval by ID.")
25+
credit_memo_id = credit_memo.id
26+
27+
result = await async_mpt_ops.billing.credit_memos.get(credit_memo_id)
28+
29+
assert result is not None
30+
31+
32+
async def test_get_credit_memo_by_id_not_found(async_mpt_ops, invalid_credit_memo_id):
33+
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
34+
await async_mpt_ops.billing.credit_memos.get(invalid_credit_memo_id)
35+
36+
37+
async def test_list_credit_memos(async_mpt_ops):
38+
limit = 10
39+
40+
result = await async_mpt_ops.billing.credit_memos.fetch_page(limit=limit)
41+
42+
assert len(result) > 0
43+
44+
45+
async def test_filter_credit_memos(async_mpt_ops, credit_memo):
46+
if credit_memo is None:
47+
pytest.skip("No credit memos available to test filtering.")
48+
credit_memo_id = credit_memo.id
49+
credit_memo_status = credit_memo.status
50+
select_fields = ["-vendor"]
51+
filtered_credit_memos = (
52+
async_mpt_ops.billing.credit_memos.filter(RQLQuery(id=credit_memo_id))
53+
.filter(RQLQuery(status=credit_memo_status))
54+
.select(*select_fields)
55+
)
56+
57+
result = [credit_memo async for credit_memo in filtered_credit_memos.iterate()]
58+
59+
assert len(result) == 1
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import pytest
2+
3+
from mpt_api_client.exceptions import MPTAPIError
4+
from mpt_api_client.rql.query_builder import RQLQuery
5+
6+
pytestmark = [pytest.mark.flaky]
7+
8+
9+
@pytest.fixture
10+
def credit_memos(mpt_ops):
11+
limit = 1
12+
return mpt_ops.billing.credit_memos.fetch_page(limit=limit)
13+
14+
15+
@pytest.fixture
16+
def credit_memo(credit_memos):
17+
if credit_memos:
18+
return credit_memos[0]
19+
return None
20+
21+
22+
def test_get_credit_memo_by_id(mpt_ops, credit_memo):
23+
if credit_memo is None:
24+
pytest.skip("No credit memos available to test retrieval by ID.")
25+
credit_memo_id = credit_memo.id
26+
27+
result = mpt_ops.billing.credit_memos.get(credit_memo_id)
28+
29+
assert result is not None
30+
31+
32+
def test_get_credit_memo_by_id_not_found(mpt_ops, invalid_credit_memo_id):
33+
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
34+
mpt_ops.billing.credit_memos.get(invalid_credit_memo_id)
35+
36+
37+
def test_list_credit_memos(mpt_ops):
38+
limit = 10
39+
40+
result = mpt_ops.billing.credit_memos.fetch_page(limit=limit)
41+
42+
assert len(result) > 0
43+
44+
45+
def test_filter_credit_memos(mpt_ops, credit_memo):
46+
if credit_memo is None:
47+
pytest.skip("No credit memos available to test filtering.")
48+
credit_memo_id = credit_memo.id
49+
credit_memo_status = credit_memo.status
50+
select_fields = ["-vendor"]
51+
filtered_credit_memos = (
52+
mpt_ops.billing.credit_memos.filter(RQLQuery(id=credit_memo_id))
53+
.filter(RQLQuery(status=credit_memo_status))
54+
.select(*select_fields)
55+
)
56+
57+
result = list(filtered_credit_memos.iterate())
58+
59+
assert len(result) == 1

0 commit comments

Comments
 (0)