refactor(todo): 移除 due_at 字段,改用 order 字段管理象限内顺序

This commit is contained in:
qzl
2026-03-20 11:09:38 +08:00
parent d574128815
commit fbf15bc937
22 changed files with 1458 additions and 1524 deletions
@@ -27,6 +27,7 @@ void main() {
() async {
const todoId = 'todo-123';
const targetPriority = 2;
const targetOrder = 0;
when(
() => mockClient.patch(any(), data: any(named: 'data')),
@@ -38,6 +39,7 @@ void main() {
'owner_id': 'user-1',
'title': 'Test Todo',
'priority': targetPriority,
'order': targetOrder,
'status': 'pending',
'created_at': '2024-01-01T00:00:00Z',
'updated_at': '2024-01-01T00:00:00Z',
@@ -48,13 +50,15 @@ void main() {
final result = await todoApi.updateTodo(
todoId,
priority: targetPriority,
order: targetOrder,
);
expect(result.priority, targetPriority);
expect(result.order, targetOrder);
verify(
() => mockClient.patch(
'/api/v1/todos/$todoId',
data: {'priority': targetPriority},
data: {'priority': targetPriority, 'order': targetOrder},
),
).called(1);
},
@@ -67,7 +71,10 @@ void main() {
() => mockClient.patch(any(), data: any(named: 'data')),
).thenThrow(Exception('Network error'));
expect(() => todoApi.updateTodo(todoId, priority: 2), throwsException);
expect(
() => todoApi.updateTodo(todoId, priority: 2, order: 0),
throwsException,
);
});
});
@@ -81,6 +88,7 @@ void main() {
'owner_id': 'user-1',
'title': 'Q1 Todo',
'priority': 1,
'order': 1,
'status': 'pending',
'created_at': '2024-01-01T00:00:00Z',
'updated_at': '2024-01-01T00:00:00Z',
@@ -88,8 +96,9 @@ void main() {
),
);
final result = await todoApi.updateTodo('todo-1', priority: 1);
final result = await todoApi.updateTodo('todo-1', priority: 1, order: 1);
expect(result.priority, 1);
expect(result.order, 1);
});
test('priority 2 = important not urgent (Q3)', () async {
@@ -101,6 +110,7 @@ void main() {
'owner_id': 'user-1',
'title': 'Q3 Todo',
'priority': 2,
'order': 2,
'status': 'pending',
'created_at': '2024-01-01T00:00:00Z',
'updated_at': '2024-01-01T00:00:00Z',
@@ -108,8 +118,9 @@ void main() {
),
);
final result = await todoApi.updateTodo('todo-2', priority: 2);
final result = await todoApi.updateTodo('todo-2', priority: 2, order: 2);
expect(result.priority, 2);
expect(result.order, 2);
});
test('priority 3 = urgent not important (Q2)', () async {
@@ -121,6 +132,7 @@ void main() {
'owner_id': 'user-1',
'title': 'Q2 Todo',
'priority': 3,
'order': 0,
'status': 'pending',
'created_at': '2024-01-01T00:00:00Z',
'updated_at': '2024-01-01T00:00:00Z',
@@ -128,8 +140,37 @@ void main() {
),
);
final result = await todoApi.updateTodo('todo-3', priority: 3);
final result = await todoApi.updateTodo('todo-3', priority: 3, order: 0);
expect(result.priority, 3);
expect(result.order, 0);
});
});
group('TodoApi.reorderTodos', () {
test('calls batch reorder endpoint once', () async {
when(() => mockClient.patch(any(), data: any(named: 'data'))).thenAnswer(
(_) async => Response(
requestOptions: RequestOptions(path: '/api/v1/todos/reorder'),
data: {},
),
);
await todoApi.reorderTodos(const [
TodoReorderItemPayload(id: 'todo-1', priority: 1, order: 0),
TodoReorderItemPayload(id: 'todo-2', priority: 1, order: 1),
]);
verify(
() => mockClient.patch(
'/api/v1/todos/reorder',
data: {
'items': [
{'id': 'todo-1', 'priority': 1, 'order': 0},
{'id': 'todo-2', 'priority': 1, 'order': 1},
],
},
),
).called(1);
});
});
}