Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit 65065a8

Browse files
committed
test(postgres): add test for update fallback to read
- Adds a test for the `update` method's edge case where no updatable fields are provided. - Verifies that the client correctly calls the `read` method as a fallback, preventing an empty SQL UPDATE statement.
1 parent 314c37d commit 65065a8

File tree

2 files changed

+50
-9
lines changed

2 files changed

+50
-9
lines changed

coverage/lcov.info

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ DA:137,4
5151
DA:138,1
5252
DA:140,4
5353
DA:141,1
54-
DA:145,0
55-
DA:154,0
56-
DA:155,0
54+
DA:145,1
55+
DA:154,1
56+
DA:155,1
5757
DA:164,1
5858
DA:173,2
5959
DA:174,2
@@ -77,7 +77,7 @@ DA:229,2
7777
DA:232,1
7878
DA:233,1
7979
DA:235,1
80-
DA:237,0
80+
DA:237,1
8181
DA:240,5
8282
DA:242,2
8383
DA:243,2
@@ -87,13 +87,13 @@ DA:249,1
8787
DA:251,2
8888
DA:252,1
8989
DA:256,1
90-
DA:257,0
91-
DA:258,0
90+
DA:257,1
91+
DA:258,1
9292
DA:261,4
9393
DA:262,4
9494
DA:263,1
95-
DA:265,0
96-
DA:266,0
95+
DA:265,4
96+
DA:266,1
9797
DA:271,1
9898
DA:272,1
9999
DA:275,1
@@ -154,5 +154,5 @@ DA:390,2
154154
DA:391,2
155155
DA:393,1
156156
LF:154
157-
LH:120
157+
LH:128
158158
end_of_record

test/src/ht_data_postgres_test.dart

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,47 @@ void main() {
298298
),
299299
).called(1);
300300
});
301+
302+
test('should throw NotFoundException if item to update is not found',
303+
() {
304+
final mockResult = MockResult();
305+
when(() => mockResult.isEmpty).thenReturn(true);
306+
when(
307+
() => mockConnection.execute(
308+
any(),
309+
parameters: any(named: 'parameters'),
310+
),
311+
).thenAnswer((_) async => mockResult);
312+
313+
expect(
314+
() => sut.update(id: '1', item: testModel),
315+
throwsA(isA<NotFoundException>()),
316+
);
317+
});
318+
319+
test('should call read when update data is empty', () async {
320+
final mockResult = MockResult();
321+
final mockResultRow = MockResultRow();
322+
when(() => mockResultRow.toColumnMap()).thenReturn(testModelJson);
323+
when(() => mockResult.isEmpty).thenReturn(false);
324+
when(() => mockResult.first).thenReturn(mockResultRow);
325+
when(
326+
() => mockConnection.execute(
327+
any(),
328+
parameters: any(named: 'parameters'),
329+
),
330+
).thenAnswer((_) async => mockResult);
331+
332+
final mockEmptyModel = MockTestModel();
333+
when(() => mockEmptyModel.toJson()).thenReturn({'id': '1'});
334+
335+
await sut.update(id: '1', item: mockEmptyModel);
336+
337+
// Verify that read was called by checking for the SELECT statement
338+
verify(
339+
() => mockLogger.fine(contains('Reading item with id "1"')),
340+
).called(1);
341+
});
301342
});
302343

303344
group('delete', () {

0 commit comments

Comments
 (0)