// Form submission example
// Demonstrates .form_from() with a .fdef file for application/x-www-form-urlencoded requests.

def username as string("alice")
def password as string("s3cr3t")

def login_mock as mock(POST, "https://example.com/login")
  .reply(200, "welcome alice")

def res as response(
  request(POST)
    .path("https://example.com/login")
    .form_from("data/login.fdef")
    .with_var(username)
    .with_var(password)
    .with_mocks(login_mock)
    .do()
)

assert(res.ok())
assert(res.body_contains("welcome"))

print("status:  {{res.describe_status()}}")
print("body:    {{res.body()}}")
print("form submission passed")
