parse-tester
v0.1.0
Published
Tool for creating parse based backend tests
Downloads
1
Readme
#Parse tester
Tool for creating automated tests for parse.com based based backends.
It's based on top of Jasmine, so you can group tests using describe
and assert using expect
.
To launch tests just launch node-jasmine <your-test-dir>
. As in jasmine, only cases in files with their names ending with spec
will be tested.
Getting started
To make TestCase
constructing function avalilable you have to:
var TestCase = require('parse-tester')(config);
It's created this way for future tests because allow to override ALL of required dependencies. Config format is described below.
Config
Config is simple object as presented below:
var config = {
apiUrl: 'https://api.parse.com/1/functions/',
requestSetup: {
hostname: 'api.parse.com',
port: 443,
method: 'POST',
headers: {
'X-Parse-Session-Token': '<your session token>',
'X-Parse-Application-Id': '<yours application id>',
'X-Parse-REST-API-Key': '<your rest api key>',
'Content-Type': 'application/json'
}
}
};
Examples
The simplest test you can write is:
var noItems = new TestCase({
title: 'simple test',
types: [],
data: [],
request: {
functionName: 'getItems',
body: {}
},
assertions: function (response, data, types) {
expect(true).toBe(true);
}
});
Tester will create jasmine suite for given test and launch assertions after each needed request will be received. All given fields are required.
Given object has to be in format as given:
title
- it's the same string which would you use in jasmine'sdescribe
types
- array with string containing names of types of which all objects will be downloaded from parse after making main requestdata
:- It can be array containing definitions of objects which will be persist in parse's database. Every object is in format as given:
type
- name of object's type (it will be used for saving object in proper table)body
- object containing object's data
- It can be object containing two fields:
items
- array defined as abovelinks
- array containing links (described below)
- It can be array containing definitions of objects which will be persist in parse's database. Every object is in format as given:
request
- object containing two fields:functionName
- name of cloud code function which will calledbody
- object with request body (only data)
assertions
- function containing all assertions for case. It will receive arguments:response
,data
,types
where:response
- response object in format compatible with http/https node packagesdata
- object with data items, it's the same (but extended) object which was defined indata
field, it is in format:items
- array containing defined items, every in format described belowlinks
- array containing links
types
- object containing downloaded whole tables as given intypes
field. Detailed description is below.
After that just call noItems.run()
.
Data items
type
- type of given itembody
- item's dataobjectId
- item's id (given by parse). This field is added in preparing data phase before request.actual
- actual item's state. This field is added in downloading data phase after request.
Links
It's way for creating connections between objects stored in parse's db.
source
- index of object beeing a source of data for other objectfunc
- linking function, it will receive object beeing source, can be used for example for preparing requests as given:var linkedRequest = new TestCase((function () { var testObj = { 'title': 'linked request test', types: [], data: { items: [ { type: 'SomeType', body: { data: 'foo' } } ], links: [ { source: 0, func: linker } ] }, request: { functionName: 'someFunc', body: null }, assertions: function (response, data, types) { expect(true).toBe(true); } }; function linker (item) { testObj.request.body = { id: item.objectId }; } return testObj; })());
target
- index of linking targetproperties
- object containing properties to copy where key is property name in source object, value is string containing property name in target object. If source property is equalobjectId
, then will be created pointer to source object
If linking function is present, then target
and properties
are ignored.
Types
It's array containing names of types to download after main request. When data are downloaded, then under key beeing type name is array of objects with given type as they are stored in parse.