Skip to content

Commit

Permalink
improved doc, tests
Browse files Browse the repository at this point in the history
  • Loading branch information
artwells committed Nov 26, 2013
1 parent f40bcf1 commit 35c4a06
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 12 deletions.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,23 @@ Automatically add visitor as anonymous guest with userId

##Installation
```sh
mrt add accounts-base
mrt add accounts-password
mrt add accounts-guest
```

then in a client accessible code
then in client-only code
```javascript
Meteor.loginVisitor
Meteor.loginVisitor()
```

and that's it! You'll want to clean out the users db of old accounts

optionally (to clean out old guest accounts) in server-only code
```javascript
Meteor.loginVisitor();
```

Now Meteor.userId() will be populated for each new visitor, including across reloads



Expand Down
9 changes: 9 additions & 0 deletions accounts-guest-client-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Tinytest.add(
'guest - account creation',
function (test) {
res = Meteor.createGuest();
console.log(res + 'ko');
uid = Meteor.userId();
test.isTrue((typeof uid !== undefined && typeof uid !== null), 'no userId returned');
}
);
3 changes: 2 additions & 1 deletion accounts-guest-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
*
*/
Meteor.createGuest = function (fn) {
Accounts.createUser({password: Meteor.uuid(), username: Meteor.uuid(), profile: {guest: "guest", name: 'Guest'}});
res = Accounts.createUser({password: Meteor.uuid(), username: Meteor.uuid(), profile: {guest: "guest", name: 'Guest'}});
console.log(res);
};


Expand Down
19 changes: 19 additions & 0 deletions accounts-guest-server-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

Tinytest.add(
'guest - remove guests',
function (test) {
var before = new Date();
before.setHours(before.getHours() - 100000);
Meteor.createGuest();
var username = Meteor.uuid();
Accounts.createUser({password: Meteor.uuid(), username: username, profile: {guest: "guest", name: 'Guest'}});
Meteor.users.update({username: username},{$set: {createdAt: before}});
usr = Meteor.users.findOne({username: username});
test.isFalse((typeof usr === 'undefined'), 'guest account not defined');
before.setHours(before.getHours() + 1);
res = Accounts.removeOldGuests(before);
test.equal(res, 1, 'should exactly one deleted');
usr = Meteor.users.findOne({username: username});
test.isTrue((typeof usr === 'undefined'), 'guest account not deleted');}
);

3 changes: 2 additions & 1 deletion accounts-guest-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ Accounts.removeOldGuests = function (before) {
before = new Date();
before.setHours(before.getHours() - 1);
}
return Meteor.users.remove({createdAt: {$lte: before}, 'profile.anon': 'anon'});
res = Meteor.users.remove({createdAt: {$lte: before}, 'profile.guest': 'guest'});
return res;
};
6 changes: 0 additions & 6 deletions accounts-guest-tests.js

This file was deleted.

5 changes: 4 additions & 1 deletion package.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ Package.on_use(function (api) {

Package.on_test(function (api) {
api.use(['accounts-base', 'accounts-password', 'tinytest'], ['client','server']);
api.add_files('accounts-guest-tests.js', ['client']);
api.add_files('accounts-guest-client.js', ['client','server']);
api.add_files('accounts-guest-server.js', 'server');
api.add_files('accounts-guest-client-tests.js', 'client');
api.add_files('accounts-guest-server-tests.js', 'server');
});

0 comments on commit 35c4a06

Please sign in to comment.