-
-
Notifications
You must be signed in to change notification settings - Fork 527
Expand file tree
/
Copy pathdb-drop.test.js
More file actions
103 lines (98 loc) · 2.87 KB
/
db-drop.test.js
File metadata and controls
103 lines (98 loc) · 2.87 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
const expect = require('expect.js');
const Support = require(__dirname + '/../support');
const helpers = require(__dirname + '/../support/helpers');
const gulp = require('gulp');
const _ = require('lodash');
const prepare = function (flag, callback, options) {
options = _.assign({ config: {} }, options || {});
const configPath = 'config/config.json';
const config = _.assign({}, helpers.getTestConfig(), options.config);
const configContent = JSON.stringify(config);
gulp
.src(Support.resolveSupportPath('tmp'))
.pipe(helpers.clearDirectory())
.pipe(helpers.runCli('init'))
.pipe(helpers.removeFile(configPath))
.pipe(helpers.overwriteFile(configContent, configPath))
.pipe(helpers.runCli('db:create'))
.pipe(helpers.runCli(flag, { pipeStdout: true }))
.pipe(helpers.teardown(callback));
};
describe(Support.getTestDialectTeaser('db:drop'), () => {
if (Support.dialectIsPostgres()) {
it('correctly drops database', function (done) {
const databaseName = `my_test_db_${_.random(10000, 99999)}`;
prepare(
'db:drop',
() => {
this.sequelize
.query(
`SELECT 1 as exists FROM pg_database WHERE datname = '${databaseName}';`,
{
type: this.sequelize.QueryTypes.SELECT,
}
)
.then((result) => {
expect(result).to.be.empty;
done();
});
},
{
config: {
database: databaseName,
},
}
);
});
it('correctly drops database with force', function (done) {
const databaseName = `my_test_db_${_.random(10000, 99999)}`;
prepare(
'db:drop --force',
() => {
this.sequelize
.query(
`SELECT 1 as exists FROM pg_database WHERE datname = '${databaseName}';`,
{
type: this.sequelize.QueryTypes.SELECT,
}
)
.then((result) => {
expect(result).to.be.empty;
done();
});
},
{
config: {
database: databaseName,
},
}
);
});
}
if (Support.dialectIsMySQL()) {
it('correctly drops database', function (done) {
const databaseName = `my_test_db_${_.random(10000, 99999)}`;
prepare(
'db:drop',
() => {
this.sequelize
.query(
`SELECT IF('${databaseName}' IN(SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA), 1, 0) AS found;`,
{
type: this.sequelize.QueryTypes.SELECT,
}
)
.then((result) => {
expect(result[0].found).to.eql(0);
done();
});
},
{
config: {
database: databaseName,
},
}
);
});
}
});