Skip to content

Commit 3531f64

Browse files
committed
splits toggle_complete into two endpoints, beefs up tests
1 parent fcc7050 commit 3531f64

File tree

3 files changed

+142
-11
lines changed

3 files changed

+142
-11
lines changed

ada-project-docs/wave_03.md

+60-4
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ The following route is required for wave 3.
2222
- JSON's value of `true` is similar to Python's value of `True`, and `false` is similar to Python's `False`.
2323
- JSON's value of `null` is similar to Python's value of `None`.
2424

25-
### Toggle Complete: Mark Complete on an Incomplete Task
25+
### Mark Complete on an Incompleted Task
2626

2727
Given a task that has:
2828

2929
- An id `1`
3030
- A `completed_at` attribute with a `null` value
3131

32-
when I send a `PATCH` request to `/tasks/1/complete`,
32+
when I send a `PATCH` request to `/tasks/1/mark_complete`,
3333

3434
then the task is updated, so that its `completed_at` value is the current date, and I get this response:
3535

@@ -46,14 +46,14 @@ then the task is updated, so that its `completed_at` value is the current date,
4646
}
4747
```
4848

49-
### Toggle Complete: Mark Complete on an Incomplete Task
49+
### Mark Incomplete on a Completed Task
5050

5151
Given a task that has:
5252

5353
- An id `1`
5454
- A `completed_at` attribute with a datetime value
5555

56-
when I send a `PATCH` request to `/tasks/1/complete`,
56+
when I send a `PATCH` request to `/tasks/1/mark_incomplete`,
5757

5858
then the task is updated, so that its `completed_at` value is `null`/`None`, and I get this response:
5959

@@ -69,3 +69,59 @@ then the task is updated, so that its `completed_at` value is `null`/`None`, and
6969
}
7070
}
7171
```
72+
73+
### Mark Complete on a Completed Task
74+
75+
Given a task that has:
76+
77+
- An id `1`
78+
- A `completed_at` attribute with a datetime value
79+
80+
when I send a `PATCH` request to `/tasks/1/mark_complete`,
81+
82+
then I want this to behave exactly like `/tasks/1/mark_complete` for an incomplete task. The task is updated, so that its `completed_at` value is the current date, and I get this response:
83+
84+
`200 OK`
85+
86+
```json
87+
{
88+
"task": {
89+
"id": 1,
90+
"title": "Go on my daily walk 🏞",
91+
"description": "Notice something new every day",
92+
"is_complete": true
93+
}
94+
}
95+
```
96+
97+
### Mark Incomplete on an Incompleted Task
98+
99+
Given a task that has:
100+
101+
- An id `1`
102+
- A `completed_at` attribute with a `null` value
103+
104+
when I send a `PATCH` request to `/tasks/1/mark_incomplete`,
105+
106+
then I want this to behave exactly like `/tasks/1/mark_complete` for an incomplete task. Its `completed_at` value remains as `null`/`None`, and I get this response:
107+
108+
`200 OK`
109+
110+
```json
111+
{
112+
"task": {
113+
"id": 1,
114+
"title": "Go on my daily walk 🏞",
115+
"description": "Notice something new every day",
116+
"is_complete": false
117+
}
118+
}
119+
```
120+
121+
## Mark Complete and Mark Incomplete for Missing Tasks
122+
123+
Given that there are no tasks with the ID `1`,
124+
125+
When I send a `PATCH` request to `/tasks/1/mark_complete` or a `PATCH` request `/tasks/1/mark_incomplete`,
126+
127+
Then I get a `404 Not Found`, with no response body.

ada-project-docs/wave_04.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ To complete this wave, follow these steps:
1515
1. Setup a Slack workspace and create a Slackbot with the right permissions, and get a Slackbot API key
1616
1. Verify that your Slackbot works using the Slack Tester
1717
1. Verify that your Slackbot works using Postman
18-
1. Modify the `/tasks/<task_id>/complete` route to make a call to the Slack API
18+
1. Modify the `/tasks/<task_id>/mark_complete` route to make a call to the Slack API
1919
1. Use Postman to verify your work
2020

2121
### Setup a Slack Workspace
@@ -95,15 +95,15 @@ Let's verify that this API call works even in Postman!
9595

9696
- We could put in the token as a query param. However, the Slack API documentation states that it prefers API keys to be sent in the "Authorization" request header.
9797

98-
### Modify `/tasks/<task_id>/complete` to Call the Slack API: Toggle Complete
98+
### Modify `/tasks/<task_id>/mark_complete` to Call the Slack API
9999

100100
Given a task that has:
101101

102102
- An id `1`
103103
- A `title` attribute with the value `"My Beautiful Task"`
104104
- A `completed_at` attribute with a `null` value
105105

106-
when I send a `PATCH` request to `/tasks/1/complete`,
106+
when I send a `PATCH` request to `/tasks/1/mark_complete`,
107107

108108
then a Slack message is immediately sent to the channel `task-notifications` in the configured Slack workspace, with the text `"Someone just completed the task My Beautiful Task"`. "My Beautiful Task" should be the title of the task.
109109

tests/test_wave_03.py

+79-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from app.models.task import Task
55

66

7-
def test_toggle_complete_on_incomplete_task(client, one_task):
7+
def test_mark_complete_on_incomplete_task(client, one_task):
88
# Arrange
99
"""
1010
The future Wave 4 adds special functionality to this route,
@@ -22,7 +22,7 @@ def test_toggle_complete_on_incomplete_task(client, one_task):
2222
mock_get.return_value.status_code = 200
2323

2424
# Act
25-
response = client.patch("/tasks/1/complete")
25+
response = client.patch("/tasks/1/mark_complete")
2626
response_body = response.get_json()
2727

2828
# Assert
@@ -40,9 +40,9 @@ def test_toggle_complete_on_incomplete_task(client, one_task):
4040
assert Task.query.get(1).completed_at
4141

4242

43-
def test_toggle_complete_on_complete_task(client, completed_task):
43+
def test_mark_incomplete_on_complete_task(client, completed_task):
4444
# Act
45-
response = client.patch("/tasks/1/complete")
45+
response = client.patch("/tasks/1/mark_incomplete")
4646
response_body = response.get_json()
4747

4848
# Assert
@@ -59,6 +59,81 @@ def test_toggle_complete_on_complete_task(client, completed_task):
5959
assert Task.query.get(1).completed_at == None
6060

6161

62+
def test_mark_complete_on_completed_task(client, completed_task):
63+
# Arrange
64+
"""
65+
The future Wave 4 adds special functionality to this route,
66+
so for this test, we need to set-up "mocking."
67+
68+
Mocking will help our tests work in isolation, which is a
69+
good thing!
70+
71+
We need to mock any POST requests that may occur during this
72+
test (due to Wave 4).
73+
74+
There is no action needed here, the tests should work as-is.
75+
"""
76+
with patch("app.routes.requests.post") as mock_get:
77+
mock_get.return_value.status_code = 200
78+
79+
# Act
80+
response = client.patch("/tasks/1/mark_complete")
81+
response_body = response.get_json()
82+
83+
# Assert
84+
assert response.status_code == 200
85+
assert "task" in response_body
86+
assert response_body["task"]["is_complete"] == True
87+
assert response_body == {
88+
"task": {
89+
"id": 1,
90+
"title": "Go on my daily walk 🏞",
91+
"description": "Notice something new every day",
92+
"is_complete": True
93+
}
94+
}
95+
assert Task.query.get(1).completed_at
96+
97+
98+
def test_mark_incomplete_on_incomplete_task(client, one_task):
99+
# Act
100+
response = client.patch("/tasks/1/mark_incomplete")
101+
response_body = response.get_json()
102+
103+
# Assert
104+
assert response.status_code == 200
105+
assert response_body["task"]["is_complete"] == False
106+
assert response_body == {
107+
"task": {
108+
"id": 1,
109+
"title": "Go on my daily walk 🏞",
110+
"description": "Notice something new every day",
111+
"is_complete": False
112+
}
113+
}
114+
assert Task.query.get(1).completed_at == None
115+
116+
117+
def test_mark_complete_missing_task(client):
118+
# Act
119+
response = client.patch("/tasks/1/mark_complete")
120+
response_body = response.get_json()
121+
122+
# Assert
123+
assert response.status_code == 404
124+
assert response_body == None
125+
126+
127+
def test_mark_incomplete_missing_task(client):
128+
# Act
129+
response = client.patch("/tasks/1/mark_incomplete")
130+
response_body = response.get_json()
131+
132+
# Assert
133+
assert response.status_code == 404
134+
assert response_body == None
135+
136+
62137
# Let's add this test for creating tasks, now that
63138
# the completion functionality has been implemented
64139
def test_create_task_with_valid_completed_at(client):

0 commit comments

Comments
 (0)