tasks.tests.js 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /* eslint-env mocha */
  2. import { Meteor } from 'meteor/meteor';
  3. import { Random } from 'meteor/random';
  4. import { assert } from 'meteor/practicalmeteor:chai';
  5. import { Tasks } from './tasks.js';
  6. if (Meteor.isServer) {
  7. describe('Tasks', () => {
  8. describe('methods', () => {
  9. const userId = Random.id();
  10. let taskId;
  11. beforeEach(() => {
  12. Tasks.remove({});
  13. taskId = Tasks.insert({
  14. text: 'test task',
  15. createdAt: new Date(),
  16. owner: userId,
  17. username: 'tmeasday',
  18. });
  19. });
  20. it('can delete owned task', () => {
  21. // Find the internal implementation of the task method so we can
  22. // test it in isolation
  23. const deleteTask = Meteor.server.method_handlers['tasks.remove'];
  24. // Set up a fake method invocation that looks like what the method expects
  25. const invocation = {userId};
  26. // Run the method with `this` set to the fake invocation
  27. deleteTask.apply(invocation, [taskId]);
  28. // Verify that the method does what we expected
  29. assert.equal(Tasks.find().count(), 0);
  30. });
  31. });
  32. });
  33. }