first tests created
This commit is contained in:
parent
18918a01d1
commit
d68b2cf3ed
11
package.json
11
package.json
@ -20,7 +20,6 @@
|
||||
},
|
||||
"homepage": "https://github.com/Kononnable/typeorm-model-generator#readme",
|
||||
"dependencies": {
|
||||
"@types/node": "^7.0.10",
|
||||
"mssql": "^3.3.0",
|
||||
"mustache": "^2.3.0",
|
||||
"reflect-metadata": "^0.1.10",
|
||||
@ -28,6 +27,16 @@
|
||||
"yargs": "^7.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/chai": "^3.5.2",
|
||||
"@types/chai-as-promised": "0.0.30",
|
||||
"@types/mocha": "^2.2.41",
|
||||
"@types/node": "^7.0.10",
|
||||
"@types/sinon": "^2.1.3",
|
||||
"chai": "^3.5.0",
|
||||
"chai-as-promised": "^6.0.0",
|
||||
"mocha": "^3.3.0",
|
||||
"sinon": "^2.2.0",
|
||||
"sinon-chai": "^2.10.0",
|
||||
"typings": "^2.1.0"
|
||||
}
|
||||
}
|
||||
|
@ -2,16 +2,16 @@
|
||||
* ColumnInfo
|
||||
*/
|
||||
export class ColumnInfo {
|
||||
name: string;
|
||||
default: string|null;
|
||||
is_nullable: boolean;
|
||||
name: string='';
|
||||
default: string|null=null;
|
||||
is_nullable: boolean=false;
|
||||
ts_type: 'number' | 'string' | 'boolean';
|
||||
sql_type: "string" | "text" | "number" | "integer" | "int" | "smallint" | "bigint" |
|
||||
"float" | "double" | "decimal" | "date" | "time" | "datetime" | "boolean" | "json";
|
||||
char_max_lenght: number|null;
|
||||
isPrimary:boolean;
|
||||
numericPrecision:number|null;
|
||||
numericScale:number|null;
|
||||
char_max_lenght: number|null=null;
|
||||
isPrimary:boolean=false;
|
||||
numericPrecision:number|null=null;
|
||||
numericScale:number|null=null;
|
||||
relations:RelationInfo[];
|
||||
|
||||
constructor() {
|
||||
|
97
test/drivers/MssqlDriver.ts
Normal file
97
test/drivers/MssqlDriver.ts
Normal file
@ -0,0 +1,97 @@
|
||||
import { expect } from "chai";
|
||||
import { MssqlDriver } from './../../src/drivers/MssqlDriver'
|
||||
import * as Sinon from 'sinon'
|
||||
import * as MSSQL from 'mssql'
|
||||
import { EntityInfo } from './../../src/models/EntityInfo'
|
||||
import { ColumnInfo } from './../../src/models/ColumnInfo'
|
||||
|
||||
|
||||
describe('MssqlDriver', function () {
|
||||
let driver: MssqlDriver
|
||||
let sandbox = Sinon.sandbox.create()
|
||||
|
||||
beforeEach(() => {
|
||||
driver = new MssqlDriver();
|
||||
// sandbox.mock()
|
||||
// sandbox.stub( (<any>driver).Connection,)
|
||||
// driver = Sinon.createStubInstance(MssqlDriver);
|
||||
|
||||
// sandbox.stub(MSSQL,'Connection')
|
||||
// .callsFake( (a,b)=>{
|
||||
// console.log(a)
|
||||
// b({message:'a'})
|
||||
// })
|
||||
// sandbox.stub(MSSQL.)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
sandbox.restore()
|
||||
})
|
||||
|
||||
it('should get tables info', async () => {
|
||||
sandbox.stub(MSSQL, 'Request')
|
||||
.returns(
|
||||
{
|
||||
query: (q) => {
|
||||
let response = <{ TABLE_SCHEMA: string, TABLE_NAME: string }[]>[];
|
||||
response.push({ TABLE_SCHEMA: 'schema', TABLE_NAME: 'name' })
|
||||
return response;
|
||||
}
|
||||
}
|
||||
)
|
||||
let result = await driver.GetAllTables()
|
||||
let expectedResult = <EntityInfo[]>[];
|
||||
let y = new EntityInfo();
|
||||
y.EntityName = 'name'
|
||||
y.Columns = <ColumnInfo[]>[];
|
||||
y.Indexes = <IndexInfo[]>[];
|
||||
expectedResult.push(y)
|
||||
expect(result).to.be.deep.equal(expectedResult)
|
||||
})
|
||||
it('should get columns info', async () => {
|
||||
sandbox.stub(MSSQL, 'Request')
|
||||
.returns(
|
||||
{
|
||||
query: (q) => {
|
||||
let response = <{
|
||||
TABLE_NAME: string, COLUMN_NAME: string, COLUMN_DEFAULT: string,
|
||||
IS_NULLABLE: string, DATA_TYPE: string, CHARACTER_MAXIMUM_LENGTH: number,
|
||||
NUMERIC_PRECISION: number, NUMERIC_SCALE: number
|
||||
}[]>[]
|
||||
response.push({
|
||||
TABLE_NAME: 'name', CHARACTER_MAXIMUM_LENGTH: 0,
|
||||
COLUMN_DEFAULT: 'a', COLUMN_NAME: 'name', DATA_TYPE: 'int',
|
||||
IS_NULLABLE: 'YES', NUMERIC_PRECISION: 0, NUMERIC_SCALE: 0
|
||||
})
|
||||
return response;
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
let entities = <EntityInfo[]>[];
|
||||
let y = new EntityInfo();
|
||||
y.EntityName = 'name'
|
||||
y.Columns = <ColumnInfo[]>[];
|
||||
y.Indexes = <IndexInfo[]>[];
|
||||
entities.push(y)
|
||||
var expected: EntityInfo[] = JSON.parse(JSON.stringify(entities));
|
||||
expected[0].Columns.push({
|
||||
char_max_lenght: null,
|
||||
default: 'a',
|
||||
is_nullable: true,
|
||||
isPrimary: false,
|
||||
name: 'name',
|
||||
numericPrecision: null,
|
||||
numericScale: null,
|
||||
sql_type: 'int',
|
||||
ts_type: 'number',
|
||||
relations: <RelationInfo[]>[]
|
||||
})
|
||||
let result = await driver.GetCoulmnsFromEntity(entities);
|
||||
expect(result).to.be.deep.equal(expected)
|
||||
})
|
||||
it('should find primary indexes')
|
||||
it('should get indexes info')
|
||||
it('should get relations info')
|
||||
})
|
@ -13,6 +13,7 @@
|
||||
"strictNullChecks": true,
|
||||
"moduleResolution": "node"
|
||||
}, "include": [
|
||||
"src"
|
||||
"src",
|
||||
"test"
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user