api-test
Advanced tools
Comparing version 2.3.0 to 2.4.0
@@ -15,4 +15,6 @@ 'use strict' | ||
this.name = name | ||
/** @member {string} */ | ||
this.collection = collection | ||
/** @member {Obj} */ | ||
@@ -34,2 +36,6 @@ this.value = value | ||
value = this.value.execute(context, '<' + this.name + ' in ' + this.collection + '>') | ||
if (context.defaultDocuments[this.collection]) { | ||
setDefaults(value, context.defaultDocuments[this.collection]) | ||
} | ||
context[that.name] = copyDeep(value) | ||
@@ -52,4 +58,3 @@ db.collection(this.collection).insert(context[that.name], { | ||
return x.map(copyDeep) | ||
} else if (x && typeof x === 'object' && | ||
(x.constructor === Object || !Object.getPrototypeOf(x))) { | ||
} else if (isObject(x)) { | ||
// Map | ||
@@ -64,2 +69,30 @@ r = Object.create(null) | ||
} | ||
} | ||
/** | ||
* @param {Object} value | ||
* @param {Object} defaults | ||
*/ | ||
function setDefaults(value, defaults) { | ||
var key | ||
for (key in defaults) { | ||
if (!(key in value)) { | ||
// Not present, simply set | ||
// No need to copyDeep here because it will be done after | ||
// setDefaults returns | ||
value[key] = defaults[key] | ||
} else if (isObject(value[key]) && isObject(defaults[key])) { | ||
// Recurse | ||
setDefaults(value[key], defaults[key]) | ||
} | ||
} | ||
} | ||
/** | ||
* @param {*} x | ||
* @returns {boolean} | ||
*/ | ||
function isObject(x) { | ||
return x && typeof x === 'object' && (x.constructor === Object || !Object.getPrototypeOf(x)) | ||
} |
@@ -33,2 +33,3 @@ /*globals describe, before, it*/ | ||
* @param {Function} [options.it] | ||
* @param {Object<String, Object>} [options.defaultDocuments] | ||
*/ | ||
@@ -38,2 +39,5 @@ module.exports = function (folder, options) { | ||
// Save defaultDocuments to baseContext to make it available for the script | ||
baseContext.defaultDocuments = options.defaultDocuments || Object.create(null) | ||
// Prepare options | ||
@@ -40,0 +44,0 @@ options.describe = options.describe || describe |
{ | ||
"name": "api-test", | ||
"version": "2.3.0", | ||
"version": "2.4.0", | ||
"author": "Sitegui <sitegui@sitegui.com.br>", | ||
@@ -19,6 +19,6 @@ "description": "API testing made simple", | ||
"async": "^0.9.0", | ||
"mocha": "^2.1.0", | ||
"mongodb": "^1.4.33", | ||
"request": "^2.53.0", | ||
"should": "^5.0.1" | ||
"mocha": "^2.2.1", | ||
"mongodb": "^2.0.25", | ||
"request": "^2.54.0", | ||
"should": "^5.2.0" | ||
}, | ||
@@ -33,6 +33,6 @@ "license": "MIT", | ||
"devDependencies": { | ||
"body-parser": "^1.12.0", | ||
"express": "^4.12.2", | ||
"mongoose": "^3.8.24" | ||
"body-parser": "^1.12.2", | ||
"express": "^4.12.3", | ||
"mongoose": "^4.0.1" | ||
} | ||
} |
@@ -63,4 +63,6 @@ # API Test | ||
The syntax for _docDescription_ is described bellow | ||
The syntax for _docDescription_ is described bellow. | ||
Most of times, documents have a base strucuture with some default fields. You do not need to repeat yourself in this case, see the option `defaultDocuments` bellow. | ||
#### Clearing collections | ||
@@ -148,2 +150,3 @@ The syntax is simply: | ||
* `baseUrl`: the base API url. Every request url will be composed from this base and the test name. | ||
* `defaultDocuments`: (optional) the default structure for documents in each collection. See [issue #1](https://github.com/clubedaentrega/api-test/issues/1) for details | ||
* `describe`, `it`, `before`: (optional) the mocha interface. Defaults to global mocha functions | ||
@@ -150,0 +153,0 @@ * `context`: (optional) define your own variables/functions accessible to object definitions |
@@ -7,4 +7,5 @@ # user/signup | ||
### user is | ||
name: 'Guilherme' | ||
password: '1234' | ||
defaultDocuments.users with | ||
name: 'Guilherme' | ||
password: '1234' | ||
@@ -11,0 +12,0 @@ ## Invalid username |
@@ -8,4 +8,5 @@ # Signup + Login | ||
### user is | ||
name: 'Guilherme' | ||
password: '12345' | ||
defaultDocuments.users with | ||
name: 'Guilherme' | ||
password: '12345' | ||
@@ -12,0 +13,0 @@ ## Signup |
@@ -19,3 +19,7 @@ 'use strict' | ||
password: String, | ||
token: String | ||
token: String, | ||
isActive: { | ||
type: Boolean, | ||
default: true | ||
} | ||
})) | ||
@@ -86,2 +90,4 @@ | ||
token: String(Math.random()) | ||
}, { | ||
new: true | ||
}, function (err, user) { | ||
@@ -88,0 +94,0 @@ if (err) { |
@@ -15,3 +15,8 @@ /*globals before*/ | ||
baseUrl: 'http://localhost:8000/', | ||
recursive: true | ||
recursive: true, | ||
defaultDocuments: { | ||
users: { | ||
isActive: true | ||
} | ||
} | ||
}) |
66750
1950
213
+ Addedbson@1.0.9(transitive)
+ Addedbuffer-shims@1.0.0(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addedes6-promise@3.2.1(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedmongodb@2.2.36(transitive)
+ Addedmongodb-core@2.1.20(transitive)
+ Addedprocess-nextick-args@1.0.7(transitive)
+ Addedreadable-stream@2.2.7(transitive)
+ Addedrequire_optional@1.0.1(transitive)
+ Addedresolve-from@2.0.0(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedsemver@5.7.2(transitive)
+ Addedstring_decoder@1.0.3(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
- Removedabort-controller@3.0.0(transitive)
- Removedbase64-js@1.5.1(transitive)
- Removedbson@0.2.22(transitive)
- Removedbuffer@6.0.3(transitive)
- Removedevent-target-shim@5.0.1(transitive)
- Removedevents@3.3.0(transitive)
- Removedieee754@1.2.1(transitive)
- Removedkerberos@0.0.11(transitive)
- Removedmongodb@1.4.40(transitive)
- Removednan@1.8.4(transitive)
- Removedprocess@0.11.10(transitive)
- Removedreadable-stream@4.5.2(transitive)
- Removedstring_decoder@1.3.0(transitive)
Updatedmocha@^2.2.1
Updatedmongodb@^2.0.25
Updatedrequest@^2.54.0
Updatedshould@^5.2.0