{"id":15062098,"url":"https://github.com/rochejul/sequelize-mocking","last_synced_at":"2025-09-09T21:49:29.999Z","repository":{"id":4172913,"uuid":"52217026","full_name":"rochejul/sequelize-mocking","owner":"rochejul","description":"Sequelize extension to deal with data-mocking for testing","archived":false,"fork":false,"pushed_at":"2024-03-12T10:02:04.000Z","size":398,"stargazers_count":63,"open_issues_count":10,"forks_count":26,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-09T00:07:52.554Z","etag":null,"topics":["database","mock-data","nodejs","sequelize-extension","sequelize-mocking"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rochejul.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-02-21T16:57:18.000Z","updated_at":"2023-12-12T07:53:11.000Z","dependencies_parsed_at":"2024-09-24T23:30:25.114Z","dependency_job_id":"1aff9e79-2400-45a6-ad28-8298225d07dc","html_url":"https://github.com/rochejul/sequelize-mocking","commit_stats":{"total_commits":105,"total_committers":9,"mean_commits":"11.666666666666666","dds":"0.47619047619047616","last_synced_commit":"bf19fa6a5c8f20ed013d1df29f91498ca970a31a"},"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rochejul%2Fsequelize-mocking","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rochejul%2Fsequelize-mocking/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rochejul%2Fsequelize-mocking/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rochejul%2Fsequelize-mocking/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rochejul","download_url":"https://codeload.github.com/rochejul/sequelize-mocking/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253166520,"owners_count":21864482,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","mock-data","nodejs","sequelize-extension","sequelize-mocking"],"created_at":"2024-09-24T23:30:19.521Z","updated_at":"2025-05-09T00:07:58.367Z","avatar_url":"https://github.com/rochejul.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sequelize-mocking\n\n[![Build Status](https://travis-ci.org/rochejul/sequelize-mocking.svg?branch=master)](https://travis-ci.org/rochejul/sequelize-mocking)[![Dependency Status](https://david-dm.org/rochejul/sequelize-mocking.svg)](https://david-dm.org/rochejul/sequelize-mocking)\n[![devDependency Status](https://david-dm.org/rochejul/sequelize-mocking/dev-status.svg)](https://david-dm.org/rochejul/sequelize-mocking#info=devDependencies)\n\n[![Known Vulnerabilities](https://snyk.io/test/github/rochejul/sequelize-mocking/badge.svg)](https://snyk.io/test/github/rochejul/sequelize-mocking)\n\n[![NPM](https://nodei.co/npm/sequelize-mocking.png?downloads=true\u0026downloadRank=true)](https://nodei.co/npm/sequelize-mocking/)\n[![NPM](https://nodei.co/npm-dl/sequelize-mocking.png?\u0026months=6\u0026height=3)](https://nodei.co/npm/sequelize-mocking/)\n\n\nSequelize extension to deal with data-mocking for testing\n\n - it was tested with Sequelize 3.19.3 before 1.0.0\n - it was tested with Sequelize 4.3.1 since 1.0.0.\n - it was tested with Sequelize 5.3.0 since 2.0.0\n \n **And you have to declare in your package.json the expected sequelize version**\n\nIt will use the sqlite database for mocked database, will recreate it for database.\n\nCan be integrated with Mocha and Jasmine.\n\nA sample of use:\n\n````js\n/**\n * Test around the @{UserService}\n *\n * @module test/user/service\n */\n\n'use strict';\n\nconst chai = require('chai');\nconst sinon = require('sinon');\nconst path = require('path');\nconst sequelizeMockingMocha = require('sequelize-mocking').sequelizeMockingMocha;\n\ndescribe('User - UserService (using sequelizeMockingMocha) - ', function () {\n    const Database = require('../../lib/database');\n    const UserService = require('../../lib/user/service');\n    const UserModel = require('../../lib/user/model');\n\n    // Basic configuration: create a sinon sandbox for testing\n    let sandbox = null;\n\n    beforeEach(function () {\n        sandbox = sinon.sandbox.create();\n    });\n\n    afterEach(function () {\n        sandbox \u0026\u0026 sandbox.restore();\n    });\n\n    // Load fake data for the users\n    sequelizeMockingMocha(\n        Database.getInstance(),\n        path.resolve(path.join(__dirname, './fake-users-database.json')),\n        /* Or load array of files\n        [\n            path.resolve(path.join(__dirname, './fake-users-database.json')),\n            path.resolve(path.join(__dirname, './fake-candy-database.json')),\n        ]\n        */\n        { 'logging': false }\n    );\n\n    it('the service shall exist', function () {\n       chai.expect(UserService).to.exist;\n    });\n\n    describe('and the method findAll shall ', function () {\n        it('exist', function () {\n           chai.expect(UserService.findAll).to.exist;\n        });\n\n        it('shall returns an array of user', function () {\n            return UserService\n                .findAll()\n                .then(function (users) {\n                    chai.expect(users).deep.equals([{\n                        'id': 1,\n                        'firstName': 'John',\n                        'lastName': 'Doe',\n                        'age': 25,\n                        'description': null\n                    }]);\n                });\n        });\n    });\n\n    describe('and the method find shall ', function () {\n        it('exist', function () {\n            chai.expect(UserService.find).to.exist;\n        });\n\n        it('shall return a user if we can', function () {\n            let findByIdSpy = sandbox.spy(UserModel, 'findById');\n\n            return UserService\n                .find(1)\n                .then(function (user) {\n                    chai.expect(findByIdSpy.called).to.be.true;\n                    chai.expect(findByIdSpy.calledOnce).to.be.true;\n                    chai.expect(findByIdSpy.calledWith(1)).to.be.true;\n\n                    chai.expect(user).deep.equals({\n                        'id': 1,\n                        'firstName': 'John',\n                        'lastName': 'Doe',\n                        'age': 25,\n                        'description': null\n                    });\n                });\n        });\n\n        it('shall return null if not found', function () {\n            return UserService\n                .find(-1)\n                .then(function (user) {\n                    chai.expect(user).to.be.null;\n                });\n        });\n    });\n});\n````\n\nAnd the mocked data from the JSON file:\n\n````JSON\n[\n  {\n    \"model\": \"user\",\n    \"data\": {\n      \"id\": 1,\n      \"firstName\": \"John\",\n      \"lastName\": \"Doe\",\n      \"age\": 25,\n      \"description\": null\n    }\n  }\n]\n````\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frochejul%2Fsequelize-mocking","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frochejul%2Fsequelize-mocking","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frochejul%2Fsequelize-mocking/lists"}