Skip to content

Commit 0ad8dc7

Browse files
committed
fills out wave 6 to have the update tasks at post /goals/:id/tasks route
1 parent 4bbb7ec commit 0ad8dc7

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

ada-project-docs/wave_06.md

+26
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,32 @@ After learning the strategy for creating a one-to-many relationship, in the Task
4444
- Setting the foreign key to `goal`'s primary key column
4545
- Setting the `nullable` to `True`
4646

47+
Remember to run `flask db migrate` and `flask db upgrade` whenever there is a change to the model.
48+
49+
### Sending a List of Task IDs to a Goal
50+
51+
Given:
52+
53+
- a goal that has the ID `1`
54+
- three tasks with the IDs `1`, `2`, and `3`
55+
56+
When I send a `POST` request to `/goals/1/tasks` with this request body:
57+
58+
```json
59+
{
60+
"task_ids": [1, 2, 3]
61+
}
62+
```
63+
64+
Then the three `Task`s belong to the `Goal` and it gets updated in the database, and we get back a `200 OK` with the following response body:
65+
66+
```json
67+
{
68+
"id": 1,
69+
"task_ids": [1, 2, 3]
70+
}
71+
```
72+
4773
### Getting Tasks of One Goal
4874

4975
Given a goal that has:

tests/test_wave_06.py

+41
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,44 @@
1+
from app.models.goal import Goal
2+
3+
4+
def test_post_task_ids_to_goal(client, one_goal, three_tasks):
5+
# Act
6+
response = client.post("/goals/1/tasks", json={
7+
"task_ids": [1, 2, 3]
8+
})
9+
response_body = response.get_json()
10+
11+
# Assert
12+
assert response.status_code == 200
13+
assert "id" in response_body
14+
assert "task_ids" in response_body
15+
assert response_body == {
16+
"id": 1,
17+
"task_ids": [1, 2, 3]
18+
}
19+
20+
# Check that Goal was updated in the db
21+
assert len(Goal.query.get(1).tasks) == 3
22+
23+
24+
def test_post_task_ids_to_goal_already_with_goals(client, one_task_belongs_to_one_goal, three_tasks):
25+
# Act
26+
response = client.post("/goals/1/tasks", json={
27+
"task_ids": [1, 4]
28+
})
29+
response_body = response.get_json()
30+
31+
# Assert
32+
assert response.status_code == 200
33+
assert "id" in response_body
34+
assert "task_ids" in response_body
35+
assert response_body == {
36+
"id": 1,
37+
"task_ids": [1, 4]
38+
}
39+
assert len(Goal.query.get(1).tasks) == 2
40+
41+
142
def test_get_tasks_for_specific_goal_no_goal(client):
243
# Act
344
response = client.get("/goals/1/tasks")

0 commit comments

Comments
 (0)