-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
executable file
·148 lines (105 loc) · 3.77 KB
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/bin/bash
# Create a blog post.
curl http://localhost:3000/posts \
-H 'Content-Type: application/json' \
-X POST \
-d '{"name": "I Am a Blog Post", "text": "Blogs are so 2006!"}'
# Fetch the blog post.
curl http://localhost:3000/posts/1
# Add a comment to the post.
curl http://localhost:3000/posts/1/comments \
-H 'Content-Type: application/json' \
-X POST \
-d '{"text": "But I still read them."}'
# Fetch the comment.
curl http://localhost:3000/posts/1/comments/1
# Create a second blog post.
curl http://localhost:3000/posts \
-H 'Content-Type: application/json' \
-X POST \
-d '{"name": "Cannot Stop with the Blogging", "text": "Does not get much bloggier than this.", "doggy": "Should be ignored"}'
# Add comments to that post.
curl http://localhost:3000/posts/2/comments \
-H 'Content-Type: application/json' \
-X POST \
-d '{"text": "I have seen bloggier."}'
curl http://localhost:3000/posts/2/comments \
-H 'Content-Type: application/json' \
-X POST \
-d '{"text": "You do not know from bloggy.", "doggy": "Should be ignored"}'
# Get the comments.
curl http://localhost:3000/posts/2/comments
# Delete the first of those.
curl http://localhost:3000/posts/2/comments/1 \
-X DELETE
# Get the comments again.
curl http://localhost:3000/posts/2/comments
# Update the first post.
curl http://localhost:3000/posts/1 \
-H 'Content-Type: application/json' \
-X PUT \
-d '{"text": "Blogs are so 2017...", "doggy": "Should be ignored"}'
# Update the first comment on the first post.
curl http://localhost:3000/posts/1/comments/1 \
-H 'Content-Type: application/json' \
-X PUT \
-d '{"text": "I stopped reading them like ten years ago.", "doggy": "Should be ignored"}'
# Fetch the updated post.
curl http://localhost:3000/posts/1
# Check that empty and missing properties are handled. First, on creating
# posts.
curl http://localhost:3000/posts \
-H 'Content-Type: application/json' \
-X POST \
-d '{"name": "I Am Another Blog Post"}'
curl http://localhost:3000/posts \
-H 'Content-Type: application/json' \
-X POST \
-d '{"name": "I Am Another Blog Post", "text": ""}'
# Next, on creating comments.
curl http://localhost:3000/posts/1/comments \
-H 'Content-Type: application/json' \
-X POST \
-d '{"text": ""}'
curl http://localhost:3000/posts/1/comments \
-H 'Content-Type: application/json' \
-X POST \
-d '{}'
# On updating posts.
curl http://localhost:3000/posts/1 \
-H 'Content-Type: application/json' \
-X PUT \
-d '{"text": ""}'
curl http://localhost:3000/posts/1 \
-H 'Content-Type: application/json' \
-X PUT \
-d '{}'
# On updating comments.
curl http://localhost:3000/posts/1/comments/1 \
-H 'Content-Type: application/json' \
-X PUT \
-d '{"text": ""}'
curl http://localhost:3000/posts/1/comments/1 \
-H 'Content-Type: application/json' \
-X PUT \
-d '{}'
# Check that we get 404s when we ask for comments/posts that don't exist.
curl http://localhost:3000/posts/5
curl http://localhost:3000/posts/1/comments/2
# And 404s when we delete what doesn't exist.
curl -X DELETE http://localhost:3000/posts/5
curl -X DELETE http://localhost:3000/posts/5/comments/2
curl -X DELETE http://localhost:3000/posts/1/comments/2
# And 404s when we update what doesn't exist.
curl http://localhost:3000/posts/5 \
-H 'Content-Type: application/json' \
-X PUT \
-d '{"text": "I am illusory"}'
curl http://localhost:3000/posts/5/comments/2 \
-H 'Content-Type: application/json' \
-X PUT \
-d '{"text": "I am illusory"}'
curl http://localhost:3000/posts/1/comments/2 \
-H 'Content-Type: application/json' \
-X PUT \
-d '{"text": "I am illusory"}'