11/* tslint:disable:max-classes-per-file */
22
33import { expect } from 'chai' ;
4- import { createSequelize , createSequelizeUriObject , createSequelizeUriString } from "../../utils/sequelize" ;
4+ import { createSequelize } from "../../utils/sequelize" ;
55import { Game } from "../../models/exports/Game" ;
66import Gamer from "../../models/exports/gamer.model" ;
77import { Sequelize } from "../../../lib/models/Sequelize" ;
@@ -11,6 +11,14 @@ import {Table} from '../../../lib/annotations/Table';
1111describe ( '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' , ( ) => {
0 commit comments