|
1 | 1 | { |
2 | 2 | "info": { |
3 | | - "name": "Todo API", |
| 3 | + "name": "Todo API (Newman)", |
4 | 4 | "_postman_id": "11111111-1111-1111-1111-111111111111", |
5 | 5 | "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" |
6 | 6 | }, |
7 | 7 | "item": [ |
| 8 | + |
8 | 9 | { |
9 | | - "name": "GET dashboard", |
| 10 | + "name": "Set unique title + dashboard ok", |
10 | 11 | "request": { |
11 | 12 | "method": "GET", |
12 | 13 | "url": "{{baseUrl}}/dashboard" |
13 | 14 | }, |
14 | 15 | "event": [ |
| 16 | + { |
| 17 | + "listen": "prerequest", |
| 18 | + "script": { |
| 19 | + "exec": [ |
| 20 | + "pm.environment.set('title', 'Newman Todo ' + Date.now());" |
| 21 | + ] |
| 22 | + } |
| 23 | + }, |
15 | 24 | { |
16 | 25 | "listen": "test", |
17 | 26 | "script": { |
18 | 27 | "exec": [ |
19 | | - "pm.test('status 200', function () {", |
20 | | - " pm.response.to.have.status(200);", |
| 28 | + "pm.test('dashboard returns 200', () => pm.response.to.have.status(200));" |
| 29 | + ] |
| 30 | + } |
| 31 | + } |
| 32 | + ] |
| 33 | + }, |
| 34 | + |
| 35 | + { |
| 36 | + "name": "Create todo", |
| 37 | + "request": { |
| 38 | + "method": "POST", |
| 39 | + "body": { |
| 40 | + "mode": "urlencoded", |
| 41 | + "urlencoded": [ |
| 42 | + { "key": "title", "value": "{{title}}", "type": "text" }, |
| 43 | + { "key": "description", "value": "Created by newman", "type": "text" }, |
| 44 | + { "key": "status", "value": "not-started", "type": "text" } |
| 45 | + ] |
| 46 | + }, |
| 47 | + "url": "{{baseUrl}}/todo/create" |
| 48 | + }, |
| 49 | + "event": [ |
| 50 | + { |
| 51 | + "listen": "test", |
| 52 | + "script": { |
| 53 | + "exec": [ |
| 54 | + "pm.test('title is set', () => {", |
| 55 | + " pm.expect(pm.environment.get('title')).to.be.ok;", |
| 56 | + "});", |
| 57 | + "pm.test('create returns 200 or 302', () => {", |
| 58 | + " pm.expect([200, 302]).to.include(pm.response.code);", |
21 | 59 | "});" |
22 | 60 | ] |
23 | 61 | } |
24 | 62 | } |
25 | 63 | ] |
26 | 64 | }, |
| 65 | + |
27 | 66 | { |
28 | | - "name": "POST create todo", |
| 67 | + "name": "Find created todo id (todo/get)", |
| 68 | + "request": { |
| 69 | + "method": "GET", |
| 70 | + "url": "{{baseUrl}}/todo/get" |
| 71 | + }, |
| 72 | + "event": [ |
| 73 | + { |
| 74 | + "listen": "test", |
| 75 | + "script": { |
| 76 | + "exec": [ |
| 77 | + "pm.test('todo/get returns 200', () => pm.response.to.have.status(200));", |
| 78 | + "var body = pm.response.json();", |
| 79 | + "pm.expect(body).to.have.property('todos');", |
| 80 | + "var title = pm.environment.get('title');", |
| 81 | + "var found = body.todos.find(t => t.title === title);", |
| 82 | + "pm.expect(found, 'created todo should exist').to.be.ok;", |
| 83 | + "pm.environment.set('todo_id', String(found.id));", |
| 84 | + "pm.test('todo_id saved', () => {", |
| 85 | + " pm.expect(pm.environment.get('todo_id')).to.be.ok;", |
| 86 | + "});" |
| 87 | + ] |
| 88 | + } |
| 89 | + } |
| 90 | + ] |
| 91 | + }, |
| 92 | + |
| 93 | + { |
| 94 | + "name": "Update status to done", |
29 | 95 | "request": { |
30 | 96 | "method": "POST", |
31 | 97 | "header": [ |
|
34 | 100 | "body": { |
35 | 101 | "mode": "urlencoded", |
36 | 102 | "urlencoded": [ |
37 | | - { "key": "title", "value": "Newman todo", "type": "text" }, |
38 | | - { "key": "description", "value": "Created by newman", "type": "text" }, |
39 | | - { "key": "status", "value": "not-started", "type": "text" } |
| 103 | + { "key": "status", "value": "done", "type": "text" } |
40 | 104 | ] |
41 | 105 | }, |
42 | | - "url": "{{baseUrl}}/todo/create" |
| 106 | + "url": "{{baseUrl}}/todo/{{todo_id}}/status" |
43 | 107 | }, |
44 | 108 | "event": [ |
45 | 109 | { |
46 | 110 | "listen": "test", |
47 | 111 | "script": { |
48 | 112 | "exec": [ |
49 | | - "pm.test('status is 200 or redirect', function () {", |
| 113 | + "pm.test('todo_id exists', () => {", |
| 114 | + " pm.expect(pm.environment.get('todo_id')).to.be.ok;", |
| 115 | + "});", |
| 116 | + "", |
| 117 | + "pm.test('update returns 200 or 302', () => {", |
50 | 118 | " pm.expect([200, 302]).to.include(pm.response.code);", |
51 | 119 | "});" |
52 | 120 | ] |
53 | 121 | } |
54 | 122 | } |
55 | 123 | ] |
| 124 | + }, |
| 125 | + |
| 126 | + { |
| 127 | + "name": "Verify status is done (todo/get)", |
| 128 | + "request": { |
| 129 | + "method": "GET", |
| 130 | + "url": "{{baseUrl}}/todo/get" |
| 131 | + }, |
| 132 | + "event": [ |
| 133 | + { |
| 134 | + "listen": "test", |
| 135 | + "script": { |
| 136 | + "exec": [ |
| 137 | + "pm.test('todo/get returns 200', () => pm.response.to.have.status(200));", |
| 138 | + "", |
| 139 | + "var body2 = pm.response.json();", |
| 140 | + "var id2 = pm.environment.get('todo_id');", |
| 141 | + "pm.expect(id2, 'todo_id should be set').to.be.ok;", |
| 142 | + "", |
| 143 | + "var found2 = body2.todos.find(t => String(t.id) === String(id2));", |
| 144 | + "pm.expect(found2, 'todo should exist').to.be.ok;", |
| 145 | + "", |
| 146 | + "pm.test('status is done', () => {", |
| 147 | + " pm.expect(found2.status).to.eql('done');", |
| 148 | + "});" |
| 149 | + ] |
| 150 | + } |
| 151 | + } |
| 152 | + ] |
| 153 | + }, |
| 154 | + |
| 155 | + { |
| 156 | + "name": "Delete todo", |
| 157 | + "request": { |
| 158 | + "method": "POST", |
| 159 | + "url": "{{baseUrl}}/todo/{{todo_id}}/delete" |
| 160 | + }, |
| 161 | + "event": [ |
| 162 | + { |
| 163 | + "listen": "test", |
| 164 | + "script": { |
| 165 | + "exec": [ |
| 166 | + "pm.test('todo_id exists', () => {", |
| 167 | + " pm.expect(pm.environment.get('todo_id')).to.be.ok;", |
| 168 | + "});", |
| 169 | + "", |
| 170 | + "pm.test('delete returns 200 or 302', () => {", |
| 171 | + " pm.expect([200, 302]).to.include(pm.response.code);", |
| 172 | + "});" |
| 173 | + ] |
| 174 | + } |
| 175 | + } |
| 176 | + ] |
| 177 | + }, |
| 178 | + |
| 179 | + { |
| 180 | + "name": "Verify todo removed (todo/get)", |
| 181 | + "request": { |
| 182 | + "method": "GET", |
| 183 | + "url": "{{baseUrl}}/todo/get" |
| 184 | + }, |
| 185 | + "event": [ |
| 186 | + { |
| 187 | + "listen": "test", |
| 188 | + "script": { |
| 189 | + "exec": [ |
| 190 | + "pm.test('todo/get returns 200', () => pm.response.to.have.status(200));", |
| 191 | + "", |
| 192 | + "var body3 = pm.response.json();", |
| 193 | + "var id3 = pm.environment.get('todo_id');", |
| 194 | + "pm.expect(id3, 'todo_id should be set').to.be.ok;", |
| 195 | + "", |
| 196 | + "var found3 = body3.todos.find(t => String(t.id) === String(id3));", |
| 197 | + "", |
| 198 | + "pm.test('todo is deleted', () => {", |
| 199 | + " pm.expect(found3).to.not.be.ok;", |
| 200 | + "});" |
| 201 | + ] |
| 202 | + } |
| 203 | + } |
| 204 | + ] |
56 | 205 | } |
57 | 206 | ] |
58 | 207 | } |
0 commit comments