vlucas / frisby Goto Github PK
View Code? Open in Web Editor NEWFrisby is a REST API testing framework built on Jest that makes testing API endpoints easy, fast, and fun.
Home Page: http://frisbyjs.com
Frisby is a REST API testing framework built on Jest that makes testing API endpoints easy, fast, and fun.
Home Page: http://frisbyjs.com
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.
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!!
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
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.
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
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!
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.
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.
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() { ... }
Could not find license details in readme or a separate license file.
For example, please see the readme file of Wintersmith @ https://github.com/jnordberg/wintersmith#about , the readme file mentions the license and points to it.
Mentioning the license at end of readme seems to be becoming the norm.
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.
Please allow also patch HTTP method
currently
frisby.patch
return [TypeError: Object # has no method 'patch']
I want to be able to see the JSON response when a test fails. But I do not want to see the JSON response when it is successful. How do I do this?
I'm trying to test an older API that expects a post with user parameters that can be read as an array by a PHP backend
curl "http://localhost/user/create" -d "user[email_address]=[email protected]&user[password]=password"
I tried
frisby.create('Subscribe a user')
.post('hhttp://localhost/user/create', {
user[email_address]: "[email protected]",
})
.expectStatus(200)
.toss()
but it choked on the brackets. Is there a way to do this?
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?
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();
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?
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?
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
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...
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?
FrisbyJS help: I need syntax for a Basic HTTP authentication to a server using an id and password. Simple?
Any examples for using OAuth with Frisby.js?
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?
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?
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.
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?
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
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?
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?
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
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
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
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());
};
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;
};
/**
* 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
To replicate the issue, set the headers on a test, they will carry on and overwrite all the other tests.
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
How can we add attachment using Frisbyjs?
Also is there any official open forum for Frisbyjs where we can clarify our doubt?
Hi
Is there a way to synchronize tests sequence without using after(), afterJSON() ?
Basicaly I want to do:
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?
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');
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
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
}
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.
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!
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();
i executed below script, it ran successfully. But the values are not updated as expected. anything wrong in my script?
frisby.create('Post sample Script').
post('http://petstore.swagger.wordnik.com/api/store.json/order?api_key=special-key',{
Order:{id:12,petId:22,quantity:22,shipDate:'2012-09-26T10:00:00.000+0000',status:'placed'}
},
{ json: true})
.expectStatus(200).toss()
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.