@@ -56,3 +56,61 @@ def test_toggle_complete_on_complete_task(client, completed_task):
56
56
"is_complete" : False
57
57
}
58
58
}
59
+ assert Task .query .get (1 ).completed_at == None
60
+
61
+
62
+ # Let's add this test for creating tasks, now that
63
+ # the completion functionality has been implemented
64
+ def test_create_task_with_valid_completed_at (client ):
65
+ # Act
66
+ response = client .post ("/tasks" , json = {
67
+ "title" : "A Brand New Task" ,
68
+ "description" : "Test Description" ,
69
+ "completed_at" : datetime .utcnow ()
70
+ })
71
+ response_body = response .get_json ()
72
+
73
+ # Assert
74
+ assert response .status_code == 201
75
+ assert "task" in response_body
76
+ assert response_body == {
77
+ "task" : {
78
+ "id" : 1 ,
79
+ "title" : "A Brand New Task" ,
80
+ "description" : "Test Description" ,
81
+ "is_complete" : True
82
+ }
83
+ }
84
+ new_task = Task .query .get (1 )
85
+ assert new_task
86
+ assert new_task .title == "A Brand New Task"
87
+ assert new_task .description == "Test Description"
88
+ assert new_task .completed_at
89
+
90
+
91
+ # Let's add this test for updating tasks, now that
92
+ # the completion functionality has been implemented
93
+ def test_update_task_with_completed_at_date (client , completed_task ):
94
+ # Act
95
+ response = client .put ("/tasks/1" , json = {
96
+ "title" : "Updated Task Title" ,
97
+ "description" : "Updated Test Description" ,
98
+ "completed_at" : datetime .utcnow ()
99
+ })
100
+ response_body = response .get_json ()
101
+
102
+ # Assert
103
+ assert response .status_code == 200
104
+ assert "task" in response_body
105
+ assert response_body == {
106
+ "task" : {
107
+ "id" : 1 ,
108
+ "title" : "Updated Task Title" ,
109
+ "description" : "Updated Test Description" ,
110
+ "is_complete" : True
111
+ }
112
+ }
113
+ task = Task .query .get (1 )
114
+ assert task .title == "Updated Task Title"
115
+ assert task .description == "Updated Test Description"
116
+ assert task .completed_at
0 commit comments