This file contains 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
{ | |
"swagger": "2.0", | |
"info": { | |
"version": "v1", | |
"title": "ShipEngine" | |
}, | |
"host": "api.shipengine.com", | |
"schemes": [ | |
"https" | |
], |
This file contains 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
tests["Status code is 200"] = responseCode.code === 200; | |
tests["Response time is acceptable"] = responseTime < 200; // milliseconds | |
tests["Content-Type header is set"] = postman.getResponseHeader("Content-Type"); |
This file contains 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 customer = JSON.parse(responseBody); | |
if (customer.id === undefined) { | |
// No customer was returned, so don't run the rest of the collection | |
postman.setNextRequest(null); | |
} | |
else { | |
// Save the customer ID to a Postman environment variable | |
postman.setEnvironmentVariable("cust_id", customer.id); |
This file contains 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
// First, run the common tests | |
eval(globals.commonTests)(); | |
// Then run any request-specific tests | |
tests["Status code is 200"] = responseCode.code === 200; |
This file contains 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
// Save common tests in a global variable | |
postman.setGlobalVariable("commonTests", () => { | |
// The Content-Type must be JSON | |
tests["Content-Type header is set"] = postman.getResponseHeader("Content-Type") === "application/json"; | |
// The response time must be less than 500 milliseconds | |
tests["Response time is acceptable"] = responseTime < 500; | |
// The response body must include an "id" property | |
var data = JSON.parse(responseBody); |
This file contains 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
describe('Get customer info', () => { | |
it('should return a valid response', () => { | |
response.should.have.status(200); | |
response.should.be.json; | |
response.body.should.not.be.empty; | |
}); | |
it('should set the Location header', () => { | |
response.should.have.header('Location'); |
This file contains 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
// Load the JSON Schema | |
const customerSchema = JSON.parse(environment.customerSchema); | |
// Test whether the response matches the schema | |
var customer = JSON.parse(responseBody); | |
tests["Customer is valid"] = tv4.validate(customer, customerSchema); |
This file contains 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
// Define the JSON Schema | |
const customerSchema = { | |
"required": ["id"], | |
"properties": { | |
"id": { | |
"type": "integer", | |
"minimum": 100, | |
"maximum": 1000 | |
}, | |
"name": { |
This file contains 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
swagger: "2.0" | |
info: | |
version: 1.0.0 | |
title: Blog | |
paths: | |
"/blogs/{id}/posts": | |
parameters: | |
- name: "id" | |
in: "path" | |
type: "integer" |
This file contains 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
swagger: "2.0" | |
info: | |
version: 1.0.0 | |
title: Example | |
paths: | |
"/foo": | |
get: | |
responses: | |
200: |
NewerOlder