All Projects → rochejul → sequelize-mocking

rochejul / sequelize-mocking

Licence: MIT license
Sequelize extension to deal with data-mocking for testing

Programming Languages

javascript
184084 projects - #8 most used programming language
Dockerfile
14818 projects

Projects that are alternatives of or similar to sequelize-mocking

mock-data
Mock data in PostgreSQL/Greenplum databases
Stars: ✭ 115 (+85.48%)
Mutual labels:  mock-data
factory
Generate lots of mock API data with ease.
Stars: ✭ 17 (-72.58%)
Mutual labels:  mock-data
storybook-addon-mock
This addon allows you to mock fetch or XMLHttpRequest in the storybook.
Stars: ✭ 67 (+8.06%)
Mutual labels:  mock-data
interface-forge
Graceful mock-data and fixtures generation using TypeScript
Stars: ✭ 58 (-6.45%)
Mutual labels:  mock-data
mock-webpack-plugin
A webpack plugin that starts a json mock server
Stars: ✭ 21 (-66.13%)
Mutual labels:  mock-data
SQLitmus
A simple and practical tool for SQL data generation and performance testing
Stars: ✭ 16 (-74.19%)
Mutual labels:  mock-data
fe-dev-server
FE Dev Server target to help frontend web developers create view template, styles and js easily.
Stars: ✭ 30 (-51.61%)
Mutual labels:  mock-data
Mockoon
Mockoon is the easiest and quickest way to run mock APIs locally. No remote deployment, no account required, open source.
Stars: ✭ 3,448 (+5461.29%)
Mutual labels:  mock-data
Pont
🌉数据服务层解决方案
Stars: ✭ 2,492 (+3919.35%)
Mutual labels:  mock-data
Faker
Go (Golang) Fake Data Generator for Struct
Stars: ✭ 1,698 (+2638.71%)
Mutual labels:  mock-data
MockDataGenerator
Generate mock data for POCO
Stars: ✭ 12 (-80.65%)
Mutual labels:  mock-data
tree-json-generator
Simple JavaScript Tree Generator library
Stars: ✭ 13 (-79.03%)
Mutual labels:  mock-data
ng-apimock
Node plugin that provides the ability to use scenario based api mocking: for local development for protractor testing
Stars: ✭ 102 (+64.52%)
Mutual labels:  mock-data
TermiNetwork
🌏 A zero-dependency networking solution for building modern and secure iOS, watchOS, macOS and tvOS applications.
Stars: ✭ 80 (+29.03%)
Mutual labels:  mock-data
better-mock
Forked from Mockjs, Generate random data & Intercept ajax request. Support miniprogram.
Stars: ✭ 140 (+125.81%)
Mutual labels:  mock-data
fakerfactory
伪造数据的API服务
Stars: ✭ 53 (-14.52%)
Mutual labels:  mock-data
miz
🎯 Generate fake data, Just like a person.
Stars: ✭ 24 (-61.29%)
Mutual labels:  mock-data
sketch-data-faker
A Sketch plugin providing 130+ types of smart placeholder content for your mockups from Faker.js and other sources.
Stars: ✭ 62 (+0%)
Mutual labels:  mock-data
sequelize-slugify
Sequelize Slugify is a plugin for the Sequelize ORM that automatically creates and updates unique, URL safe slugs for your database models.
Stars: ✭ 49 (-20.97%)
Mutual labels:  sequelize-extension
sequelize-paper-trail
Sequelize plugin for tracking revision history of model instances.
Stars: ✭ 90 (+45.16%)
Mutual labels:  sequelize-extension

sequelize-mocking

Build StatusDependency Status devDependency Status

Known Vulnerabilities

NPM NPM

Sequelize extension to deal with data-mocking for testing

  • it was tested with Sequelize 3.19.3 before 1.0.0
  • it was tested with Sequelize 4.3.1 since 1.0.0.
  • it was tested with Sequelize 5.3.0 since 2.0.0

And you have to declare in your package.json the expected sequelize version

It will use the sqlite database for mocked database, will recreate it for database.

Can be integrated with Mocha and Jasmine.

A sample of use:

/**
 * Test around the @{UserService}
 *
 * @module test/user/service
 */

'use strict';

const chai = require('chai');
const sinon = require('sinon');
const path = require('path');
const sequelizeMockingMocha = require('sequelize-mocking').sequelizeMockingMocha;

describe('User - UserService (using sequelizeMockingMocha) - ', function () {
    const Database = require('../../lib/database');
    const UserService = require('../../lib/user/service');
    const UserModel = require('../../lib/user/model');

    // Basic configuration: create a sinon sandbox for testing
    let sandbox = null;

    beforeEach(function () {
        sandbox = sinon.sandbox.create();
    });

    afterEach(function () {
        sandbox && sandbox.restore();
    });

    // Load fake data for the users
    sequelizeMockingMocha(
        Database.getInstance(),
        path.resolve(path.join(__dirname, './fake-users-database.json')),
        /* Or load array of files
        [
            path.resolve(path.join(__dirname, './fake-users-database.json')),
            path.resolve(path.join(__dirname, './fake-candy-database.json')),
        ]
        */
        { 'logging': false }
    );

    it('the service shall exist', function () {
       chai.expect(UserService).to.exist;
    });

    describe('and the method findAll shall ', function () {
        it('exist', function () {
           chai.expect(UserService.findAll).to.exist;
        });

        it('shall returns an array of user', function () {
            return UserService
                .findAll()
                .then(function (users) {
                    chai.expect(users).deep.equals([{
                        'id': 1,
                        'firstName': 'John',
                        'lastName': 'Doe',
                        'age': 25,
                        'description': null
                    }]);
                });
        });
    });

    describe('and the method find shall ', function () {
        it('exist', function () {
            chai.expect(UserService.find).to.exist;
        });

        it('shall return a user if we can', function () {
            let findByIdSpy = sandbox.spy(UserModel, 'findById');

            return UserService
                .find(1)
                .then(function (user) {
                    chai.expect(findByIdSpy.called).to.be.true;
                    chai.expect(findByIdSpy.calledOnce).to.be.true;
                    chai.expect(findByIdSpy.calledWith(1)).to.be.true;

                    chai.expect(user).deep.equals({
                        'id': 1,
                        'firstName': 'John',
                        'lastName': 'Doe',
                        'age': 25,
                        'description': null
                    });
                });
        });

        it('shall return null if not found', function () {
            return UserService
                .find(-1)
                .then(function (user) {
                    chai.expect(user).to.be.null;
                });
        });
    });
});

And the mocked data from the JSON file:

[
  {
    "model": "user",
    "data": {
      "id": 1,
      "firstName": "John",
      "lastName": "Doe",
      "age": 25,
      "description": null
    }
  }
]
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].