@@ -15,6 +15,10 @@ const { EMAIL_DB_SERVICE_NAME } = EmailProto;
1515@Injectable ( )
1616export class EmailService implements OnModuleInit {
1717 private emailService : EmailProto . EmailDbServiceClient ;
18+ private testDomains : Map <
19+ string ,
20+ EmailProto . AuthenticatedDomain [ ]
21+ > = new Map ( ) ;
1822 constructor ( @Inject ( EMAIL_DB_SERVICE_NAME ) private emailClient : ClientGrpc ) { }
1923
2024 onModuleInit ( ) {
@@ -71,13 +75,26 @@ export class EmailService implements OnModuleInit {
7175 const sendGridUrl = 'https://api.sendgrid.com/v3/whitelabel/domains' ;
7276
7377 if ( process . env [ 'NODE_ENV' ] == 'test' ) {
74- await lastValueFrom ( this . emailService . createEmailDomain ( {
78+ const configKey = `${ req . configId } :${ req . configEnvironment } ` ;
79+ const domains = this . testDomains . get ( configKey ) ?? [ ] ;
80+ domains . push ( {
81+ id : 0 ,
7582 domain : req . domain ,
76- subdomain : req . subdomain ,
77- sendgridId : 0 ,
78- configId : req . configId ,
79- configEnvironment : req . configEnvironment ,
80- } ) ) ;
83+ subdomain : req . subdomain ?? undefined ,
84+ valid : false ,
85+ } ) ;
86+ this . testDomains . set ( configKey , domains ) ;
87+
88+ lastValueFrom (
89+ this . emailService . createEmailDomain ( {
90+ domain : req . domain ,
91+ subdomain : req . subdomain ,
92+ sendgridId : 0 ,
93+ configId : req . configId ,
94+ configEnvironment : req . configEnvironment ,
95+ } ) ,
96+ ) . catch ( ( ) => { } ) ;
97+
8198 return {
8299 statusCode : 201 ,
83100 id : 0 ,
@@ -390,13 +407,9 @@ export class EmailService implements OnModuleInit {
390407 }
391408
392409 if ( process . env [ 'NODE_ENV' ] == 'test' ) {
410+ const configKey = `${ req . configId } :${ req . configEnvironment } ` ;
393411 return {
394- domains : ( config . domains ?? [ ] ) . map ( ( d ) => ( {
395- id : d . sendgridId ,
396- domain : d . domain ,
397- subdomain : d . subdomain ?? undefined ,
398- valid : false ,
399- } ) ) ,
412+ domains : this . testDomains . get ( configKey ) ?? [ ] ,
400413 } ;
401414 }
402415
0 commit comments