Skip to content

Commit 64461ac

Browse files
authored
Fix deletion check in relation (#100)
1 parent ef92ebe commit 64461ac

File tree

3 files changed

+47
-4
lines changed

3 files changed

+47
-4
lines changed

sqlite_export_for_ynab/ddl/create-relations.sql

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,7 @@ LEFT JOIN subtransactions AS st
189189
)
190190
WHERE
191191
TRUE
192-
AND NOT t.deleted
193-
AND NOT st.deleted
192+
AND NOT COALESCE(st.deleted, t.deleted)
194193
;
195194

196195
CREATE TABLE IF NOT EXISTS scheduled_transactions (
@@ -277,6 +276,5 @@ LEFT JOIN scheduled_subtransactions AS st
277276
)
278277
WHERE
279278
TRUE
280-
AND NOT t.deleted
281-
AND NOT st.deleted
279+
AND NOT COALESCE(st.deleted, t.deleted)
282280
;

testing/fixtures.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123

124124
TRANSACTION_ID_1 = str(uuid4())
125125
TRANSACTION_ID_2 = str(uuid4())
126+
TRANSACTION_ID_3 = str(uuid4())
126127

127128
SUBTRANSACTION_ID_1 = str(uuid4())
128129
SUBTRANSACTION_ID_2 = str(uuid4())
@@ -155,10 +156,18 @@
155156
"deleted": True,
156157
"subtransactions": [],
157158
},
159+
{
160+
"id": TRANSACTION_ID_3,
161+
"date": "2024-03-01",
162+
"amount": -19000,
163+
"deleted": False,
164+
"subtransactions": [],
165+
},
158166
]
159167

160168
SCHEDULED_TRANSACTION_ID_1 = str(uuid4())
161169
SCHEDULED_TRANSACTION_ID_2 = str(uuid4())
170+
SCHEDULED_TRANSACTION_ID_3 = str(uuid4())
162171

163172
SCHEDULED_SUBTRANSACTION_ID_1 = str(uuid4())
164173
SCHEDULED_SUBTRANSACTION_ID_2 = str(uuid4())
@@ -189,6 +198,12 @@
189198
"deleted": True,
190199
"subtransactions": [],
191200
},
201+
{
202+
"id": SCHEDULED_TRANSACTION_ID_3,
203+
"amount": -9000,
204+
"deleted": False,
205+
"subtransactions": [],
206+
},
192207
]
193208

194209

tests/_main_test.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
from testing.fixtures import SCHEDULED_SUBTRANSACTION_ID_2
6262
from testing.fixtures import SCHEDULED_TRANSACTION_ID_1
6363
from testing.fixtures import SCHEDULED_TRANSACTION_ID_2
64+
from testing.fixtures import SCHEDULED_TRANSACTION_ID_3
6465
from testing.fixtures import SCHEDULED_TRANSACTIONS
6566
from testing.fixtures import SCHEDULED_TRANSACTIONS_ENDPOINT_RE
6667
from testing.fixtures import SERVER_KNOWLEDGE_1
@@ -70,6 +71,7 @@
7071
from testing.fixtures import TOKEN
7172
from testing.fixtures import TRANSACTION_ID_1
7273
from testing.fixtures import TRANSACTION_ID_2
74+
from testing.fixtures import TRANSACTION_ID_3
7375
from testing.fixtures import TRANSACTIONS
7476
from testing.fixtures import TRANSACTIONS_ENDPOINT_RE
7577

@@ -251,6 +253,13 @@ def test_insert_transactions(cur):
251253
"amount": -15000,
252254
"deleted": True,
253255
},
256+
{
257+
"id": TRANSACTION_ID_3,
258+
"budget_id": BUDGET_ID_1,
259+
"date": "2024-03-01",
260+
"amount": -19000,
261+
"deleted": False,
262+
},
254263
]
255264

256265
cur.execute("SELECT * FROM subtransactions ORDER BY amount")
@@ -273,6 +282,14 @@ def test_insert_transactions(cur):
273282

274283
cur.execute("SELECT * FROM flat_transactions ORDER BY amount")
275284
assert [strip_nones(d) for d in cur.fetchall()] == [
285+
{
286+
"transaction_id": TRANSACTION_ID_3,
287+
"budget_id": BUDGET_ID_1,
288+
"date": "2024-03-01",
289+
"id": TRANSACTION_ID_3,
290+
"amount": -19000,
291+
"amount_major": pytest.approx(19),
292+
},
276293
{
277294
"transaction_id": TRANSACTION_ID_1,
278295
"subtransaction_id": SUBTRANSACTION_ID_1,
@@ -315,6 +332,12 @@ def test_insert_scheduled_transactions(cur):
315332
"amount": -11000,
316333
"deleted": True,
317334
},
335+
{
336+
"id": SCHEDULED_TRANSACTION_ID_3,
337+
"budget_id": BUDGET_ID_1,
338+
"amount": -9000,
339+
"deleted": False,
340+
},
318341
]
319342

320343
cur.execute("SELECT * FROM scheduled_subtransactions ORDER BY amount")
@@ -337,6 +360,13 @@ def test_insert_scheduled_transactions(cur):
337360

338361
cur.execute("SELECT * FROM scheduled_flat_transactions ORDER BY amount")
339362
assert [strip_nones(d) for d in cur.fetchall()] == [
363+
{
364+
"transaction_id": SCHEDULED_TRANSACTION_ID_3,
365+
"budget_id": BUDGET_ID_1,
366+
"id": SCHEDULED_TRANSACTION_ID_3,
367+
"amount": -9000,
368+
"amount_major": pytest.approx(9),
369+
},
340370
{
341371
"transaction_id": SCHEDULED_TRANSACTION_ID_1,
342372
"subtransaction_id": SCHEDULED_SUBTRANSACTION_ID_1,

0 commit comments

Comments
 (0)