52 lines
1,001 B
Text
52 lines
1,001 B
Text
|
|
meta {
|
||
|
|
name: Create Product
|
||
|
|
type: http
|
||
|
|
seq: 2
|
||
|
|
}
|
||
|
|
|
||
|
|
post {
|
||
|
|
url: {{baseUrl}}/products
|
||
|
|
body: json
|
||
|
|
}
|
||
|
|
|
||
|
|
headers {
|
||
|
|
Content-Type: application/json
|
||
|
|
Authorization: Bearer {{authToken}}
|
||
|
|
}
|
||
|
|
|
||
|
|
body:json {
|
||
|
|
{
|
||
|
|
"product": {
|
||
|
|
"name": "Test Product",
|
||
|
|
"barcode": "1234567890123"
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
assert {
|
||
|
|
res.status: equals 201
|
||
|
|
}
|
||
|
|
|
||
|
|
script:post-response {
|
||
|
|
const body = res.getBody();
|
||
|
|
if (body && body.id) {
|
||
|
|
bru.setVar("productId", body.id);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
tests {
|
||
|
|
test("Create product returns product object directly", function() {
|
||
|
|
const data = res.getBody();
|
||
|
|
expect(data).to.have.property("id");
|
||
|
|
expect(data).to.have.property("name");
|
||
|
|
expect(data).to.have.property("barcode");
|
||
|
|
expect(data).to.have.property("created_at");
|
||
|
|
expect(data).to.have.property("updated_at");
|
||
|
|
});
|
||
|
|
|
||
|
|
test("Created product has correct values", function() {
|
||
|
|
const data = res.getBody();
|
||
|
|
expect(data.name).to.equal("Test Product");
|
||
|
|
expect(data.barcode).to.equal("1234567890123");
|
||
|
|
});
|
||
|
|
}
|