price-point-api/bruno/auth/login.bru

65 lines
1.4 KiB
Text
Raw Normal View History

meta {
name: Login
type: http
seq: 2
}
post {
url: {{baseUrl}}/login
body: json
auth: none
}
headers {
Content-Type: application/json
}
body:json {
{
"email": "{{userEmail}}",
"password": "password123"
}
}
assert {
res.status: 200
res.body.success: true
res("data.token"): isNotEmpty
}
script:post-response {
const body = res.getBody();
if (body && body.data && body.data.token) {
bru.setVar("authToken", body.data.token);
bru.setVar("userId", body.data.user.id);
}
}
tests {
test("Login returns wrapped success response", function() {
const data = res.getBody();
expect(data).to.have.property("success");
expect(data.success).to.equal(true);
expect(data).to.have.property("data");
});
test("Data contains user object and token string", function() {
const data = res.getBody();
expect(data.data).to.have.property("user");
expect(data.data).to.have.property("token");
});
test("User object has correct shape", function() {
const data = res.getBody();
expect(data.data.user).to.have.property("id");
expect(data.data.user).to.have.property("email");
expect(data.data.user).to.have.property("name");
});
test("Token is a non-empty string", function() {
const data = res.getBody();
expect(data.data.token).to.be.a("string");
expect(data.data.token.length).to.be.greaterThan(0);
});
}