@@ -71,6 +71,15 @@ const HasManyDissociator = require('../src/services/has-many-dissociator');
7171 name : { type : Sequelize . STRING , allowNull : false } ,
7272 } ) ;
7373
74+ models . georegion = sequelize . define ( 'georegion' , {
75+ isocode : {
76+ type : Sequelize . STRING ,
77+ primaryKey : true ,
78+ } ,
79+ nameEnglish : { type : Sequelize . STRING , allowNull : false } ,
80+ nameFrench : { type : Sequelize . STRING , allowNull : false } ,
81+ } ) ;
82+
7483 models . address = sequelize . define ( 'address' , {
7584 line : { type : Sequelize . STRING } ,
7685 zipCode : { type : Sequelize . STRING } ,
@@ -218,6 +227,17 @@ const HasManyDissociator = require('../src/services/has-many-dissociator');
218227 { field : 'updatedAt' , type : 'Date' } ,
219228 ] ,
220229 } ,
230+ georegion : {
231+ name : 'georegion' ,
232+ idField : 'isocode' ,
233+ primaryKeys : [ 'isocode' ] ,
234+ isCompositePrimary : false ,
235+ fields : [
236+ { field : 'isocode' , type : 'String' } ,
237+ { field : 'nameEnglish' , type : 'String' } ,
238+ { field : 'nameFrench' , type : 'String' } ,
239+ ] ,
240+ } ,
221241 address : {
222242 name : 'address' ,
223243 idField : 'id' ,
@@ -1211,6 +1231,84 @@ const HasManyDissociator = require('../src/services/has-many-dissociator');
12111231 } ) ;
12121232 } ) ;
12131233
1234+ describe ( 'request on the resources getter with a search on a string primary key' , ( ) => {
1235+ describe ( 'with a string that does not matches' , ( ) => {
1236+ it ( 'should return 0 records for the specified page' , async ( ) => {
1237+ expect . assertions ( 1 ) ;
1238+ const { models, sequelizeOptions } = initializeSequelize ( ) ;
1239+ const params = {
1240+ fields : {
1241+ country : 'isocode,nameEnglish' ,
1242+ } ,
1243+ page : { number : '1' , size : '30' } ,
1244+ search : 'en' ,
1245+ timezone : 'Europe/Paris' ,
1246+ } ;
1247+ try {
1248+ const result = await new ResourcesGetter ( models . georegion , sequelizeOptions , params )
1249+ . perform ( ) ;
1250+ expect ( result [ 0 ] ) . toHaveLength ( 0 ) ;
1251+ } finally {
1252+ connectionManager . closeConnection ( ) ;
1253+ }
1254+ } ) ;
1255+
1256+ it ( 'should count 0 records' , async ( ) => {
1257+ expect . assertions ( 1 ) ;
1258+ const { models, sequelizeOptions } = initializeSequelize ( ) ;
1259+ const params = {
1260+ search : 'en' ,
1261+ timezone : 'Europe/Paris' ,
1262+ } ;
1263+ try {
1264+ const count = await new ResourcesGetter ( models . georegion , sequelizeOptions , params )
1265+ . count ( ) ;
1266+ expect ( count ) . toStrictEqual ( 0 ) ;
1267+ } finally {
1268+ connectionManager . closeConnection ( ) ;
1269+ }
1270+ } ) ;
1271+ } ) ;
1272+
1273+ describe ( 'with a string that matches' , ( ) => {
1274+ it ( 'should return 1 record for the specified page' , async ( ) => {
1275+ expect . assertions ( 1 ) ;
1276+ const { models, sequelizeOptions } = initializeSequelize ( ) ;
1277+ const params = {
1278+ fields : {
1279+ georegion : 'isocode,nameEnglish' ,
1280+ } ,
1281+ page : { number : '1' , size : '30' } ,
1282+ search : 'es' ,
1283+ timezone : 'Europe/Paris' ,
1284+ } ;
1285+ try {
1286+ const result = await new ResourcesGetter ( models . georegion , sequelizeOptions , params )
1287+ . perform ( ) ;
1288+ expect ( result [ 0 ] ) . toHaveLength ( 1 ) ;
1289+ } finally {
1290+ connectionManager . closeConnection ( ) ;
1291+ }
1292+ } ) ;
1293+
1294+ it ( 'should count 1 record' , async ( ) => {
1295+ expect . assertions ( 1 ) ;
1296+ const { models, sequelizeOptions } = initializeSequelize ( ) ;
1297+ const params = {
1298+ search : 'es' ,
1299+ timezone : 'Europe/Paris' ,
1300+ } ;
1301+ try {
1302+ const count = await new ResourcesGetter ( models . georegion , sequelizeOptions , params )
1303+ . count ( ) ;
1304+ expect ( count ) . toStrictEqual ( 1 ) ;
1305+ } finally {
1306+ connectionManager . closeConnection ( ) ;
1307+ }
1308+ } ) ;
1309+ } ) ;
1310+ } ) ;
1311+
12141312 describe ( 'request on the resources getter with a search on a collection with searchFields' , ( ) => {
12151313 it ( 'should return the records for the specified page' , async ( ) => {
12161314 expect . assertions ( 1 ) ;
0 commit comments