BatchedUpdateTests.mjs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { spawnSync } from 'child_process'
  2. import { expect } from 'chai'
  3. import { db, ObjectId } from '../../../app/src/infrastructure/mongodb.js'
  4. describe('BatchedUpdateTests', function () {
  5. it('can handle non linear insert order', async function () {
  6. await db.systemmessages.insertOne({
  7. content: '1',
  8. _id: new ObjectId('500000000000000000000000'),
  9. })
  10. await db.systemmessages.insertOne({
  11. content: '2',
  12. _id: new ObjectId('400000000000000000000000'),
  13. })
  14. await db.systemmessages.insertOne({
  15. content: '3',
  16. _id: new ObjectId('600000000000000000000000'),
  17. })
  18. await db.systemmessages.insertOne({
  19. content: '4',
  20. _id: new ObjectId('300000000000000000000000'),
  21. })
  22. spawnSync(process.argv0, [
  23. '--input-type=module',
  24. '-e',
  25. 'import BatchedUpdateModule from "./scripts/helpers/batchedUpdate.mjs"; BatchedUpdateModule.batchedUpdateWithResultHandling("systemmessages", { content: { $ne: "42" }}, { $set: { content: "42" } })',
  26. ])
  27. await expect(
  28. db.systemmessages.find({}).project({ content: 1, _id: 0 }).toArray()
  29. ).to.eventually.deep.equal([
  30. { content: '42' },
  31. { content: '42' },
  32. { content: '42' },
  33. { content: '42' },
  34. ])
  35. })
  36. })