From 98dd5d659e8857677077b90be1237a4cb4c71aa6 Mon Sep 17 00:00:00 2001 From: Dung Huynh Duc Date: Thu, 31 Oct 2024 22:33:40 +0800 Subject: [PATCH] feat(examples): add todo API tests and enhance existing examples --- example/dogs.hurl | 1 + example/example.hurl | 4 ++-- example/todo.hurl | 25 +++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 example/todo.hurl diff --git a/example/dogs.hurl b/example/dogs.hurl index 544ce14..a4b2c1c 100644 --- a/example/dogs.hurl +++ b/example/dogs.hurl @@ -5,6 +5,7 @@ HTTP 200 [Captures] id: jsonpath "$.data[0].id" +name: jsonpath "$.data[0].attributes.name" GET https://dogapi.dog/api/v2/breeds/{{id}} diff --git a/example/example.hurl b/example/example.hurl index 684aa40..2318056 100644 --- a/example/example.hurl +++ b/example/example.hurl @@ -8,9 +8,9 @@ header "server" contains "MangaDex" GET https://google.com -HTTP 301 +HTTP 302 [Asserts] -xpath "string(//title)" == "301 Moved" +xpath "string(//title)" == "302 Moved" GET https://www.google.com diff --git a/example/todo.hurl b/example/todo.hurl new file mode 100644 index 0000000..d48700e --- /dev/null +++ b/example/todo.hurl @@ -0,0 +1,25 @@ +# Get all todos +GET https://wattpm-demo.fly.dev/express/api/todo + +HTTP 200 +[Asserts] +jsonpath "$.status" == "success" +header "server" contains "Fly" + + +# Throw error if text is not provided +POST https://wattpm-demo.fly.dev/express/api/todo +Content-Type: application/json +{} +HTTP 400 +[Asserts] +jsonpath "$.status" == "error" +jsonpath "$.message" == "Text is required" + +# Create a new todo +POST https://wattpm-demo.fly.dev/express/api/todo +Content-Type: application/json +{ + "text": "Call Express API from hurl.nvim at {{now}}" +} +HTTP 201