1
1
/* tslint:disable:max-classes-per-file */
2
2
3
3
import { expect } from 'chai' ;
4
- import { createSequelize , createSequelizeUriObject , createSequelizeUriString } from "../../utils/sequelize" ;
4
+ import { createSequelize } from "../../utils/sequelize" ;
5
5
import { Game } from "../../models/exports/Game" ;
6
6
import Gamer from "../../models/exports/gamer.model" ;
7
7
import { Sequelize } from "../../../lib/models/Sequelize" ;
@@ -11,6 +11,14 @@ import {Table} from '../../../lib/annotations/Table';
11
11
describe ( 'sequelize' , ( ) => {
12
12
13
13
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
+ }
14
22
15
23
describe ( 'constructor' , ( ) => {
16
24
@@ -20,22 +28,70 @@ describe('sequelize', () => {
20
28
21
29
} ) ;
22
30
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
+
23
56
describe ( 'constructor using uri in options object' , ( ) => {
24
57
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
+
26
65
it ( 'should equal Sequelize class' , ( ) => {
27
66
expect ( sequelizeUri . constructor ) . to . equal ( Sequelize ) ;
28
67
} ) ;
29
68
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
+
30
81
} ) ;
31
82
32
83
describe ( 'constructor using uri string' , ( ) => {
33
84
34
- const sequelizeUri = createSequelizeUriObject ( false ) ;
85
+ const sequelizeUri = new Sequelize ( connectionUri ) ;
86
+
35
87
it ( 'should equal Sequelize class' , ( ) => {
36
88
expect ( sequelizeUri . constructor ) . to . equal ( Sequelize ) ;
37
89
} ) ;
38
90
91
+ it ( 'should contain valid options extracted from connection string' , ( ) => {
92
+ testOptionsProp ( sequelizeUri ) ;
93
+ } ) ;
94
+
39
95
} ) ;
40
96
41
97
describe ( 'global define options' , ( ) => {
0 commit comments