Blame view

imports/api/documents/methods.tests.js 1.39 KB
f0c912bf1   tmcdeveloper   add method tests ...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
  /* eslint-env mocha */
  /* eslint-disable func-names, prefer-arrow-callback */
  
  import { assert } from 'meteor/practicalmeteor:chai';
  import { resetDatabase } from 'meteor/xolvio:cleaner';
  import { Documents } from './documents.js';
  import { insertDocument, updateDocument, removeDocument } from './methods.js';
  
  describe('Documents methods', function () {
    beforeEach(function () {
      if (Meteor.isServer) {
        resetDatabase();
      }
    });
  
    it('inserts a document into the Documents collection', function () {
      insertDocument.call({ title: 'You can\'t arrest me, I\'m the Cake Boss!' });
      const getDocument = Documents.findOne({ title: 'You can\'t arrest me, I\'m the Cake Boss!' });
      assert.equal(getDocument.title, 'You can\'t arrest me, I\'m the Cake Boss!');
    });
  
    it('updates a document in the Documents collection', function () {
      const { _id } = Factory.create('document');
  
      updateDocument.call({
        _id,
        update: {
          title: 'You can\'t arrest me, I\'m the Cake Boss!',
        },
      });
  
      const getDocument = Documents.findOne(_id);
      assert.equal(getDocument.title, 'You can\'t arrest me, I\'m the Cake Boss!');
    });
  
    it('removes a document from the Documents collection', function () {
      const { _id } = Factory.create('document');
      removeDocument.call({ _id });
      const getDocument = Documents.findOne(_id);
      assert.equal(getDocument, undefined);
    });
  });