New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

bluecat

Package Overview
Dependencies
Maintainers
1
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bluecat - npm Package Compare versions

Comparing version 0.3.2 to 0.3.3

2

lib/index.js
exports.ServiceSync = require('./service.gen.sync');
exports.ServiceAsync = require('./service.gen.async');
exports.Api = require('./service.api');
exports.version = '0.3.2';
exports.version = '0.3.3';
{
"name": "bluecat",
"version": "0.3.2",
"version": "0.3.3",
"description": "Generic REST API Test Framework",
"repository": {
"type" : "git",
"url" : "https://github.com/chenchaoyi/bluecat"
"type": "git",
"url": "https://github.com/chenchaoyi/bluecat"
},

@@ -12,10 +12,21 @@ "engines": {

},
"keywords": ["testing", "api", "REST", "bdd", "bluecat"],
"keywords": [
"testing",
"api",
"REST",
"bdd",
"bluecat"
],
"dependencies": {
"request": "2.55.0",
"fibers": ">=1.0.5",
"hoek": "^2.13.0",
"promise": ">=7.0.1",
"hoek": "^2.13.0"
"request": "2.55.0"
},
"scripts": {
"test": "./node_modules/.bin/mocha test/"
},
"devDependencies": {
"chai": "^2.3.0",
"mocha": "^2.2.5",
"grunt-cli": "^0.1.13",

@@ -22,0 +33,0 @@ "grunt": "^0.4.5",

@@ -9,9 +9,20 @@ ## Bluecat

A REST API testing framework built on node.js that makes testing API endpoints straightforward.
A REST API testing framework built on Node.js that makes testing API endpoints straightforward.
* Define your APIs in a json file, Bluecat will create all the methods for you
* Define your APIs in a json file, `Bluecat` will create all the methods for you
* Callbacks are removed so tests that have a complex API call flow will be more clear
* Full control over the request URL query, headers and body in test case
* Automatically maintains session cookies for you for HTTP API call flows
* [Convenience methods](#usage) that helps to handle complex scenario
## Table of contents
- [Installation](#installation)
- [Example](#example)
- [Usage](#usage)
- [Logging](#logging)
- [License](#license)
---
## Installation ##

@@ -22,3 +33,5 @@ ```bash

## Simple Sample Usage ##
---
## Example ##
* First define your API in config/api.json:

@@ -35,3 +48,2 @@

}
```

@@ -49,12 +61,14 @@

before(function() {
t = new Bluecat.ServiceSync(Api, 'mobile.walmart.com');
t = new Bluecat.ServiceSync(Api, 'api.mobile.walmart.com');
})
it('typeahead?term=toy&cat=0&num=8', function(done) {
it('GET typeahead?term=toy&cat=0&num=2', function(done) {
t.run(function() {
// send GET to typeahead?term=toy&cat=0&num=8
// send GET to http://api.mobile.walmart.com/typeahead?term=toy&cat=0&num=2
var r = t.typeahead.GET({
term: 'xbox',
cat: 8,
num: 0
query: {
term: 'toy',
cat: 0,
num: 2
}
});

@@ -70,5 +84,103 @@

})
```
---
## Usage ##
<!--Usage is a two steps process. First, define the API structure in config/api.json:-->
#### `Bluecat.ServiceSync(api, host, options)`
Create a new bluecat service object, with desired [options](https://github.com/request/request/blob/master/README.md#requestoptions-callback).
```javascript
var Bluecat = require('bluecat');
var Api = Bluecat.Api('mobileapi');
var service = new Bluecat.ServiceSync(Api, 'api.mobile.walmart.com', {
gzip: true
});
```
#### `rawRequest(options)`
Sometimes we just want to send a request to some host, which is different than the API host we are testing. You can use `rawRequest(options)` to fully to send it.
```javascript
var Bluecat = require('bluecat');
var Api = Bluecat.Api('mobileapi');
var service = new Bluecat.ServiceSync(Api, 'api.mobile.walmart.com');
var r = lapetus.rawRequest({
method: 'GET',
json: true,
uri: 'https://thirdparty-host/creditcard/encryption.js',
headers: {'accept-encoding': 'gzip'},
});
expect(r.err).to.equal(null);
expect(r.data.statusCode).to.equal(200);
```
#### `setProxy(proxy)`
Set proxy address, all the requests will be sent via a connection to the proxy server.
```javascript
var Bluecat = require('bluecat');
var Api = Bluecat.Api('mobileapi');
var service = new Bluecat.ServiceSync(Api, 'api.mobile.walmart.com');
service.setProxy('http://127.0.0.1:8888')
```
#### `resetCookie()`
Clean up cookie jar, so the next request won't set any cookies in the header.
```javascript
var Bluecat = require('bluecat');
var Api = Bluecat.Api('mobileapi');
var service = new Bluecat.ServiceSync(Api, 'api.mobile.walmart.com');
service.v1.products.search.GET();
service.resetCookie();
service.v1.cart.POST({
body: {
location: '94066'
}
})
```
#### `setHeaders(headers)`
Set headers that will be set in all the requests.
```javascript
var Bluecat = require('bluecat');
var Api = Bluecat.Api('mobileapi');
var service = new Bluecat.ServiceSync(Api, 'api.mobile.walmart.com');
service.setHeaders({'User-Agent': 'Automation'});
```
#### `setSessionRules(rules)`
Set extra session rules other than cookie. Some RESTful APIs defines their own session rules, you can set it in the `Bluecat` framework so you don't have to deal with it in the actual test case.
```javascript
var Bluecat = require('bluecat');
var Api = Bluecat.Api('mobileapi');
var service = new Bluecat.ServiceSync(Api, 'api.mobile.walmart.com');
// The following sessions rules start with 'start-auth-token-value' in the request header AUTH_TOKEN,
// then grab new value from response header REFRESH_AUTH_TOKEN
// and put it in the next request header AUTH_TOKEN
service.setSessionRules({
requestHeader: 'AUTH_TOKEN',
responseHeader: 'REFRESH_AUTH_TOKEN',
startSessionHeader: 'start-auth-token-value'
});
```
---
## Logging
* Launch the node process like `BLUECAT_DEBUG_FILE=/path/to/bluecat.log node script.js` to keep a log file of all the requests/responses information.
* Launch the node process like `BLUECAT_DEBUG_CONSOLE=true node script.js` to see all the requests/responses information from your console (stdout).
---
## License

@@ -75,0 +187,0 @@ Licensed under the [MIT](http://opensource.org/licenses/MIT)

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc