Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mongo-assert

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongo-assert

Mongo assertion library

  • 0.3.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

mongo-assert

Mongo assertion library.

Build Status Code Coverage npm version

Why

This library is created to assert made changes in mongodb. Useful when you want to be sure that method added, updated or deleted only one document, and other were unchanged.

Install

$ npm i -D mongo-assert

Usage

const nassert = require('n-assert')
const mongoassert = require('mongo-assert')

const initialUsers = [
  {
    _id: nassert.getObjectId(),
    email: 'pen@mail.com',
    firstName: 'Piter',
    lastName: 'Pen'
  },
  {
    _id: nassert.getObjectId(),
    email: 'smith@mail.com',
    firstName: 'John',
    lastName: 'Smith'
  }
]

it('should update user', async () => {
  let filter = { _id: initialUsers[0]._id }
  let userData = {
      email: 'smith-another-email@mail.com'
  }
  let updatedUser = {
    _id: initialUsers[0]._id,
    email: 'smith-another-email@mail.com'
  }

  await User.create(initialUsers)
  await usersSrvc.updateUser({ filter, userData })

  await mongoassert.assertCollection({
    model: User,
    initialDocs: initialUsers,
    changedDoc: updatedUser,
    typeOfChange: updatedUser ? 'updated' : null,
    sortField: '_id'
  })
})

API

  • assertCollection({ model, initialDocs, changedDoc, typeOfChange, sortField })
    Asserts mongodb collection. Loads all documents in the collection, merges initial collection with changed document and asserts.

    • model - mongoose model.
    • initialDocs - initial documents collection.
    • changedDoc - changed document, must be omitted or undefined if collection is unchanged.
    • typeOfChange - the type of the change (created, updated, deleted), must be omitted if collection is unchanged.
    • sortField - the field which should be used for sorting actual and expected collections before asseting.

Licence

Licensed under the MIT license.

Author

Alexander Mac

Keywords

FAQs

Package last updated on 22 May 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc