enum.test.js
2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
'use strict';
/* jshint -W110 */
var Support = require(__dirname + '/../support')
, DataTypes = require(__dirname + '/../../../lib/data-types')
, expectsql = Support.expectsql
, current = Support.sequelize
, sql = current.dialect.QueryGenerator
, expect = require('chai').expect;
describe(Support.getTestDialectTeaser('SQL'), function() {
describe('enum', function () {
if (Support.getTestDialect() === 'postgres') {
var FooUser = current.define('user', {
mood: DataTypes.ENUM('happy', 'sad')
},{
schema: 'foo'
});
var PublicUser = current.define('user', {
mood: {
type: DataTypes.ENUM('happy', 'sad'),
field: 'theirMood'
}
});
describe('pgEnumName', function() {
it('does not add schema when options: { schema: false }', function() {
expect(sql.pgEnumName(PublicUser.getTableName(), 'mood', { schema: false }))
.to.equal('"enum_users_mood"');
expect(sql.pgEnumName(FooUser.getTableName(), 'theirMood', { schema: false }))
.to.equal('"enum_users_theirMood"');
});
it('properly quotes both the schema and the enum name', function() {
expect(sql.pgEnumName(PublicUser.getTableName(), 'mood', PublicUser.rawAttributes.mood.type))
.to.equal('"public"."enum_users_mood"');
expect(sql.pgEnumName(FooUser.getTableName(), 'theirMood', FooUser.rawAttributes.mood.type))
.to.equal('"foo"."enum_users_theirMood"');
});
});
describe('pgEnum', function () {
it('uses schema #3171', function () {
expectsql(sql.pgEnum(FooUser.getTableName(), 'mood', FooUser.rawAttributes.mood.type), {
postgres: 'CREATE TYPE "foo"."enum_users_mood" AS ENUM(\'happy\', \'sad\');'
});
});
it('does add schema when public', function () {
expectsql(sql.pgEnum(PublicUser.getTableName(), 'theirMood', PublicUser.rawAttributes.mood.type), {
postgres: 'CREATE TYPE "public"."enum_users_theirMood" AS ENUM(\'happy\', \'sad\');'
});
});
});
describe('pgListEnums', function () {
it('works with schema #3563', function () {
expectsql(sql.pgListEnums(FooUser.getTableName(), 'mood'), {
postgres: 'SELECT t.typname enum_name, array_agg(e.enumlabel) enum_value FROM pg_type t JOIN pg_enum e ON t.oid = e.enumtypid JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace WHERE n.nspname = \'foo\' AND t.typname=\'enum_users_mood\' GROUP BY 1'
});
});
it('uses the default schema if no options given', function () {
expectsql(sql.pgListEnums(), {
postgres: 'SELECT t.typname enum_name, array_agg(e.enumlabel) enum_value FROM pg_type t JOIN pg_enum e ON t.oid = e.enumtypid JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace WHERE n.nspname = \'public\' GROUP BY 1'
});
});
});
}
});
});