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