Skip to content
This repository has been archived by the owner on Dec 23, 2021. It is now read-only.

Commit

Permalink
fix: char type for test
Browse files Browse the repository at this point in the history
  • Loading branch information
Soontao committed Sep 23, 2020
1 parent ad6582b commit 2835dd3
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
16 changes: 9 additions & 7 deletions src/type/decorators/odata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,6 @@ export function ODataColumn(options: ColumnOptions = {}) {
break;
default:
Edm.String(object, propertyName);
if (options.type === undefined) {
options.type = 'text';
}
break;
}
break;
Expand All @@ -226,9 +223,6 @@ export function ODataColumn(options: ColumnOptions = {}) {
default:
// unknown or not have type
Edm.Int32(object, propertyName);
if (options.type === undefined) {
options.type = 'int';
}
break;
}
break;
Expand Down Expand Up @@ -273,6 +267,7 @@ export function ODataColumn(options: ColumnOptions = {}) {
case 'varchar2':
case 'char':
case 'text':
case String:
Assert.IsString({ groups: ODataMethods })(object, propertyName);
break;
case 'uuid':
Expand All @@ -281,7 +276,14 @@ export function ODataColumn(options: ColumnOptions = {}) {
case 'datetime': case 'datetime2': case 'datetimeoffset':
Assert.IsDateString({ groups: ODataMethods })(object, propertyName);
break;
case 'int': case 'int2': case 'int4': case 'int8': case 'int64': case 'bigint':
case 'int':
case 'integer':
case 'int2':
case 'int4':
case 'int8':
case 'int64':
case 'bigint':
case Number:
if (reflectType == Date) {
Assert.IsDateOrDateString({ groups: ODataMethods })(object, propertyName);
} else {
Expand Down
4 changes: 2 additions & 2 deletions test/type/decorator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ describe('Decorator Test Suite', () => {
const entityProps = getODataColumns(A);

expect(entityProps).toHaveLength(2);
expect(entityProps[0].type).toBe('int');
expect(entityProps[1].type).toBe('text');
expect(entityProps[0].type).toBe(Number);
expect(entityProps[1].type).toBe(String);

expect(getODataColumns(new A)).toHaveLength(2);

Expand Down
21 changes: 19 additions & 2 deletions test/type/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,29 @@ import '@odata/client/lib/polyfill';
import { Server } from 'http';
import * as os from 'os';
import * as path from 'path';
import { Connection, ConnectionOptions, createConnection } from 'typeorm';
import { ColumnType, Connection, ConnectionOptions, createConnection } from 'typeorm';
import { v4 } from 'uuid';
import { createTypedODataServer, TypedODataServer } from '../../src';
import { randomPort } from '../utils/randomPort';
import { ready, shutdown } from '../utils/server';

/**
* get char data type from env
*
* TEST only
*/
export function getTestCharDataType(): ColumnType {
const options = createTmpConnOpt();
switch (options?.type) {
case 'sap': case 'mysql': case 'sqlite': case 'sqljs':
return 'nvarchar';
case 'postgres':
return 'varchar';
default:
return 'text';
}
}

const createTmpDefaultOption = () => {
let defaultOpt: ConnectionOptions = undefined;

Expand Down Expand Up @@ -86,7 +103,7 @@ export const createTmpMigrateConnOpt = (opt?: Partial<ConnectionOptions>) => {
};


export const createTmpConnOpt = (opt?: Partial<ConnectionOptions>) => {
export const createTmpConnOpt = (opt?: Partial<ConnectionOptions> = {}) => {

let defaultOpt: ConnectionOptions = createTmpDefaultOption();

Expand Down
4 changes: 2 additions & 2 deletions test/type/validation.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BaseODataModel, KeyProperty, ODataEntityType, ODataModel, ODataNavigation, OptionalProperty, Property, UUIDKeyProperty } from '../../src';
import { createServerAndClient, createTmpConnection } from './utils';
import { createServerAndClient, createTmpConnection, getTestCharDataType } from './utils';


describe('Validate Test Suite', () => {
Expand Down Expand Up @@ -213,7 +213,7 @@ describe('Validate Test Suite', () => {
@ODataModel()
class ValidationString {
@UUIDKeyProperty() id: string;
@Property({ length: 10 }) value: string;
@Property({ type: getTestCharDataType(), length: 10 }) value: string;
}

@ODataModel()
Expand Down

0 comments on commit 2835dd3

Please sign in to comment.