/* eslint-env mocha */ /* eslint-disable func-names, prefer-arrow-callback */ /* eslint-disable import/no-absolute-path */ import { expect } from 'chai'; import ActiveFiresUnion from '/imports/api/ActiveFiresUnion/ActiveFiresUnion'; const centerid = { type: 'Point', coordinates: [-5.905956029891968, 43.55727622097011] }; const shape = { type: 'Polygon', coordinates: [[[-5.9084, 43.5558], [-5.906, 43.5558], [-5.906, 43.5566], [-5.9036, 43.5566], [-5.9036, 43.5583], [-5.9061, 43.5583], [-5.9061, 43.558], [-5.9084, 43.558], [-5.9084, 43.5558]]] }; // `new Date(...)` (the old test used bare `Date(...)`, which yields a string and // fails collection2 schema validation on a Date field). const fireUnion = { centerid, shape, when: new Date('2018-05-02T16:11:04.617Z') }; describe('activeFireUnion insert', () => { it('should insert fire union', async () => { // Remove any leftover from a previous run const alreadyInserted = await ActiveFiresUnion.findOneAsync({ centerid }); if (alreadyInserted) { await ActiveFiresUnion.removeAsync(alreadyInserted._id); } const insertedId = await ActiveFiresUnion.insertAsync(fireUnion); ActiveFiresUnion.schema.validate(fireUnion); const inserted = await ActiveFiresUnion.findOneAsync(insertedId); delete inserted._id; expect(inserted).to.deep.equal(fireUnion); await ActiveFiresUnion.removeAsync(insertedId); expect(await ActiveFiresUnion.find({ _id: insertedId }).countAsync()).to.equal(0); }); });