co-http-test

0.3.1 • Public • Published

co-http-test

Build Status npm npm

Validates results of one or more http requests. (optional) validate by status(defaults to 200), body, and headers

npm i --save co-http-test

const httpTest = require('co-http-test');

httpTest(description, request)
// description   : string
// request       : co/koa/generator compatible request.js call

for slightly more verbose output format description:

var str = 'test group description | test1 desc, test2 desc, etc'

examples

const httpTest = require('co-http-test').httpTest; // ".httpTest" only needed when httpUtil is used
const httpUtil = require('co-http-test').httpUtil;

const testApi = {
    gmaps: new $http('https://maps.googleapis.com/', {'x-hi-there': 'hello'}),
    endPoint: new $http('http://jsonplaceholder.typicode.com/')
};

httpTest('HTTP DELETE',testApi.endPoint.put('posts/1'))

httpTest('enforce response body | and status', testApi.endPoint.get('posts/1'),
    200,
    {
        "userId": 1,
        "id": 1,
        "title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
        "body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
    }
);

// request arrays are executed in parallel


httpTest('parallel HTTP test detailed description | details for POST, PUT details, PATCH details', [
    testApi.endPoint.post('posts/'),
    testApi.endPoint.put('posts/1', {
        title: 'test put'
    }),
    testApi.endPoint.patch('posts/1', {
        title: 'test patch'
    })
]);

httpTest('parallel HTTP enforce statuses | POST, PUT, PATCH', [
    testApi.endPoint.post('posts/'),
    testApi.endPoint.put('posts/1', {
        title: 'test put'
    }),
    testApi.endPoint.patch('posts/1', {
        title: 'test patch'
    })
], [201, 200, 200]);


httpTest('enforce response body | status and headers', testApi.endPoint.get('posts/1'),
    200,
    {
        "userId": 1,
        "id": 1,
        "title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
        "body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
    },
    {
        'x-powered-by': 'Express'
    }
);


credits

Package Sidebar

Install

npm i co-http-test

Weekly Downloads

1

Version

0.3.1

License

MIT

Last publish

Collaborators

  • maxmill