jbrumwell / mock-knex

A mock knex adapter for simulating a database during testing
MIT License
239 stars 71 forks source link

TypeError: conn.rollbackAsync is not a function with oracledb #121

Open aggaton opened 3 years ago

aggaton commented 3 years ago

Hi, I am having this issue when attempting to mock a transaction with multiple inserts. I have tried doing what is suggested here https://github.com/jbrumwell/mock-knex/issues/95 however it does not seem to help, I still get the same error.

this is what I am trying to mock

import * as knex from 'knex';

export const pool: any = knex({
    acquireConnectionTimeout: 60000,
    client: 'oracledb',
    connection: {
        connectString: 'zoo',
        password: 'foo',
        user: 'bar',
    },
    debug: true,
    pool: {
        acquireTimeoutMillis: 60000, 10),
        idleTimeoutMillis: 60000,
        max: 10,
        min: 10,
    },
});

    await pool.transaction((trx: any) => {
        return Promise.all([
            row = this.insertOne(trx, id, data),
           this.insertTwo(trx, id, data),
           userData.flag ? this.insertThree(trx, id, data) : {},
           this.insertFour(trx, id, data),
           moreToDo(data),
        ]);
    })
    .catch((err: any) => {
        logger.error(err);
    });

each insert looks something like this:

    return pool('FOOBAR')
            .transacting(trx)
            .withSchema('FOO')
            .insert([
                {
                    FOO: 'BAR',
                    ID: id,
                    CREATE_DT: pool.raw('sysdate'),
                    LAST_MOD_DT: pool.raw('sysdate'),
                },
            ]);
}

this is my mock:

mockKnex.mock(pool);
const tracker = mockKnex.getTracker();
tracker.install();
    tracker.on('query', (query, step) => {
        [
            function firstQuery() {
                    {
                        ID: 1234,
                    },
                ]);
            },
            function secondQuery() {
                query.response([
                    {
                        ID: 1234,
                    },
                ]);
            },
            function thirdQuery() {
                query.response([]);
            },
            function fourthQuery() {
                query.response([]);
            },
            function fifthQuery() {
                query.response([]);
            },
        ][step - 1]();
    });
    const results = await sut.inserts(subject);
    expect(results).toEqual(foo);

This is the error:

TypeError: conn.rollbackAsync is not a function
    at Oracle_Transaction.commit (/home/foo/node_modules/knex/lib/dialects/oracledb/transaction.js:14:18)
    at Function.transactor.commit (/home/foo/node_modules/knex/lib/transaction.js:277:40)
    at /home/foo/node_modules/knex/lib/transaction.js:191:35

Im using knex 0.21.12 mock-knex 0.4.9

jbrumwell commented 3 years ago

@aggaton this may be an issue with the implementation on our side for Oracle. We currently only have tests for msyql and postgres. I'll look into adding tests for the other engines but I don't have a timeline for you at the moment.