Skip to content

Commit

Permalink
tests: fn.uuid oracle and redshift coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
arbezerra authored and OlivierCavadenti committed Jul 7, 2023
1 parent 2e463dc commit 2134d2d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 10 deletions.
32 changes: 22 additions & 10 deletions test/integration2/query/misc/additional.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,19 +394,31 @@ describe('Additional', function () {

it('should allow using .fn.uuid to create raw statements', function () {
const expectedStatement = {
[drivers.MsSQL]: "(NEWID())",
[drivers.MySQL]: "(UUID())",
[drivers.MySQL2]: "(UUID())",
[drivers.Oracle]: "(random_uuid())",
[drivers.PostgreSQL]: "(gen_random_uuid())",
[drivers.PgNative]: "(gen_random_uuid())",
[drivers.SQLite]: "(lower(hex(randomblob(4))) || '-' || lower(hex(randomblob(2))) || '-4' || substr(lower(hex(randomblob(2))),2) || '-' || substr('89ab',abs(random()) % 4 + 1, 1) || substr(lower(hex(randomblob(2))),2) || '-' || lower(hex(randomblob(6))))",
[drivers.CockroachDB]: "(gen_random_uuid())",
[drivers.BetterSQLite3]: "(lower(hex(randomblob(4))) || '-' || lower(hex(randomblob(2))) || '-4' || substr(lower(hex(randomblob(2))),2) || '-' || substr('89ab',abs(random()) % 4 + 1, 1) || substr(lower(hex(randomblob(2))),2) || '-' || lower(hex(randomblob(6))))",
[drivers.MsSQL]: '(NEWID())',
[drivers.MySQL]: '(UUID())',
[drivers.MySQL2]: '(UUID())',
[drivers.Oracle]: '(random_uuid())',
oracle: '(random_uuid())',
[drivers.PostgreSQL]: '(gen_random_uuid())',
[drivers.PgNative]: '(gen_random_uuid())',
[drivers.SQLite]:
"(lower(hex(randomblob(4))) || '-' || lower(hex(randomblob(2))) || '-4' || substr(lower(hex(randomblob(2))),2) || '-' || substr('89ab',abs(random()) % 4 + 1, 1) || substr(lower(hex(randomblob(2))),2) || '-' || lower(hex(randomblob(6))))",
[drivers.CockroachDB]: '(gen_random_uuid())',
[drivers.BetterSQLite3]:
"(lower(hex(randomblob(4))) || '-' || lower(hex(randomblob(2))) || '-4' || substr(lower(hex(randomblob(2))),2) || '-' || substr('89ab',abs(random()) % 4 + 1, 1) || substr(lower(hex(randomblob(2))),2) || '-' || lower(hex(randomblob(6))))",
};

expect(knex.fn.uuid().prototype === knex.raw().prototype);
expect(knex.fn.uuid().toQuery()).to.equal(expectedStatement[knex.client.driverName]);

if (isRedshift()) {
expect(() => knex.fn.uuid().toQuery()).to.throw(
`${knex.client.driverName} does not have a uuid function`
);
} else {
expect(knex.fn.uuid().toQuery()).to.equal(
expectedStatement[knex.client.driverName]
);
}
});

it('should allow using .fn-methods to generate a uuid with select', async function () {
Expand Down
8 changes: 8 additions & 0 deletions test/unit/schema-builder/oracledb.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const { expect } = require('chai');
const sinon = require('sinon');
const Oracle_Client = require('../../../lib/dialects/oracledb');
const knex = require('../../../knex');
const FunctionHelper = require('../../../lib/knex-builder/FunctionHelper');
const client = new Oracle_Client({ client: 'oracledb' });

describe('OracleDb SchemaBuilder', function () {
Expand Down Expand Up @@ -1048,6 +1049,13 @@ describe('OracleDb SchemaBuilder', function () {
expect(tableSql[0].sql).to.equal('alter table "users" add "foo" raw(16)');
});

it('should allow using .fn.uuid to create raw statements', function () {
// Integration tests doesnt cover for oracle
const helperFunctions = new FunctionHelper(client);

expect(helperFunctions.uuid().toQuery()).to.equal('(random_uuid())');
});

it('test set comment', function () {
tableSql = client
.schemaBuilder()
Expand Down
9 changes: 9 additions & 0 deletions test/unit/schema-builder/redshift.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ let tableSql;

const Redshift_Client = require('../../../lib/dialects/redshift');
const knex = require('../../../knex');
const FunctionHelper = require('../../../lib/knex-builder/FunctionHelper');
const client = new Redshift_Client({ client: 'redshift' });

const equal = require('assert').equal;
Expand Down Expand Up @@ -891,6 +892,14 @@ describe('Redshift SchemaBuilder', function () {
);
});

it('redshift doesnt have a uuid function', function () {
const helperFunctions = new FunctionHelper(client);

expect(() => helperFunctions.uuid()).to.throw(
`${client.driverName} does not have a uuid function`
);
});

it('allows adding default json objects when the column is json', function () {
tableSql = client
.schemaBuilder()
Expand Down

0 comments on commit 2134d2d

Please sign in to comment.