Last active
          March 22, 2018 13:02 
        
      - 
      
- 
        Save safaorhan/253a63bc5a226b35aa8b6ed8a3e0efe5 to your computer and use it in GitHub Desktop. 
    POST /customers 
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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"; | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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