Skip to content

Instantly share code, notes, and snippets.

@safaorhan
Last active March 22, 2018 13:02
Show Gist options
  • Save safaorhan/253a63bc5a226b35aa8b6ed8a3e0efe5 to your computer and use it in GitHub Desktop.
Save safaorhan/253a63bc5a226b35aa8b6ed8a3e0efe5 to your computer and use it in GitHub Desktop.
POST /customers
var firstName = getRandomFirstName();
var lastName = getRandomLastName();
var uniqueEmail = getUniqueEmail();
/*
* Generate random names and email address
* and save them into the environment variables.
* So that we can use the values in the request body.
*/
pm.environment.set("CUSTOMER_FIRST_NAME", firstName);
pm.environment.set("CUSTOMER_LAST_NAME", lastName);
pm.environment.set("CUSTOMER_EMAIL", uniqueEmail);
function getRandom(max) {
return Math.floor(Math.random() * max);
}
function getRandomFirstName() {
var firstNames = ["Şafak", "Emine", "Ezgi", "Gamze", "Leyla", "Mecnun", "Kerem", "Aslı"];
return firstNames[getRandom(firstNames.length)];
}
function getRandomLastName() {
var lastNames = ["Özcan", "Demir", "Ecevit", "Ayazoğlu", "Rüya", "Kazım", "Mecnun"];
return lastNames[getRandom(lastNames.length)];
}
function getUniqueEmail() {
var timestamp = Date.now();
return "bt" + timestamp + "@gmail.com";
}
var schema = {
"type": "object",
"properties": {
"model": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"createdDate": {
"type": "string"
},
"firstName": {
"type": "string"
},
"lastname": {
"type": "string"
},
"email": {
"type": "string"
}
}
}
}
};
//1. status code should be 201
pm.test("status code should be 201",function(){
pm.response.to.have.status(201);
})
//2. Response body should be json
pm.test("Response body should be json", function(){
pm.response.to.have.jsonBody();
});
//3. Response schema should match the expected
var body = pm.response.json();
pm.test("Schema should be valid", function() {
pm.expect(tv4.validate(body, schema)).to.be.true;
})
// Save the customer id to
var customerId = body.model.id;
pm.environment.set("CUSTOMER_ID", customerId + "");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment