Created
February 26, 2014 14:23
-
-
Save davidworkman9/9230304 to your computer and use it in GitHub Desktop.
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
/* global Tinytest:true */ | |
/* global testAsyncMulti:true */ | |
'use strict'; | |
if (Meteor.isServer) { | |
Meteor.methods({ | |
'remove-all-users': function () { return Meteor.users.remove({}); } | |
}); | |
} | |
if(Meteor.isClient) (function () { | |
var afterremoveUsers = function (test, expect) { | |
Accounts.createUser({ | |
email: '[email protected]', | |
password: 'password', | |
profile: { | |
firstName: 'test', | |
lastName: 'tester' | |
} | |
}, expect(function (err) { | |
test.isUndefined(err); | |
var superUser = Meteor.users.findOne({ _id: Meteor.userId() }); | |
test.equal(superUser.isSuperUser(), true, 'Expect first client user to be super user'); | |
test.equal(superUser.isVerified(), true, 'Expect first client user to be verified'); | |
})); | |
}; | |
testAsyncMulti('Shore Users Client - Users Schema Functions', [ | |
function (test, expect) { | |
Meteor.call('remove-all-users', expect(function (err) { | |
test.isUndefined(err); | |
})); | |
}, | |
afterremoveUsers | |
]); | |
})(); |
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
/* global Tinytest:true */ | |
/* global testAsyncMulti:true */ | |
'use strict'; | |
var superUserId, verifiedUserId, unverifiedUserId; | |
/** | |
* Setup | |
*/ | |
function setup() { | |
Meteor.users.remove({}); | |
superUserId = Accounts.createUser({ | |
email: '[email protected]', | |
password: 'password', | |
profile: { | |
firstName: 'test', | |
lastName: 'tester' | |
} | |
}); | |
verifiedUserId = Accounts.createUser({ | |
email: '[email protected]', | |
password: 'password', | |
profile: { | |
firstName: 'test', | |
lastName: 'tester' | |
} | |
}); | |
Meteor.users.update({ _id: verifiedUserId }, { $set: { verified: true } }); | |
unverifiedUserId = Accounts.createUser({ | |
email: '[email protected]', | |
password: 'password', | |
profile: { | |
firstName: 'test', | |
lastName: 'tester' | |
} | |
}); | |
} | |
/** | |
* Tests | |
*/ | |
Tinytest.add('Shore Users Server - Verify first user is verified & super user', function (test) { | |
setup(); | |
var superUser = Meteor.users.findOne({ _id: superUserId }); | |
test.equal(superUser.isVerified(), true, 'Expect isVerified to return true for the first user'); | |
test.equal(superUser.isSuperUser(), true, 'Expect isSuperUser to return true for the first user'); | |
}); | |
Tinytest.add('Shore Users Server - Users Helper Class', function (test) { | |
setup(); | |
test.equal(Users.allowUser(verifiedUserId), true, 'Expect allowUser to return true for user that is verified'); | |
test.equal(Users.denyUser(verifiedUserId), false, 'Expect denyUser to return false for user that is verified'); | |
test.equal(Users.allowUser(unverifiedUserId), false, 'Expect allowUser to return false for user that is not verified'); | |
test.equal(Users.denyUser(unverifiedUserId), true, 'Expect denyUser to return true for user that is not verified'); | |
test.equal(Users.allowUser('this Id does not exist'), false, 'Expect allowUser to return false for user that does not exist'); | |
test.equal(Users.denyUser('this Id does not exist'), true, 'Expect denyUser to return true for user that does not exist'); | |
}); | |
Tinytest.add('Shore Users Server - Users Schema Functions', function (test) { | |
setup(); | |
var verifiedUser = Meteor.users.findOne({ _id: verifiedUserId }), | |
unverifiedUser = Meteor.users.findOne({ _id: unverifiedUserId }); | |
test.equal(verifiedUser.isVerified(), true, 'Expect isVerified to return true for verified users'); | |
test.equal(unverifiedUser.isVerified(), false, 'Expect isVerified to return false for unverified users'); | |
test.equal(verifiedUser.isSuperUser(), false, 'Expect isSuperUser to return false for verified users'); | |
test.equal(unverifiedUser.isSuperUser(), false, 'Expect isSuperUser to return false for unverified users'); | |
test.equal(unverifiedUser.getName(), 'test' + ' tester', 'User.getName'); | |
test.equal(verifiedUser.getNameWithEmail(), 'test' + ' tester' + ' ([email protected])', 'User.getNameWithEmail'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment