Getting started Community Training Tutorials Documentation APIs, AI & Tools
import * from bat::BDD
import * from bat::Assertions
import * from bat::Mutable
var context = HashMap()
---
describe("the login flow") in [
it("tries a secured endpoint") in [
GET `http://127.0.0.1:4567/secured_by_token` with {
} assert [
$.response.status mustEqual 401,
]
],
it("gets the access token") in [
POST `http://127.0.0.1:4567/get_access_token` with {} assert [
$.response.body.new_token mustMatch /accessToken_\d+/,
] execute [
context.set('token', $.response.body.new_token)
] assert [
context.get('token') mustMatch /accessToken_\d+/,
context.get('token') mustEqual $.response.body.new_token,
$.response.status mustEqual 200,
]
],
it("tries to get a secured endpoint") in [
GET `http://127.0.0.1:4567/secured_by_token/header` with {
headers: {
Authorization: context.get('token')
}
} assert [
$.request.headers.Authorization mustEqual context.get('token'),
$.response.status mustEqual 200
]
]
]



