fragments / tests / integration / getid-fragments-imageConversion.hurl
getid-fragments-imageConversion.hurl
Raw
# ================================================================================================================

# Post Authorized IMAGE

# Authenticated POST to /v1/fragments
POST http://localhost:8080/v1/fragments
# user1@email.com:password1
Authorization: Basic dXNlcjFAZW1haWwuY29tOnBhc3N3b3JkMQ==
# We're sending a image/png fragment
Content-Type: image/png
# Body of the request
file,Portfolio.png;

# 1. We expect to get back an HTTP 201
HTTP/1.1 201
# We have various assertions about the response that we want to check 
[Asserts]
# The Location header should look like what we expect (including the fragment id)
header "Location" matches "^http:\/\/localhost:8080\/v1\/fragments\/[A-Za-z0-9_-]+$"
jsonpath "$.status" == "ok"
# Our fragment ids use https://www.npmjs.com/package/nanoid
jsonpath "$.fragments.id" matches "^[A-Za-z0-9_-]+$"
# Our ownerId hash is a hex encoded string
jsonpath "$.fragments.ownerId" matches "^[0-9a-fA-F]+$"
# Basic check for the presence of created and updated date strings.
# You could also write a regex for this and use matches
jsonpath "$.fragments.created" isString
jsonpath "$.fragments.updated" isString
jsonpath "$.fragments.type" == "image/png"
# Capture the Location URL into a variable named `url`
[Captures]
url: header "Location"


# ================================================================================================================
# Get the converted fragment (PNG - > JPEG)

# 2. Try to GET the fragment we just posted by its URL + .png
GET {{url}}.jpeg
Authorization: Basic dXNlcjFAZW1haWwuY29tOnBhc3N3b3JkMQ==

HTTP/1.1 200

# ================================================================================================================

# Fail to Get the converted fragment

# 2. Try to convert the fragment we just posted to the invalid conversion type and fail
GET {{url}}.html
Authorization: Basic dXNlcjFAZW1haWwuY29tOnBhc3N3b3JkMQ==

HTTP/1.1 415

# ================================================================================================================

# DELETE the converted fragment

# 2. Try to DELETE the fragment we just posted by its URL 
DELETE {{url}}
Authorization: Basic dXNlcjFAZW1haWwuY29tOnBhc3N3b3JkMQ==

HTTP/1.1 200