Skip to content

Commit cdd95b7

Browse files
author
kukoo
committed
improve sequelize instantiation test
1 parent 6847fbd commit cdd95b7

File tree

2 files changed

+59
-20
lines changed

2 files changed

+59
-20
lines changed

test/specs/models/sequelize.spec.ts

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* tslint:disable:max-classes-per-file */
22

33
import {expect} from 'chai';
4-
import {createSequelize, createSequelizeUriObject, createSequelizeUriString} from "../../utils/sequelize";
4+
import {createSequelize} from "../../utils/sequelize";
55
import {Game} from "../../models/exports/Game";
66
import Gamer from "../../models/exports/gamer.model";
77
import {Sequelize} from "../../../lib/models/Sequelize";
@@ -11,6 +11,14 @@ import {Table} from '../../../lib/annotations/Table';
1111
describe('sequelize', () => {
1212

1313
const sequelize = createSequelize(false);
14+
const connectionUri = "sqlite://root@localhost/__";
15+
16+
function testOptionsProp(instance: Sequelize): void {
17+
expect(instance).to.have.property('options').that.have.property('dialect').that.eqls('sqlite');
18+
expect(instance).to.have.property('config').that.have.property('host').that.eqls('localhost');
19+
expect(instance).to.have.property('config').that.have.property('database').that.eqls('__');
20+
expect(instance).to.have.property('config').that.have.property('username').that.eqls('root');
21+
}
1422

1523
describe('constructor', () => {
1624

@@ -20,22 +28,70 @@ describe('sequelize', () => {
2028

2129
});
2230

31+
describe('constructor: using "name" property as a db name', () => {
32+
33+
const db = '__';
34+
const sequelizeDbName = new Sequelize({
35+
name: db,
36+
dialect: 'sqlite',
37+
username: 'root',
38+
password: '',
39+
storage: ':memory:',
40+
logging: !('SEQ_SILENT' in process.env)
41+
});
42+
43+
it('should equal Sequelize class', () => {
44+
expect(sequelizeDbName.constructor).to.equal(Sequelize);
45+
});
46+
47+
it('should contain database property, which equal to db.', () => {
48+
expect(sequelizeDbName)
49+
.to.have.property('config')
50+
.that.have.property('database')
51+
.that.eqls(db);
52+
});
53+
54+
});
55+
2356
describe('constructor using uri in options object', () => {
2457

25-
const sequelizeUri = createSequelizeUriString(false);
58+
const sequelizeUri = new Sequelize({
59+
uri: connectionUri,
60+
storage: ':memory:',
61+
logging: !('SEQ_SILENT' in process.env),
62+
pool: {max: 8, min: 0}
63+
});
64+
2665
it('should equal Sequelize class', () => {
2766
expect(sequelizeUri.constructor).to.equal(Sequelize);
2867
});
2968

69+
it('should contain valid options extracted from connection string', () => {
70+
testOptionsProp(sequelizeUri);
71+
});
72+
73+
it('should contain additional Sequelize options', () => {
74+
expect(sequelizeUri)
75+
.to.have.property('options')
76+
.to.have.property('pool')
77+
.that.have.property('max')
78+
.that.eqls(8);
79+
});
80+
3081
});
3182

3283
describe('constructor using uri string', () => {
3384

34-
const sequelizeUri = createSequelizeUriObject(false);
85+
const sequelizeUri = new Sequelize(connectionUri);
86+
3587
it('should equal Sequelize class', () => {
3688
expect(sequelizeUri.constructor).to.equal(Sequelize);
3789
});
3890

91+
it('should contain valid options extracted from connection string', () => {
92+
testOptionsProp(sequelizeUri);
93+
});
94+
3995
});
4096

4197
describe('global define options', () => {

test/utils/sequelize.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,6 @@ export function createSequelize(useModelsInPath: boolean = true, define: DefineO
1616
});
1717
}
1818

19-
export function createSequelizeUriObject(useModelsInPath: boolean = true, define: DefineOptions<any> = {}): Sequelize {
20-
21-
return new Sequelize({
22-
uri: 'sqlite://root@localhost/__',
23-
dialect: 'sqlite',
24-
define,
25-
storage: ':memory:',
26-
logging: !('SEQ_SILENT' in process.env),
27-
modelPaths: useModelsInPath ? [__dirname + '/../models'] : []
28-
});
29-
}
30-
31-
export function createSequelizeUriString(useModelsInPath: boolean = true, define: DefineOptions<any> = {}): Sequelize {
32-
33-
return new Sequelize("sqlite://root@localhost/__");
34-
}
35-
3619
export function createSequelizeValidationOnly(useModelsInPath: boolean = true): Sequelize {
3720

3821
return new Sequelize({

0 commit comments

Comments
 (0)