@@ -20,10 +20,15 @@ import {
2020import { sendRequestToSaasPart } from '../../utils/send-request-to-saas-part.util.js' ;
2121import { TestUtils } from '../../utils/test.utils.js' ;
2222import { Cacher } from '../../../src/helpers/cache/cacher.js' ;
23+ import { Constants } from '../../../src/helpers/constants/constants.js' ;
24+ import { getTestData } from '../../utils/get-test-data.js' ;
25+ import { createTestTable } from '../../utils/create-test-table.js' ;
26+ import { MockFactory } from '../../mock.factory.js' ;
2327
2428let app : INestApplication ;
2529let currentTest : string ;
2630let testUtils : TestUtils ;
31+ const mockFactory = new MockFactory ( ) ;
2732
2833test . before ( async ( ) => {
2934 const moduleFixture = await Test . createTestingModule ( {
@@ -469,3 +474,112 @@ test.skip(`${currentTest} should login user successfully with company id from cu
469474 }
470475 t . pass ( ) ;
471476} ) ;
477+
478+ currentTest = 'POST /user/demo/register' ;
479+ test . serial ( `${ currentTest } should register demo user` , async ( t ) => {
480+ const result = await fetch ( 'http://rocketadmin-private-microservice:3001/saas/user/demo/register' , {
481+ method : 'POST' ,
482+ headers : {
483+ 'Content-Type' : 'application/json' ,
484+ Accept : 'application/json' ,
485+ } ,
486+ } ) ;
487+ if ( result . status > 201 ) {
488+ console . info ( 'result.body -> ' , await result . json ( ) ) ;
489+ }
490+ const token = `${ Constants . JWT_COOKIE_KEY_NAME } =${ TestUtils . getJwtTokenFromResponse2 ( result ) } ` ;
491+
492+ //check test connections was created
493+ const getUserConnectionsResult = await request ( app . getHttpServer ( ) )
494+ . get ( '/connections' )
495+ . set ( 'Cookie' , token )
496+ . set ( 'Content-Type' , 'application/json' )
497+ . set ( 'Accept' , 'application/json' ) ;
498+ const getUserConnectionsRO = JSON . parse ( getUserConnectionsResult . text ) ;
499+ t . is ( getUserConnectionsResult . status , 200 ) ;
500+ t . is ( getUserConnectionsRO . hasOwnProperty ( 'connections' ) , true ) ;
501+ t . is ( getUserConnectionsRO . connections . length , 4 ) ;
502+
503+ //check user can add connection and use it
504+
505+ const connectionToTestDB = getTestData ( mockFactory ) . connectionToPostgres ;
506+
507+ const { testTableName, testTableColumnName, testEntitiesSeedsCount, testTableSecondColumnName } =
508+ await createTestTable ( connectionToTestDB ) ;
509+
510+ const createConnectionResponse = await request ( app . getHttpServer ( ) )
511+ . post ( '/connection' )
512+ . send ( connectionToTestDB )
513+ . set ( 'Cookie' , token )
514+ . set ( 'Content-Type' , 'application/json' )
515+ . set ( 'Accept' , 'application/json' ) ;
516+ const createConnectionRO = JSON . parse ( createConnectionResponse . text ) ;
517+ t . is ( createConnectionResponse . status , 201 ) ;
518+
519+ const getTableRowsResponse = await request ( app . getHttpServer ( ) )
520+ . get ( `/table/rows/${ createConnectionRO . id } ?tableName=${ testTableName } &page=1&perPage=50` )
521+ . set ( 'Cookie' , token )
522+ . set ( 'Content-Type' , 'application/json' )
523+ . set ( 'Accept' , 'application/json' ) ;
524+
525+ const getTableRowsRO = JSON . parse ( getTableRowsResponse . text ) ;
526+ t . is ( getTableRowsResponse . status , 200 ) ;
527+
528+ t . is ( typeof getTableRowsRO , 'object' ) ;
529+ t . is ( getTableRowsRO . hasOwnProperty ( 'rows' ) , true ) ;
530+ t . is ( getTableRowsRO . hasOwnProperty ( 'primaryColumns' ) , true ) ;
531+ t . is ( getTableRowsRO . hasOwnProperty ( 'pagination' ) , true ) ;
532+ t . is ( getTableRowsRO . rows . length , 42 ) ;
533+ t . is ( typeof getTableRowsRO . primaryColumns , 'object' ) ;
534+ t . is ( getTableRowsRO . primaryColumns [ 0 ] . hasOwnProperty ( 'column_name' ) , true ) ;
535+ t . is ( getTableRowsRO . primaryColumns [ 0 ] . hasOwnProperty ( 'data_type' ) , true ) ;
536+ t . is ( getTableRowsRO . primaryColumns [ 0 ] . column_name , 'id' ) ;
537+ t . is ( getTableRowsRO . primaryColumns [ 0 ] . data_type , 'integer' ) ;
538+
539+ //check that user has a company
540+
541+ const getUserCompanyResult = await request ( app . getHttpServer ( ) )
542+ . get ( '/company/my/full' )
543+ . set ( 'Cookie' , token )
544+ . set ( 'Content-Type' , 'application/json' )
545+ . set ( 'Accept' , 'application/json' ) ;
546+ const getUserCompanyRO = JSON . parse ( getUserCompanyResult . text ) ;
547+ t . is ( getUserCompanyResult . status , 200 ) ;
548+
549+ t . truthy ( getUserCompanyRO ) ;
550+ t . is ( typeof getUserCompanyRO , 'object' ) ;
551+ t . is ( getUserCompanyRO . hasOwnProperty ( 'id' ) , true ) ;
552+ t . is ( typeof getUserCompanyRO . id , 'string' ) ;
553+ t . is ( getUserCompanyRO . hasOwnProperty ( 'name' ) , true ) ;
554+ t . is ( typeof getUserCompanyRO . name , 'string' ) ;
555+ t . is ( getUserCompanyRO . hasOwnProperty ( 'subscriptionLevel' ) , true ) ;
556+ t . is ( getUserCompanyRO . subscriptionLevel , 'TEAM_PLAN' ) ;
557+ t . is ( getUserCompanyRO . hasOwnProperty ( 'is_payment_method_added' ) , true ) ;
558+ t . is ( getUserCompanyRO . is_payment_method_added , false ) ;
559+ t . is ( getUserCompanyRO . hasOwnProperty ( 'is2faEnabled' ) , true ) ;
560+ t . is ( getUserCompanyRO . is2faEnabled , false ) ;
561+ t . is ( getUserCompanyRO . hasOwnProperty ( 'show_test_connections' ) , true ) ;
562+ t . is ( getUserCompanyRO . show_test_connections , true ) ;
563+ t . is ( getUserCompanyRO . hasOwnProperty ( 'connections' ) , true ) ;
564+ t . true ( Array . isArray ( getUserCompanyRO . connections ) ) ;
565+ t . is ( getUserCompanyRO . connections . length , 5 ) ;
566+
567+ for ( const connection of getUserCompanyRO . connections ) {
568+ t . is ( typeof connection . id , 'string' ) ;
569+ t . is ( typeof connection . title , 'string' ) ;
570+ t . is ( typeof connection . author , 'object' ) ;
571+ t . is ( connection . author . role , 'ADMIN' ) ;
572+ t . true ( Array . isArray ( connection . groups ) ) ;
573+ for ( const group of connection . groups ) {
574+ t . is ( typeof group . id , 'string' ) ;
575+ t . is ( group . isMain , true ) ;
576+ t . is ( typeof group . title , 'string' ) ;
577+ t . true ( Array . isArray ( group . users ) ) ;
578+ for ( const user of group . users ) {
579+ t . is ( typeof user . id , 'string' ) ;
580+ t . is ( user . role , 'ADMIN' ) ;
581+ t . is ( typeof user . email , 'string' ) ;
582+ }
583+ }
584+ }
585+ } ) ;
0 commit comments