npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@nestjs-cucumber-kit/mongodb

v2.1.0

Published

Nestjs cucumber kit mongodb

Downloads

9

Readme

@nestjs-cucumber-kit/mongodb

The @nestjs-cucumber-kit/mongodb is a MongoDB plugin for the NestJS Cucumber Kit. It replaces the standard MongoDB connection with an in-memory MongoDB server, facilitating easier and more efficient testing.

Installation

Install the package using either npm or Yarn:

Using npm:

npm install @nestjs-cucumber-kit/mongodb --save-dev

Using Yarn:

yarn add @nestjs-cucumber-kit/mongodb --dev

Configuration

To configure, add the following provider to your config.js:

config.js

import { INestApplication, ValidationPipe } from '@nestjs/common';
import * as path from 'path';
import { FixtureSteps, HttpSteps, StorageSteps, ICucumberKitConfig } from '@nestjs-cucumber-kit/core';
import { MongoDBProvider, MongoDBSteps } from '@nestjs-cucumber-kit/mongodb';

export const config: ICucumberKitConfig = {
  steps: [HttpSteps, StorageSteps, FixtureSteps, MongoDBSteps],
  providers: [MongoDBProvider],
  dataDir: path.join(__dirname, '..', 'data'),
  appConfigure: (app: INestApplication) => {
    app.useGlobalPipes(new ValidationPipe());
  },
};

Setting Up Test Data with Fixtures

You can add fixtures to set up your test data. Here's an example:

data/fixture/item.fixture.ts

import { Model } from 'mongoose';
import { getModelToken } from '@nestjs/mongoose';
import { BaseFixture } from '@nestjs-cucumber-kit/core';
import { Item, ItemDocument } from '../../app/item';

export default class ItemFixture extends BaseFixture {
  async apply(): Promise<void> {
    const itemModel: Model<ItemDocument> = this.app.get(getModelToken(Item.name));
    const items = [
      { _id: '1', name: 'test' },
      { _id: '2', name: 'test' },
    ];

    await itemModel.insertMany(items);
  }
}

Usage Examples

Below are some scenarios illustrating how to use the plugin:

Feature: MongoDB

Feature: MongoDB

  Background: Load data
    Given I load fixture from the file "fixture/item.fixture"

  Scenario: Find a single item and store the result
    Given I store the key "itemName" with the value "test"
    When I findOne in model "Item" with JSON and store in "item":
      """
      { "name": "{{itemName}}" }
      """
    Then the key "item" should contain JSON:
      """
      { "_id": "1", "name": "{{itemName}}" }
      """

  Scenario: Assert exact match for a single item
    When I findOne in model "Item" with JSON:
      """
      { "name": "test" }
      """
    And the result should contain JSON:
      """
      { "_id": "1", "name": "test" }
      """

  Scenario: Find multiple items and store the results
    When I find in model "Item" with JSON and store in "items":
      """
      { "name": "test" }
      """
    Then the key "items" should contain JSON:
      """
      [{ "_id": "1", "name": "test" }, { "_id": "2", "name": "test" }]
      """

  Scenario: Assert truthy & falsy
    When I find in model "Item" with JSON and store in "items":
      """
      { "name": "test" }
      """
    Then the key "items" should be truthy
    And I findOne in model "Item" with JSON and store in "item":
      """
      { "name": "test12344" }
      """
    Then the key "item" should be falsy

Complete MongoDB example.