-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added hidden fields support to autocrud.
- Loading branch information
Andrew Rademacher
committed
Sep 9, 2013
1 parent
5504e96
commit 499c7e1
Showing
5 changed files
with
115 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
var _ = require('underscore'), | ||
assert = require('assert'), | ||
getMongoProjection = require('../lib/schema-tools').getMongoProjection; | ||
|
||
var sampleSchema = { | ||
type: 'object', | ||
additionalProperties: false, | ||
properties: { | ||
username: {type:'string', required: true}, | ||
password: {type:'string', required: true, hidden: true}, | ||
stripe: { | ||
type: 'object', | ||
additionalProperties: false, | ||
properties: { | ||
stripeId: {type:'string', required: true}, | ||
stripeKey: {type:'string', required: true, hidden: true} | ||
} | ||
}, | ||
subUsers: { | ||
type: 'array', | ||
items: { | ||
type: 'object', | ||
additionalProperties: false, | ||
properties: { | ||
username: {type:'string', required: true}, | ||
password: {type:'string', required: true, hidden: true} | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
|
||
describe('Schema Manipulation', function() { | ||
it('should generate a mongo projection', function() { | ||
var projection = getMongoProjection(sampleSchema); | ||
assert(_.isEqual(projection, { | ||
'password': 0, | ||
'stripe.stripeKey': 0, | ||
'subUsers.password': 0 | ||
})); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,24 @@ | ||
var _ = require('underscore'), | ||
assert = require('assert'), | ||
getMongoProjection = require('../lib/schema').getMongoProjection; | ||
var assert = require('assert'), | ||
rest = require('restler'), | ||
_ = require('underscore'); | ||
|
||
var sampleSchema = { | ||
type: 'object', | ||
additionalProperties: false, | ||
properties: { | ||
username: {type:'string', required: true}, | ||
password: {type:'string', required: true, hidden: true}, | ||
stripe: { | ||
type: 'object', | ||
additionalProperties: false, | ||
properties: { | ||
stripeId: {type:'string', required: true}, | ||
stripeKey: {type:'string', required: true, hidden: true} | ||
} | ||
}, | ||
subUsers: { | ||
type: 'array', | ||
items: { | ||
type: 'object', | ||
additionalProperties: false, | ||
properties: { | ||
username: {type:'string', required: true}, | ||
password: {type:'string', required: true, hidden: true} | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
|
||
describe('Schema Manipulation', function() { | ||
it('should generate a mongo projection', function() { | ||
var projection = getMongoProjection(sampleSchema); | ||
assert(_.isEqual(projection, { | ||
'password': 0, | ||
'stripe.stripeKey': 0, | ||
'subUsers.password': 0 | ||
})); | ||
describe('Schema Modification', function() { | ||
describe('Projection', function() { | ||
it('should not return hidden fields in GET calls', function(done) { | ||
rest.json(callPrefix + '/schema', { | ||
username: 'testuser', | ||
password: 'pass' | ||
}, null, 'POST') | ||
.on('complete', function(data, res) { | ||
assert(res.statusCode === 200); | ||
|
||
rest.json(callPrefix + '/schema/' + data._id, null, null, 'GET') | ||
.on('complete', function(data, res) { | ||
assert(data.username); | ||
assert(!data.password); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |