endpoint: https://ostrava.czechibank.ostrava.digital/api/v1/user
{
"email": "[email protected]",
"name": "Papagaj Pepa 🦜",
"password": "password123456"
}
endpoint: https://ostrava.czechibank.ostrava.digital/api/v1/user
{
"email": "{{$randomEmail}}",
"name": "{{$randomFullName}}",
"password": "{{$randomPassword}}"
}
Links: Postman documentation - variable list
Example for checking status code - I am expecting, that response has status code 200
pm.test("should have correct status", function () {
pm.response.to.have.status(200);
});
Example - checking payload - checking property success
if it is true
pm.test("should return success response", function () {
var jsonData = pm.response.json();
pm.expect(jsonData.success).to.eql(true);
});
Example - checking payload - if the schema is correct
pm.test("should return user data", function(){
var jsonData = pm.response.json();
pm.expect(jsonData.data.user).to.have.property("name"); // if data.user has property `name`
pm.expect(jsonData.data.user).to.have.property("email"); // if data.user has property `email`
pm.expect(jsonData.data.user).to.not.have.property("password"); // if data.user has property password
pm.expect(jsonData.data.user.name).to.eql("Vojta 🦊 Cerveny"); // if property `data.user.name` has value "Vojta 🦊 Cerveny"
pm.expect(jsonData.data.user.email).to.eql("[email protected]"); // if property `data.user.email` has value "[email protected]"
})
// Same, buf without comments
pm.test("should return user data", function(){
var jsonData = pm.response.json();
pm.expect(jsonData.data.user).to.have.property("name");
pm.expect(jsonData.data.user).to.have.property("email");
pm.expect(jsonData.data.user).to.not.have.property("password");
pm.expect(jsonData.data.user.name).to.eql("Vojta 🦊 Cerveny");
pm.expect(jsonData.data.user.email).to.eql("[email protected]");
})
// save informations into variable (proměnná)
const body = pm.response.json();
const msg = body?.data?.message;
pm.test("HTTP status is OK (201)", () => {
pm.response.to.have.status(201);
});
pm.test("response time should be less than 500ms", () => {
pm.expect(pm.response.responseTime).to.be.below(500);
})
pm.test("amount is a positive specific number", () => {
pm.expect(msg.amount).to.be.a("number")
pm.expect(msg.amount).to.be.eql(44.4);
});
pm.test("currency is exactly CZECHITOKEN", () => {
pm.expect(msg.currency).to.eql("CZECHITOKEN");
});
pm.test("from.number and to.number have expected account numbers", () => {
pm.expect(msg.from.number).to.eql("968558900169/5555")
pm.expect(msg.to.number).to.eq("555555555555/5555")
});
// FIRST REQUEST - create new user
// endpoint: https://ostrava.czechibank.ostrava.digital/api/v1/user/create
// body:
{
"name": "💔 A TY a Tvůj DONATE JSTE KDE? 💔 🫵",
"email": "{{$randomEmail}}",
"password": "securepassword123"
}
// post request;
const response = pm.response.json();
pm.collectionVariables.set("apiKeyFromResponse", response.apiKey);
// SECOND REQUEST - check number of your bank account
// endpoint: https://ostrava.czechibank.ostrava.digital/api/v1/bank-account/
// API-key: set to {{apiKeyFromResponse}}
// post request:
const response = pm.response.json();
pm.collectionVariables.set("bankAccountFromResponse", response.data.bankAccounts[0].number);
// THIRD REQUEST - send czechitokens to some bank account
// Endpoint https://ostrava.czechibank.ostrava.digital/api/v1/transactions/create
// API-key: set to {{apiKeyFromResponse}}
// payload:
{
"amount": 1,
"fromBankNumber": "{{bankAccountFromResponse}}",
"toBankNumber": "000000000001/5555"
}
// HELP
// What info do you need? Do you need some test?
// This post-script will help you:
const response = pm.response.json();
// in variable firstBankAccount is all informations about your first bank accout.
// Now you need to find way, how to check if the it has 100000 CZECHITOKENs
const firstBankAccount = response.data.bankAccounts[0];
// Check previous tests how to do that.
pm.test("template for your test.", () => {
pm.expect().to.eql();
});