-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay 02- Version control.postman_collection.json
334 lines (334 loc) · 15.1 KB
/
Day 02- Version control.postman_collection.json
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
{
"info": {
"_postman_id": "98eb0359-bbe0-4afd-9ba8-f09dfa6f3c2c",
"name": "Day 02: Version control",
"description": "## Instructions for Day 2: Version control\n\n1. **Get the challenge:** Fork the parent collection to your own public workspace.\n2. **Read the documentation:** Select the first folder. Expand the context bar on the right to follow the instructions in the collection documentation.\n3. **Submit your solution:** Select the second folder and follow the instructions in the documentation to validate your solution.\n\n## Learning objectives\n- Configure request headers\n- Explain version control in Postman\n- Fork and merge changes into a collection\n- Use environment variables to store data\n\n## Concepts covered\n\n- [Fork a collection](https://learning.postman.com/docs/collaborating-in-postman/version-control-for-collections/#forking-a-collection)\n- [Send body data](https://learning.postman.com/docs/sending-requests/requests/#sending-body-data)\n- [Use environments](https://learning.postman.com/docs/sending-requests/managing-environments/#creating-environments)\n- [Configure request headers](https://learning.postman.com/docs/sending-requests/requests/#configuring-request-headers)\n \n\n## Additional resources\n\n* [Version Control for Collections](https://youtu.be/QKxukXJWRPI) video\n* [How to use Postman environments](https://youtu.be/oCEDjp3XMco) video",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "3488052"
},
"item": [
{
"name": "Version control",
"item": [
{
"name": "New Request",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n\"data\": \"noodles\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{baseURL}}/post",
"host": [
"{{baseURL}}"
],
"path": [
"post"
]
}
},
"response": []
}
],
"description": "It's time to work on your next challenge.\n\n1. **Fork the collection (again)**: Fork the collection (again) within your workspace and label the fork `feature-branch`, so that you have 2 collections in the same workspace. The next few steps are going to be completed in your `feature-branch` collection.\n1. **Add a request**: In the `feature-branch` collection, add a request to the folder `Version control` called `New Request` with the following details:\n - `POST` method\n - <code>\\{{baseURL\\}}/post</code> request URL\n1. **Include a body**: Under the **Body** tab, update the body type to `raw` and in the dropdown at the end where it says \"Text\", select `JSON`. Add a JSON object, like the following. \n```\n{\n\"data\": \"noodles\"\n}\n```\n When you add a raw JSON request body, Postman auto-generates a header `Content-Type: application/json` header under the **Headers** tab. Take a look. You may need to click the **hidden** button to show the headers. This is also where you can [configure other request headers](https://learning.postman.com/docs/sending-requests/requests/#configuring-request-headers).\n1. **Add an environment**: [Create a new environment](https://learning.postman.com/docs/sending-requests/managing-environments/#creating-environments) called `myEnvironment`, with a key `baseURL` and a value `https://postman-echo.com`. Then select the environment as the active environment, so that Postman reads in the appropriate value for <code>\\{{baseURL\\}}</code> in the request URL. **Send** to make sure you get a 200 status code, and then save your changes.\n1. **Merge changes**: Since you are the author of both forks, you have permissions to merge any changes. If you did not have permission to edit the parent collection, you would instead submit a [pull request](https://learning.postman.com/docs/collaborating-in-postman/version-control-for-collections/#creating-pull-requests). Now [merge your changes](https://learning.postman.com/docs/collaborating-in-postman/version-control-for-collections/#merging-changes) from `feature-branch` into your own parent collection. Make sure to select the option \"Merge changes\". You will need the collection ID for both collections in the next step.\n\nOnce you complete these steps, save your changes and move on to the next folder. Follow the instructions in the request documentation."
},
{
"name": "Submit your solution",
"item": [
{
"name": "submit first collection",
"event": [
{
"listen": "test",
"script": {
"exec": [
"// counter for passed tests",
"let pass = 0",
"let totalToPass = 4",
"",
"let collection = pm.response.json().collection",
"",
"pm.test(\"If you have any failures, review the failed test results or ask for support in the community forum. Remember to save your changes if you update the collection. When all of your tests pass, you are done with today's challenge.\", () => {",
" pm.expect(true);",
" pass += 1",
"});",
"",
"pm.test(\"Status code is 200\", () => {",
" pm.response.to.have.status(200);",
" pass += 1",
"});",
"",
"pm.test(\"Correct collection returned\", () => {",
" pm.expect(collection.info.name).equals(\"Day 02: Version control\")",
" pass += 1",
"})",
"",
"let folder = collection.item.find(fol => { return fol.name === \"Version control\" })",
"",
"pm.test(\"Request updated\", () => {",
" let request = folder.item.find(req => { return req.name === \"New Request\" })",
" pm.expect(request.request.method, 'check method').to.equal(\"POST\")",
" pm.expect(request.request.body.options.raw.language, 'check JSON').to.equal(\"json\")",
" pm.expect(request.request.body.raw, 'check payload').is.not.empty",
" pass += 1",
"})",
"",
"// visualization for test results",
"let template",
"if (pass == totalToPass) {",
" template = `🍪 passing!",
" <br />",
" <img src=\"https://media1.giphy.com/media/7Jplyo45Cd8Pp8A4PO/giphy.gif?cid=ecf05e4742btni80eyov8aqcpjhvc4hyxc36covy0r33xvy0&rid=giphy.gif&ct=g\" />",
" `",
"} else {",
" template = `🙅 please try again",
" <br />",
" <img src=\"https://media3.giphy.com/media/5bgS90uCmWoWp2hBvj/giphy.gif?cid=ecf05e47mv96rgygl6w4fenzomwqqeh17p5pvcsgenuyxsbo&rid=giphy.gif&ct=g\" />",
" `",
"}",
"pm.visualizer.set(template)"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [
{
"key": "x-api-key",
"value": "{{postman_api_key}}",
"type": "text"
}
],
"url": {
"raw": "https://api.getpostman.com/collections/{{collection_uid}}",
"protocol": "https",
"host": [
"api",
"getpostman",
"com"
],
"path": [
"collections",
"{{collection_uid}}"
]
},
"description": "It's time to check your collection.\n\n1. **Get the collection ID:** Select the collection (the original parent) in the sidebar. Then in the context bar to the right, select the `Info` icon and copy the collection `ID`.\n2. **Update the request URL:** Update the `collection_uid` in the request URL with the collection `ID` from the previous step, using any method you prefer.\n3. **Get your Postman API key**: Get your [Postman API key](https://go.postman.co/settings/me/api-keys), and add your API key using any method you prefer. For example, you can create an environment variable and reuse your credentials throughout the remainder of these challenges. Make sure to paste the value under `CURRENT VALUE` (and not `INITIAL VALUE`) and save your changes.\n \n > ⚠ DON'T LEAK YOUR SECRETS! \n > It's very important to add sensitive values like an API key to the `CURRENT VALUE` (and not `INITIAL VALUE`) of your public workspace.\n \n4. **Validate your solution**: Hit **Send** and look under the **Tests** tab of the server response at the bottom to review your test results.\n \n\nIf you have any failures, [review the failed test results](https://youtu.be/S3GKLTVRtmE) or ask for support in the [community forum](https://community.postman.com/). When all of your tests pass, you are done with today's challenge."
},
"response": []
},
{
"name": "submit second collection",
"event": [
{
"listen": "test",
"script": {
"exec": [
"// counter for passed tests",
"let pass = 0",
"let totalToPass = 5",
"",
"let collection = pm.response.json().collection",
"",
"pm.test(\"If you have any failures, review the failed test results or ask for support in the community forum. Remember to save your changes if you update the collection. When all of your tests pass, you are done with today's challenge.\", () => {",
" pm.expect(true);",
" pass += 1",
"});",
"",
"pm.test(\"Status code is 200\", () => {",
" pm.response.to.have.status(200);",
" pass += 1",
"});",
"",
"pm.test(\"Correct collection returned\", () => {",
" pm.expect(collection.info.name).equals(\"Day 02: Version control\")",
" pass += 1",
"})",
"",
"pm.test(\"Correct fork returned\", () => {",
" pm.expect(collection.info.fork.label).equals(\"feature-branch\")",
" pass += 1",
"})",
"",
"let folder = collection.item.find(fol => {return fol.name === \"Version control\"})",
"",
"pm.test(\"Request updated\", () => {",
" let request = folder.item.find(req => {return req.name === \"New Request\"})",
" pm.expect(request.request.method, 'check method').to.equal(\"POST\")",
" pm.expect(request.request.body.options.raw.language, 'check JSON').to.equal(\"json\")",
" pm.expect(request.request.body.raw, 'check payload').is.not.empty",
" pass += 1",
"})",
"",
"// visualization for test results",
"let template",
"if (pass == totalToPass) {",
" template = `🍪 passing!",
" <br />",
" <img src=\"https://media0.giphy.com/media/TjGm3jg5sgV1mBmq8d/giphy.gif?cid=ecf05e4742btni80eyov8aqcpjhvc4hyxc36covy0r33xvy0&rid=giphy.gif&ct=g\" />",
" `",
"} else {",
" template = `🙅 please try again",
" <br />",
" <img src=\"https://media2.giphy.com/media/HSvpy6Jk396SI/giphy.gif?cid=ecf05e47mv96rgygl6w4fenzomwqqeh17p5pvcsgenuyxsbo&rid=giphy.gif&ct=g\" />",
" `",
"}",
"pm.visualizer.set(template)"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [
{
"key": "x-api-key",
"value": "{{postman_api_key}}",
"type": "text"
}
],
"url": {
"raw": "https://api.getpostman.com/collections/{{collection_uid}}",
"protocol": "https",
"host": [
"api",
"getpostman",
"com"
],
"path": [
"collections",
"{{collection_uid}}"
]
},
"description": "Repeat the same steps to validate your second collection. You will need the collection `ID` for `feature-branch`.\n\nWhen all of your tests pass, move on to the last request in this folder."
},
"response": []
},
{
"name": "submit environment",
"event": [
{
"listen": "test",
"script": {
"exec": [
"// counter for passed tests",
"let pass = 0",
"let totalToPass = 5",
"",
"let env = pm.response.json().environment",
"",
"pm.test(\"If you have any failures, review the failed test results or ask for support in the community forum. Remember to save your changes if you update the collection. When all of your tests pass, you are done with today's challenge.\", () => {",
" pm.expect(true);",
" pass += 1",
"});",
"",
"pm.test(\"Status code is 200\", () => {",
" pm.response.to.have.status(200);",
" pass += 1",
"});",
"",
"pm.test(\"Correct environment returned\", () => {",
" pm.expect(env.name).equals(\"myEnvironment\")",
" pass += 1",
"})",
"",
"pm.test(\"Correct variable added\", () => {",
" let variable = env.values.find(key => {return key.key === \"baseURL\"})",
" pm.expect(variable.value).equals(\"\")",
" pass += 1",
"})",
"",
"pm.test(\"API key secure\", () => {",
"",
" let apiKey = env.values.find(item => { return item.key === \"postman_api_key\"})",
" if (apiKey) {",
" pm.expect(apiKey.value, 'API key visible under Initial value').does.not.include(\"PMAK\")",
" }",
" pass += 1",
"})",
"",
"// visualization for test results",
"let template",
"if (pass == totalToPass) {",
" template = `🍪 passing!",
" <br />",
" <img src=\"https://media1.giphy.com/media/LGvQYGvbG1HUTJvsqS/giphy.gif?cid=ecf05e47jecwb1ue3autu8zgn0xd3udt06orld5ohz3aenyi&rid=giphy.gif&ct=g\" />",
" `",
"} else {",
" template = `🙅 please try again",
" <br />",
" <img src=\"https://media1.giphy.com/media/11nQ2iZnQpPkgo/giphy.gif?cid=ecf05e47vtwsiob8kittbfq9lkkey2d8sxpafphia58eoanq&rid=giphy.gif&ct=g\" />",
" `",
"}",
"pm.visualizer.set(template)"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [
{
"key": "x-api-key",
"value": "{{postman_api_key}}",
"type": "text"
}
],
"url": {
"raw": "https://api.getpostman.com/environments/{{environment_uid}}",
"protocol": "https",
"host": [
"api",
"getpostman",
"com"
],
"path": [
"environments",
"{{environment_uid}}"
]
},
"description": "Follow a similar process to validate your environment. You will need the environment `ID` for `myEnvironment` to update the `environment_uid` in the request URL.\n\nWhen all of your tests pass, you are done with today's challenge."
},
"response": []
}
],
"description": "Follow the instructions in the request documentation."
}
],
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
}
],
"variable": [
{
"key": "collection_uid",
"value": ""
}
]
}