@@ -100,6 +100,7 @@ import {
100100import { defaultLogger } from "~/logging" ;
101101import { schema } from "~/schema" ;
102102import { getTestDB } from "~/tests/fixtures/databaseHelper" ;
103+ import { Context } from "~/types" ;
103104
104105const insertUserRequest = insertUsersSchema . deepPartial ( ) ;
105106
@@ -121,7 +122,10 @@ const CRUDDates = ({
121122 deletedAt : typeof deletedAt !== "undefined" ? deletedAt : faker . date . recent ( ) ,
122123} ) ;
123124
124- const createExecutor = ( user ?: Awaited < ReturnType < typeof insertUser > > ) =>
125+ const createExecutor = (
126+ user ?: Awaited < ReturnType < typeof insertUser > > | undefined ,
127+ context ?: Partial < Context > ,
128+ ) =>
125129 buildHTTPExecutor ( {
126130 fetch : createYoga < Env > ( {
127131 schema,
@@ -134,6 +138,7 @@ const createExecutor = (user?: Awaited<ReturnType<typeof insertUser>>) =>
134138 logger : defaultLogger ,
135139 USER : user ? user : undefined ,
136140 GET_STRIPE_CLIENT : ( ) => null ,
141+ ...( context ?? { } ) ,
137142 } ;
138143 } ,
139144 plugins : [ authZEnvelopPlugin ( { rules } ) ] ,
@@ -145,8 +150,9 @@ export const executeGraphqlOperation = <
145150 TVariables extends Record < string , any > = Record < string , any > ,
146151> (
147152 params : ExecutionRequest < TVariables , unknown , unknown , undefined , unknown > ,
153+ context ?: Partial < Context > ,
148154) : Promise < ExecutionResult < TResult > > => {
149- const executor = createExecutor ( ) ;
155+ const executor = createExecutor ( undefined , context ) ;
150156
151157 // @ts -expect-error This is ok. Executor returns a promise with they types passed
152158 return executor ( params ) ;
@@ -158,8 +164,9 @@ export const executeGraphqlOperationAsUser = <
158164> (
159165 params : ExecutionRequest < TVariables , unknown , unknown , undefined , unknown > ,
160166 user : Awaited < ReturnType < typeof insertUser > > ,
167+ context ?: Partial < Context > ,
161168) : Promise < ExecutionResult < TResult > > => {
162- const executor = createExecutor ( user ) ;
169+ const executor = createExecutor ( user , context ) ;
163170
164171 // @ts -expect-error This error is ok. Executor returns a promise with they types passed
165172 return executor ( params ) ;
@@ -171,13 +178,14 @@ export const executeGraphqlOperationAsSuperAdmin = async <
171178> (
172179 params : ExecutionRequest < TVariables , unknown , unknown , undefined , unknown > ,
173180 user ?: Awaited < ReturnType < typeof insertUser > > ,
181+ context ?: Partial < Context > ,
174182) : Promise < ExecutionResult < TResult > > => {
175183 if ( user && ! user . isSuperAdmin ) {
176184 throw new Error ( "User passed is not a super admin" ) ;
177185 }
178186
179187 const superAdmin = user ?? ( await insertUser ( { isSuperAdmin : true } ) ) ;
180- const executor = createExecutor ( superAdmin ) ;
188+ const executor = createExecutor ( superAdmin , context ) ;
181189
182190 // @ts -expect-error This error is ok. Executor returns a promise with they types passed
183191 return executor ( params ) ;
@@ -234,10 +242,11 @@ export const insertUser = async (
234242 externalId : partialInput ?. externalId ?? faker . string . uuid ( ) ,
235243 username : partialInput ?. username ?? faker . internet . userName ( ) ,
236244 bio : partialInput ?. bio ?? faker . lorem . paragraph ( ) ,
237- email : partialInput ?. email ?? faker . internet . email ( ) ,
245+ email : ( partialInput ?. email ?? faker . internet . email ( ) ) . toLowerCase ( ) ,
238246 name : partialInput ?. name ,
239247 isSuperAdmin : partialInput ?. isSuperAdmin ,
240248 isEmailVerified : partialInput ?. isEmailVerified ,
249+ isRetoolEnabled : partialInput ?. isRetoolEnabled ,
241250 pronouns :
242251 partialInput ?. pronouns ??
243252 faker . helpers . arrayElement ( Object . values ( PronounsEnum ) ) ,
0 commit comments