Created
October 26, 2016 17:48
-
-
Save marbemac/43b580a527fe674156ae5db8eb7682a5 to your computer and use it in GitHub Desktop.
simple todos crud test scenario
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"flowVersion": "1.0", | |
"name": "To-do CRUD", | |
"description": "This scenario shows a test for a typical CRUD resource. \n\n1. You need to enter an apiKey variable of `123` below, otherwise steps will fail (try with and without it).\n2. Step 2 is purposefully setup to have a failing test, for demonstration purposes.", | |
"steps": [ | |
{ | |
"functions": [ | |
{ | |
"name": "Create It", | |
"input": { | |
"request": { | |
"method": "post", | |
"url": "http://todos.stoplight.io/todos?apikey=<<!apiKey>>", | |
"headers": { | |
"Content-Type": "application/json" | |
}, | |
"body": { | |
"name": "<<!todoName>>", | |
"completed": false | |
} | |
} | |
}, | |
"before": { | |
"script": "if (!state.todoName) {\n state.todoName = 'default name set in before script';\n}" | |
}, | |
"after": { | |
"assertions": [ | |
{ | |
"location": "result.output.response.body", | |
"target": "completed", | |
"op": "eq", | |
"expected": false | |
}, | |
{ | |
"location": "result.output.response.body", | |
"op": "validate.contract", | |
"expected": { | |
"type": "object", | |
"properties": { | |
"name": { | |
"type": "string" | |
}, | |
"completed": { | |
"type": [ | |
"boolean", | |
"null" | |
] | |
}, | |
"created_at": { | |
"type": "string", | |
"format": "date-time" | |
}, | |
"updated_at": { | |
"type": "string", | |
"format": "date-time" | |
} | |
}, | |
"required": [ | |
"id" | |
] | |
} | |
} | |
], | |
"transforms": [ | |
{ | |
"sourceLocation": "result.output.response.body", | |
"sourcePath": "id", | |
"targetLocation": "result.state", | |
"targetPath": "todoId" | |
} | |
] | |
} | |
} | |
] | |
}, | |
{ | |
"functions": [ | |
{ | |
"name": "Get It", | |
"input": { | |
"request": { | |
"url": "http://todos.stoplight.io/todos/<<todoId>>", | |
"method": "get" | |
} | |
}, | |
"after": { | |
"script": "tests['the to-do is completed'] = response.body.completed;", | |
"assertions": [ | |
{ | |
"location": "result.output.response.status", | |
"op": "eq", | |
"expected": 200 | |
} | |
] | |
} | |
} | |
] | |
}, | |
{ | |
"functions": [ | |
{ | |
"name": "Update It", | |
"input": { | |
"request": { | |
"body": { | |
"completed": true | |
}, | |
"headers": { | |
"Content-Type": "application/json" | |
}, | |
"url": "http://todos.stoplight.io/todos/<<todoId>>", | |
"method": "get" | |
} | |
}, | |
"after": { | |
"assertions": [ | |
{ | |
"location": "result.output.response.status", | |
"op": "eq", | |
"expected": 200 | |
} | |
] | |
} | |
} | |
] | |
}, | |
{ | |
"functions": [ | |
{ | |
"name": "Delete It", | |
"input": { | |
"request": { | |
"url": "http://todos.stoplight.io/todos/<<todoId>>?apikey=<<!apiKey>>", | |
"method": "delete" | |
} | |
}, | |
"after": { | |
"assertions": [ | |
{ | |
"location": "result.output.response.status", | |
"op": "eq", | |
"expected": 204 | |
} | |
] | |
} | |
} | |
] | |
}, | |
{ | |
"functions": [ | |
{ | |
"name": "Make Sure It's Gone", | |
"input": { | |
"request": { | |
"url": "http://todos.stoplight.io/<<todoId>>", | |
"method": "get" | |
} | |
}, | |
"after": { | |
"assertions": [ | |
{ | |
"location": "result.output.response.status", | |
"op": "eq", | |
"expected": 404 | |
} | |
] | |
} | |
} | |
] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment