Giter Site home page Giter Site logo

vlucas / frisby Goto Github PK

View Code? Open in Web Editor NEW
1.5K 43.0 202.0 697 KB

Frisby is a REST API testing framework built on Jest that makes testing API endpoints easy, fast, and fun.

Home Page: http://frisbyjs.com

JavaScript 100.00%
testing testing-framework rest-api jasmine jest integration-testing hacktoberfest

frisby's People

Contributors

cjsaylor avatar danactive avatar darrenxyli-aa avatar davewid avatar dbashford avatar derekhe avatar donatj avatar ericboehs avatar extronics avatar h1gdev avatar jturmel avatar kmorey avatar koooge avatar kreutter avatar m0x72 avatar marcin-wosinek avatar marcoscarceles avatar petrjasek avatar plpeeters avatar psaxton avatar rblu avatar renanpallin avatar sasikanth avatar slicknutter avatar sri85 avatar sudodoki avatar tleyden avatar tobias-flitsch avatar valentinh avatar vlucas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

frisby's Issues

Scope issue setHeaders

Hi there, thanks for this great module. There is a small scope issue:

Frisby.prototype.setHeaders = function (headers) {
  _.each(headers, function(val, key) {
    this.addHeader(key, val);
  });
  return this;
};

should be

Frisby.prototype.setHeaders = function (headers) {
  var that = this;
  _.each(headers, function(val, key) {
    that.addHeader(key, val);
  });
  return this;
};

Thanks!
Brice

https connections to servers with self-signed certificates

Hello,

I am facing the problem that secure https connections to servers with domains that have self-signed certificates always end up in code 500 errors:

Message:
Expected 500 to equal 200

TCPDump shows up an reset flag in the connection.

If I connect to https servers with domains that have certificates signed from CA's everything wents fine.

I already installed my own CA certificate on my Debian server into the local certificate store. So wget and other programs do not make any trouble.

Any hints on that?

Best wishes
Michael

Sequential execution of specs

Hi,
I have set of spec files in a folder, that will be executed Frisby to test an API. Each files is to test each service in that API. Is there way to execute the scripts files in a sequence, so that, create API script will be invoked first and read API will be invoked next.

Website spammed?

It would appear that the http://frisbyjs.com/ website has been exploited to add some spam links to the header. They should probably be removed. Not sure if this was noticed yet...

Sychronize tests

Hi

Is there a way to synchronize tests sequence without using after(), afterJSON() ?

Basicaly I want to do:

  • send POST, get cookie
  • send GET with this cookie

So now I need to :
var cookie
create().post().after( /* set cookie var */; create().get() )

For better test maintenance I would like to write this:
var cookie
create().post().after( /* set cookie var */)
// cookie is
create().get()

Is this possible in FrisbyJS?

condition for expectJSONTypes

Hi,

Is it possible to write tests with conditions. I would like to be able to write something like: the enpdoint can response me with this one
expectJSONTypes([{
district_id: Number.POSITIVE_INFINITY,
district_name: String
}])

or it may response me with an empty array
expectJSONTypes([])

how can I handle such situations?

bignum parse

Hello all!

Thanks for this libs.
I use it with grunt tasks to provide a API validation before deploy our application.
The use of bignumJSON.parse (https://github.com/vlucas/frisby/blob/master/lib/frisby.js#L1152) break my JSON return and I cannot be able to test some field.

For example:

{
    "count": 2,
    "_embedded": {
        "resource": [
            {
                "id": 2,
                "name": "taraefefe",
                "position": 1,
                "num": 15
            }
        ]
    }
}

Will become:

{
    "count": 2,
    "_embedded": {
        "resource": [
            {
                "id": 2,
                "name": "taraefefe",
                "position": 1,
                "num": { numberStr: '15.0' }
            }
        ]
    }
}

Why bignum parse is used and is it possible to configure it through some globalSetup (I can do the job).

Have a good day!!

$conn->send($msg)! How to get this messenge in client?

Here my code (websocket php using rachet and wamp server!

public function onClose(ConnectionInterface $conn) {
$conn->send("Close client");
}

I will using $conn->send() to send a message for all client but i don't know how to get this message using autobahnJS on client?

create multiple cookie with single file

how can i create multiple cookies with a single file
i have to just merge this two file into one single file
to test it for both valid and invalid cookie
how can i achieve this

///first file
// valid cookie
////////valid_spec.js

var frisby = require('./lib/frisby');
    // Global setup for all tests
    frisby.globalSetup({
      request: {
        headers:{'Accept': 'application/json,  application/x-httpd-php', 'Cookie': 'authenticationToken=5363; activationID=1'}
  },
      timeout: (30 * 1000)
});


    /**
    * Tests -> GET
    */
    frisby.create(' ')
    .get('http://xyz/auto?limit=0')
    .expectStatus(200)
    .expectHeaderContains('content-type', 'application/json')
    .expectJSON('status',{
    message: "SUCCESS",
    code: 1
  })
.toss(); 

//second file
// INVALID cookie
////////////// invalid_spec.js

var frisby = require('./lib/frisby');

    // Global setup for all tests
    frisby.globalSetup({
      request: {
        headers:{'Accept': 'application/json,  application/x-httpd-php', 'Cookie': 'authenticationToken=5363; activationID=11123fgf'}
  },
      timeout: (30 * 1000)
});


    /**
    * Tests -> GET
    */
    frisby.create(' ')
    .get('http://xyz/auto?limit=0')
    .expectStatus(200)
    .expectHeaderContains('content-type', 'application/json')
    .expectJSON('status',{
    message: "DATABASE_ERROR",
    code: 2
  })
.toss(); 

any answers please

failed to log errors on terminal

I have a good feeling, this error might be more related to jasmine-node than frisbyjs.

A few tests failed but i don't see the error logs.

Thoughts ?

screen shot 2013-11-13 at 10 38 37 pm

Documentation seems fairly out of date

Here are the issues I've noticed:

Missing documentation:
The '&' syntax for paths
.globalSetup()
Would be good to list out what can be configured here.
.timeout()
.reset()
.not()
.addHeader()
.addHeaders()
.removeHeader()
.responseType()
Actually, this appears to be pointless. The value of
.auth()
all of the request methods, such as .get() and .post()
.expectHeaderToMatch()
.expectJSONSchema()
format of the 'length' parameter to .expectJSONLength()
.inspectRequest()
.inspectResponse()
.inspectHeaders()
.inspectStatus()
.retry()
.waits()
.after()
.afterJSON()
.exceptionHandler()
.setResponseJSON()
.setResponseBody()
.setResponseHeaders()
.setResponseHeader()
the 'retry' param to toss()

All of the frisby matchers
toMatchOrBeNull
toMatchOrBeEmpty
toBeType
toBeTypeOrNull
toContainJson
toContainJsonTypes

Also, the documentation in README.MD should match up with the documentation on the frisbyjs.com website.

Additionally, it'd be great if a variety of example scripts were provided to demonstrate the power of Frisby.

I can take a crack at documenting some of this. A pull request makes sense for the README.MD and any examples, but what about for the website content?

Cookie authentication

I see it's possible to authenticate using OAUTH by making subsequent calls after making the OAUTH call, but is there a way to get the returned cookie from a login POST and then add it to the header?

Nested Test in afterJSON not firing

Code im using, calls fine when moved out of afterJSON

frisby.create("POST - Valid statement and return id in array")
  .post(API_DOMAIN+"/statements/",
    stmt4,{"json":true})
    .expectStatus(200)
    .expectHeaderContains("X-Experience-API-Version", API_VER)
    .expectJSONLength(1)
    .expectJSONTypes("?", Array)
    .afterJSON(function(ids) {
        guid4 = ids[0];

        //can't delete at the end
        frisby.create("delete - Statement guid4")
            .delete(API_DOMAIN+"/statements/?statementId="+guid4)
            .toss();
    })
    .toss();

version 0.6.8

Inheriting Frisby

I have inherited Frisby and added few new prototype function over Frisby functions. When i create a new instance of my child class, i want to call the constructor of Frisby, to clear the current objects. Please suggest a way.

Child

var parent = require('frisby');
Child.prototype = frisby.create(msg);
function Child() { .. } 
Child.prototype.fn2 = function(){};
exports.create = function() {
    return (new Child());  
};

Part 2 Basic HTTP auth

vlucas, Could you please provide me with more info on how to get this to work? I'm struggling with how to tell it which url to use. A complete syntax that will run with jasmine-node command would be extremely helpful.

var user = 'myUserName'
var password = 'thePassword'
var urlHere = 'http://myserver.net:8080';

//HTTP Basic Auth
// @param string username
// @param string password
Frisby.prototype.auth = function(user, pass) {
authHash = new Buffer(user + ':' + pass).toString('base64');
this.addHeader('Authorization', 'Basic ' + authHash);
return this;
};

expectJSON unreliable.

The following test fails correctly with the proceeding data set in 0.5.3 but

frisby.create('Requesting the login URL with valid credentials returns a token')
  .auth(setup.user, setup.pass)
  .get(authURL)
  .expectStatus(200)
  .expectJSON({
    result : {
      status: 'error'
    }
  }).inspectJSON()
.toss();

The data set is as follows:

{ status: 'success',
  message: null,
  result: 
   { user_id: '124570',
     token: 'redacted' } }

This erroneously passes for the version npm installs as well as the current master on github, but fails correctly in 0.5.3

Send JSON or raw body

I'm trying to test a POST where the body type is expected to be JSON (not a query string):

POST /api HTTP/1.1
Accept: application/json
Content-Type: application/json; charset=utf-8
Host: localhost

{"hello": "world"}

Is this possible?

ToBeType matcher always return true

Example : testing a simple json like {title: 'my string'}

.expectJSON({title: function(val) { expect(val).toBeType(String); }}) => test pass
.expectJSON({title: function(val) { expect(val).toBeType(Number); }}) => test pass
.expectJSON({title: function(val) { expect(val).toBeType(Array); }}) => test pass

I

Part 3 (last question) - Basic HTTP authentication

Thanks for help! That authed for me.

I think this might be the last question and I'll be all set.

I need to make the auth with several gets (one is shown below with //count of records). If I place the auth in it's on .toss, it does not keep the auth (not using cookies) when I go to my //count of records. So, I'm assuming I need to auth with each new .get. Is there a way to auth in the get? For example, auth in my //count of records.

frisby.create('Test HTTP Basic Auth')
.get('http://someserver.net:8080')
.auth('the_id', 'the_password')
.toss()

//count of records
frisby.create('get a count')
.get('http://someserver.net:8080/service' + '/count')
.expectStatus(200)
.inspectBody()
.toss();

Allow patch method

Please allow also patch HTTP method
currently

frisby.patch

return [TypeError: Object # has no method 'patch']

globalSetup example out of date

Hi vlucas,

First off, thanks for contributing this node module. I've found it pretty darned helpful and quick to get up and running with!

I believe that the example in your README.md is out of date. To wit:

frisby.create('GET user johndoe')
  .globalSetup({ // globalSetup is for ALL requests
    request: {
      headers: { 'X-Auth-Token': 'fa8426a0-8eaf-4d22-8e13-7c1b16a9370c' }
    }
  })
  .get(URL + '/users/3.json')

...should be...

frisby.globalSetup({ // globalSetup is for ALL requests
    request: {
      headers: { 'X-Auth-Token': 'fa8426a0-8eaf-4d22-8e13-7c1b16a9370c' }
    }
  });

frisby.create(...)

Cheers,
Felix

[question] Uploading files

Is there an easy way to test uploading a file in Frisby?

ATM I'm thinking of setting a header with a boundary and manually building the body with values and boundary. For the file itself I was going to base64 encode a raw file before hand, pasting that into my Frisby test and base64 decode it just before it's tossed.

Is that the best way to go about testing this?

Running a single test

Is there a way to make Frisby run only a single test. I would like to run an isolated test when debugging a specific error. Something like,

frisby.create.only('foo') // followed by the chain and toss.

I'm not terribly familiar with the jasmine layer underneath. Would this be possible with Frisby/Jasmine?

Thanks for this project. The json matchers in particular are well thought out and very handy!

Test describe message printed twice

In toss method:

Hello,

The describe message is concatenated to all tests itinfo message. This results in displaying the describe message twice, for example:

1) Frisby Test: this is the describe message this is the describe message
    [ GET api url being tested (itInfo message) ]
   Message:
     Error: whatever error

I don't know why it's like that but simple solution is to replace the it (...) line with this:

it("\n\t[ " + self.current.itInfo + " ]", function() { ... }

in toss method:

Frisby.prototype.toss = function() {
  var self = this;

  // Assemble all Jasmine tests and RUN them!
  describe('Frisby Test: ' + self.current.describe, function() {

    // Spec test
    it(self.current.describe + "\n\t[ " + self.current.itInfo + " ]", function() { ... }

Support optional return values

Currently I have a collection of users that may or may not have email and displayName properties attached to them. I want to be able to validate that each object returned either a) has an email property and it's a String or b) it doesn't have an email property at all.

frisby.create('GET /api/users')
  .get(url + '/api/users')
  .expectStatus(200)
  .expectHeaderContains('content-type', 'application/json')
  .expectJSONTypes('*', {
    _id: String,
    siteCode: String,
    username: String,
    displayName: function (val) { expect(val).toBeTypeOrNull(String); },
    email: function (val) { expect(val).toBeTypeOrNull(String); }
  })
  .toss();

POST request frisby

/**
* Tests -> POST add a new user
*/
frisby.create('testAddUser')
.post('http://localhost/payCard/Api/User', JSON.stringify({
userName : 'newApi',
Password : '123456',
installationId : 1,
cityId : 2,
}),{ json: true },{METHOD: 'POST'})
.inspectJSON()
.inspectBody()
.expectStatus(200)
.expectHeaderContains('content-type', 'application/json')
.expectJSON('status',{
StatusMSG: "SUCCESS",
Code: '1'
})
.toss();

console.log(frisby.create('testAddUser'));
console.log(JSON.stringify({
userName : 'newApi',
Password : '123456',
installationId : 1,
cityId : 2,
}));
//
is this code right
and how can i check what and how the json data is going to the api

//api code

//output is INVALID JSON

Unexpected token when posting a json object

When I try to send a json object I get
Unexpected token {

Basically, that's what I am sending:
.post(URL+'user/selfRegistration', { {name: "Alberto"} })

When I remove the json object, I get another error:
.post(URL+'user/selfRegistration', {name: "Alberto" })

Error: A JSONObject text must begin with '{' at character 1

Is it a valid scenario?

Pass value

I have two spec files, file A generates a token, file B needs this token. Is there any way to pass that value? I tried require() & module.exports, but that doesn't seem to work (strange error / value undefined).

Thanks!

[New user] Not receiving reason for failures

Running the tests in windows cl I simply receive Some Red F's for failures but no verbose reasons, I tried --verbose and outputting reports but nothing shows up. Might be jasmine-node? not sure, thanks for the help.

Creating tests in afterJSON mutes verbose

This is your code, but I am doing something similar (logging in then using the token etc for the rest of the logged in tests).

// 'afterJSON' automatically parses response body as JSON and passes it as an argument
  .afterJSON(function(user) {
    // You can use any normal jasmine-style assertions here
    expect(1+1).toEqual(2);

    // Use data from previous result in next test
    frisby.create('Update user')
      .put(URL_AUTH + '/users/' + user.id + '.json', {tags: ['jasmine', 'bdd']})
      .expectStatus(200)
    .toss();
  })
.toss();

This will execute the test correctly, but I only know the test has run because of the finished count.

Note sure why its not verbose once its called in the after command?

unwanted (?) stacktrace message

Hello,

I just installed frisbyjs and did the first tests. In the output I get something about stacktrace. Should that be there? (I think not)

An example of output:

Failures:

  1) Frisby Test: Testing ***
    [ GET ***]
   Message:
     Expected 500 to equal 200.
   Stacktrace:
     Error: Expected 500 to equal 200.
    at Frisby.expectStatus (/usr/local/lib/node_modules/frisby/lib/frisby.js:368:42)
    at Frisby.toss (/usr/local/lib/node_modules/frisby/lib/frisby.js:819:37)
    at Timer.list.ontimeout (timers.js:101:19)

Finished in 0.183 seconds
1 test, 1 assertion, 1 failure, 0 skipped

Maybe worth mentioning: I had trouble to require the module so I did it like that:

var frisby = require('/usr/local/lib/node_modules/frisby');

Testing CRUD

Hello,

Is there any sample how to test a full CRUD ?

The problem is that creating an item returns an ID which needed for the read / update / delete,

testing for example a duplicate of item creation or re-requesting delete after deletion requires sequence in tests,

I guess I can use afterJSON() but is there any better approach as nesting makes the tests look very ugly and hard to read.

Thanks.

Tests failed for reason of timeout.

Hello, help please to resolve problem. While my tests are running one by one in script some of them are failed for reason of timeout 5000ms. How can I fix this problem?
Thanks.

Data driven test using Frisbyjs

Will it be possible to create some data driven framework using Frisbyjs to test our REST APIs?
If yes, then any help in this regard will be helpful.

jasmine-node exits with no output on a bad URL

We ran into an issue when writing some tests where jasmine-node was actually just exiting with 0 even though nothing was happening! It turns out, one of the URLs in our frisby test was bad. Here is an example:

var frisby = require('frisby');

frisby.create('We should be able to GET a URL')
  .get('https://googlenotreally.com')
  .expectStatus(200)
  .toss();

When run with jasmine-node --verbose, this silently exits with 0. The working URL outputs the test and passes normally:

var frisby = require('frisby');

frisby.create('We should be able to GET a URL')
  .get('https://google.com')
  .expectStatus(200)
  .toss();

I'm running with [email protected] and [email protected].

Surely, the test with the bad URL should fail instead of exit cleanly. Any ideas what might be happening?

Running frisby seems to require frisby module installed locally.

I received module not found errors when attempting to run frisby from the command like so:

jasmine-node spec/api/

I installed frisby globally like so:

npm install -g frisby

My node version is : v0.10.4 global only and frisby version 0.6.7 locally and globally

Using expectJSONTypes expects an Array.

Hey,

I'm hitting an API that returns an Object such as:

Users: {
paginationDetails: {...}
users: [item1,item2,item3,...]
}

While expectJSONTypes expects an array, is there a way to hook before expectJSONTypes is invoked or somehow feed it the inner array ?

Thanks.

expectJSONTypes tests always passing?

I can't seem to get any expectJSONTypes tests to fail. As an example, I've used the Frisby Twitter example spec: https://github.com/vlucas/frisby/blob/master/examples/twitter_feed_spec.js

If I change, for example, retweeted: Boolean on line 22 to retweeted: Array, the spec still passes. The same goes for any type I choose. I would expect this test to fail if the value here is anything other than Boolean.

I've also tested this against the frisby_matchers_spec.js tests. As far as I can see it doesn't matter what I change the expectJSONTypes tests to check against, they never fail.

Best way to read JSON from file for expectJSON parameter?

Not sure if this is the best place for this but does anyone know the best way to read JSON from a file and use that for the expectJSON parameter? I've done a fair bit of reading and it doesn't seem like there is a way to do it without using a synchronous method.

Perhaps a method could be added to the code base as many testing frameworks feature this option?

get JSONTypes from API response

For Expected JSON Types it would be helpful if I can get the JSON type from the response string (rather than manually figuring out). Right now I have hack to convert the types from the response string but It would be helpful If I can get one from the frisby framework.

Ex: I would like to get
{ id: Number,
username: String,
is_admin: Boolean
}
For JSON response {
id: 3,
username: 'johndoe',
is_admin: false
}

JsonSchema validation

It would be nice log which Json property is failing. I get output like below, its hard to know where the failure is !

Error: JSONSchema validation failed with the following errors:
> string value found, but a number is required
> string value found, but a number is required
> string value found, but a number is required
> string value found, but a number is required
> string value found, but a number is required
> number value found, but a string is required
> number value found, but a string is required
> number value found, but a string is required
> number value found, but a string is required
> number value found, but a string is required
> number value found, but a string is required
> number value found, but a string is required
> number value found, but a string is required

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.