Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No option to initialize database with indexes #45

Open
krunal704 opened this issue Dec 5, 2020 · 1 comment
Open

No option to initialize database with indexes #45

krunal704 opened this issue Dec 5, 2020 · 1 comment

Comments

@krunal704
Copy link

I want to test API for adding duplicate entries to database, but on backend side it was done using database unique index. which is not applied while test setup.
How do i add indexing while initializing database using mongo-unit?

Unique index is set in mongoose model which initializes when app file loaded

This is my setup code

mongoUnit.start().then(() => {
    console.log("fake mongo is started", mongoUnit.getUrl())
    process.env.MONGO_URL = mongoUnit.getUrl()
    console.log("mongo_UrI", process.env.MONGO_URL)
    run() //this will start mocha tests
})

//Load server express app
before((done) => {
    server = require("../app")
    done()
})

// disconnect database and turn off virtual mongo instance
after(async () => {
    console.log("disconnecting db")
    await mongoose.disconnect()
    console.log('stopping database')
    return await mongoUnit.stop()
})

beforeEach(() => {
       console.log("initializin DB")
       return mongoUnit.initDb(process.env.MONGO_URL, testData)
})

afterEach(() => {
        console.log("removing database")
        return mongoUnit.drop()
})

@krunal704 krunal704 changed the title How to intialize database with indexes? No option to initialize database with indexes? Dec 5, 2020
@krunal704 krunal704 changed the title No option to initialize database with indexes? No option to initialize database with indexes Dec 5, 2020
@stnokott
Copy link

Almost two years later, I'm still interested in this too! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants