@@ -16,6 +16,7 @@ import {
1616 referenceToGraphQL ,
1717} from '../fieldsConverter' ;
1818import GraphQLMongoID from '../types/mongoid' ;
19+ import GraphQLBSONDecimal from '../types/bsonDecimal' ;
1920
2021describe ( 'fieldConverter' , ( ) => {
2122 const fields : { [ key : string ] : any } = getFieldsFromModel ( UserModel ) ;
@@ -77,23 +78,27 @@ describe('fieldConverter', () => {
7778 expect ( deriveComplexType ( fields . subDoc ) ) . toBe ( ComplexTypes . EMBEDDED ) ;
7879 } ) ;
7980
80- it ( 'schould derive ARRAY' , ( ) => {
81+ it ( 'should derive DECIMAL' , ( ) => {
82+ expect ( deriveComplexType ( fields . salary ) ) . toBe ( ComplexTypes . DECIMAL ) ;
83+ } ) ;
84+
85+ it ( 'should derive ARRAY' , ( ) => {
8186 expect ( deriveComplexType ( fields . users ) ) . toBe ( ComplexTypes . ARRAY ) ;
8287 expect ( deriveComplexType ( fields . skills ) ) . toBe ( ComplexTypes . ARRAY ) ;
8388 expect ( deriveComplexType ( fields . employment ) ) . toBe ( ComplexTypes . ARRAY ) ;
8489 } ) ;
8590
86- it ( 'schould derive ENUM' , ( ) => {
91+ it ( 'should derive ENUM' , ( ) => {
8792 expect ( deriveComplexType ( fields . gender ) ) . toBe ( ComplexTypes . ENUM ) ;
8893 expect ( deriveComplexType ( fields . languages . schema . paths . ln ) ) . toBe ( ComplexTypes . ENUM ) ;
8994 expect ( deriveComplexType ( fields . languages . schema . paths . sk ) ) . toBe ( ComplexTypes . ENUM ) ;
9095 } ) ;
9196
92- it ( 'schould derive REFERENCE' , ( ) => {
97+ it ( 'should derive REFERENCE' , ( ) => {
9398 expect ( deriveComplexType ( fields . user ) ) . toBe ( ComplexTypes . REFERENCE ) ;
9499 } ) ;
95100
96- it ( 'schould derive SCALAR' , ( ) => {
101+ it ( 'should derive SCALAR' , ( ) => {
97102 expect ( deriveComplexType ( fields . name ) ) . toBe ( ComplexTypes . SCALAR ) ;
98103 expect ( deriveComplexType ( fields . relocation ) ) . toBe ( ComplexTypes . SCALAR ) ;
99104 expect ( deriveComplexType ( fields . age ) ) . toBe ( ComplexTypes . SCALAR ) ;
@@ -103,7 +108,7 @@ describe('fieldConverter', () => {
103108 expect ( deriveComplexType ( fields . subDoc ) ) . not . toBe ( ComplexTypes . SCALAR ) ;
104109 } ) ;
105110
106- it ( 'schould derive MIXED mongoose type' , ( ) => {
111+ it ( 'should derive MIXED mongoose type' , ( ) => {
107112 expect ( deriveComplexType ( fields . someDynamic ) ) . toBe ( ComplexTypes . MIXED ) ;
108113 } ) ;
109114 } ) ;
@@ -141,6 +146,18 @@ describe('fieldConverter', () => {
141146 expect ( schemaComposer . get ( 'MongoID' ) ) . toBe ( customType ) ;
142147 schemaComposer . delete ( 'MongoID' ) ;
143148 } ) ;
149+
150+ it ( 'should convert any mongoose field to graphQL type' , ( ) => {
151+ schemaComposer . clear ( ) ;
152+ expect ( schemaComposer . has ( 'BSONDecimal' ) ) . toBeFalsy ( ) ;
153+ const mongooseField = {
154+ path : 'salary' ,
155+ instance : 'Decimal128' ,
156+ } ;
157+ expect ( convertFieldToGraphQL ( mongooseField , '' , schemaComposer ) ) . toBe ( 'BSONDecimal' ) ;
158+ expect ( schemaComposer . has ( 'BSONDecimal' ) ) . toBeTruthy ( ) ;
159+ expect ( schemaComposer . get ( 'BSONDecimal' ) . getType ( ) ) . toBe ( GraphQLBSONDecimal ) ;
160+ } ) ;
144161 } ) ;
145162
146163 describe ( 'scalarToGraphQL()' , ( ) => {
0 commit comments