Skip to content

Commit

Permalink
test(oracledb): change .truncate() to drop and create tables for re…
Browse files Browse the repository at this point in the history
…set auto sequences

`.truncate()` in oracle clear data rows but not clear sequences that's why this tests dosen't work with oracle. let's drop table and recreate for restart sequences
  • Loading branch information
gabolera committed May 11, 2024
1 parent 18e2f05 commit d985501
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 21 deletions.
14 changes: 6 additions & 8 deletions test/integration2/query/insert/inserts.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ describe('Inserts', function () {
describe(db, () => {
let knex;

const createTables = async (knex) => {
const dropAndRecreateTables = async (knex) => {
await dropTables(knex);
await createUsers(knex);
await createAccounts(knex, true);
await createTestTableTwo(knex);
await createDataType(knex);
}
};

before(async () => {
knex = logger(getKnexForDb(db));
await createTables(knex)
await dropAndRecreateTables(knex);
});

after(async () => {
Expand All @@ -60,10 +60,8 @@ describe('Inserts', function () {
});

beforeEach(async () => {
// .truncate() on oracle clear data rows but not sequences that's why
// this tests dosen't work with oracle. let's drop table and recreate
if(isOracle(knex)){
await createTables(knex)
if (isOracle(knex)) {
await dropAndRecreateTables(knex);
}
await knex('accounts').truncate();
await knex('test_table_two').truncate();
Expand Down Expand Up @@ -897,7 +895,7 @@ describe('Inserts', function () {
});

it('#5738 should handle insert with comments', async function () {
if(isOracle(knex)){
if (isOracle(knex)) {
return this.skip('analyze this function to oracledb');
}
await knex('test_default_table')
Expand Down
13 changes: 9 additions & 4 deletions test/integration2/query/select/joins.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,23 @@ describe('Joins', function () {
describe(db, () => {
let knex;

before(async () => {
knex = logger(getKnexForDb(db));
const dropAndRecreateTables = async (knex) => {
await dropTables(knex);
await createAccounts(knex);
await createTestTableTwo(knex);

await insertTestTableTwoData(knex);
};

before(async () => {
knex = logger(getKnexForDb(db));
await dropAndRecreateTables(knex);
});

beforeEach(async () => {
if (isOracle(knex)) {
await dropAndRecreateTables(knex);
}
await knex('accounts').truncate();

await insertAccounts(knex);
});

Expand Down
12 changes: 9 additions & 3 deletions test/integration2/query/select/selects.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,25 @@ describe('Selects', function () {
describe(db, () => {
let knex;

before(async () => {
knex = logger(getKnexForDb(db));

const dropAndRecreateTables = async (knex) => {
await dropTables(knex);
await createUsers(knex);
await createAccounts(knex);
await createCompositeKeyTable(knex);
await createTestTableTwo(knex);
await createDefaultTable(knex);
await createDefaultTable(knex, true);
};

before(async () => {
knex = logger(getKnexForDb(db));
await dropAndRecreateTables(knex);
});

beforeEach(async () => {
if (isOracle(knex)) {
await dropAndRecreateTables(knex);
}
await knex('accounts').truncate();
await insertAccounts(knex);
});
Expand Down
35 changes: 32 additions & 3 deletions test/integration2/query/select/where.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,25 @@ describe('Where', function () {
describe(db, () => {
let knex;

before(async () => {
knex = logger(getKnexForDb(db));

const dropAndRecreateTables = async (knex) => {
await dropTables(knex);
await createUsers(knex);
await createAccounts(knex);
await createCompositeKeyTable(knex);
await createTestTableTwo(knex);
await createDefaultTable(knex);
await createDefaultTable(knex, true);
};

before(async () => {
knex = logger(getKnexForDb(db));
await dropAndRecreateTables(knex);
});

beforeEach(async () => {
if (isOracle(knex)) {
await dropAndRecreateTables(knex);
}
await knex('accounts').truncate();
await insertAccounts(knex);
});
Expand Down Expand Up @@ -434,6 +440,29 @@ describe('Where', function () {

it('handles multi-column "where in" cases with where', async function () {
if (!isSQLite(knex) && !isMssql(knex)) {
// Reinsert with oracle because dorp tables in beforeEach
if (isOracle(knex)) {
await knex('composite_key_test').insert([
{
column_a: 1,
column_b: 1,
details: 'One, One, One',
status: 1,
},
{
column_a: 1,
column_b: 2,
details: 'One, Two, Zero',
status: 0,
},
{
column_a: 2,
column_b: 2,
details: 'Two, Two, Zero',
status: 0,
},
]);
}
await knex('composite_key_test')
.where('status', 1)
.whereIn(
Expand Down
13 changes: 10 additions & 3 deletions test/integration2/query/update/updates.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const { expect } = require('chai');

const { TEST_TIMESTAMP } = require('../../../util/constants');
const { isPostgreSQL } = require('../../../util/db-helpers');
const { isPostgreSQL, isOracle } = require('../../../util/db-helpers');
const {
getAllDbs,
getKnexForDb,
Expand All @@ -22,10 +22,14 @@ describe('Updates', function () {
let knex;
let accountId1;

const dropAndRecreateTables = async (knex) => {
await dropTables(knex);
await createAccounts(knex);
};

before(async () => {
knex = logger(getKnexForDb(db));
await dropTables(knex);
await createAccounts(knex);
await dropAndRecreateTables(knex);
});

after(async () => {
Expand All @@ -34,6 +38,9 @@ describe('Updates', function () {
});

beforeEach(async () => {
if (isOracle(knex)) {
await dropAndRecreateTables(knex);
}
await knex('accounts').truncate();
await insertAccounts(knex);
const accounts = await knex('accounts').select().where({
Expand Down

0 comments on commit d985501

Please sign in to comment.