@@ -181,6 +181,108 @@ describe(StubPostgresDatabaseAdapter, () => {
181181 } ) ;
182182 } ) ;
183183
184+ describe ( 'fetchOneWhereAsync' , ( ) => {
185+ it ( 'fetches one where single' , async ( ) => {
186+ const queryContext = instance ( mock ( EntityQueryContext ) ) ;
187+ const databaseAdapter = new StubPostgresDatabaseAdapter < TestFields , 'customIdField' > (
188+ testEntityConfiguration ,
189+ StubPostgresDatabaseAdapter . convertFieldObjectsToDataStore (
190+ testEntityConfiguration ,
191+ new Map ( [
192+ [
193+ testEntityConfiguration . tableName ,
194+ [
195+ {
196+ customIdField : 'hello' ,
197+ testIndexedField : 'h1' ,
198+ intField : 5 ,
199+ stringField : 'huh' ,
200+ dateField : new Date ( ) ,
201+ nullableField : null ,
202+ } ,
203+ {
204+ customIdField : 'world' ,
205+ testIndexedField : 'h2' ,
206+ intField : 3 ,
207+ stringField : 'huh' ,
208+ dateField : new Date ( ) ,
209+ nullableField : null ,
210+ } ,
211+ ] ,
212+ ] ,
213+ ] ) ,
214+ ) ,
215+ ) ;
216+
217+ const result = await databaseAdapter . fetchOneWhereAsync (
218+ queryContext ,
219+ new SingleFieldHolder ( 'stringField' ) ,
220+ new SingleFieldValueHolder ( 'huh' ) ,
221+ ) ;
222+ expect ( result ) . toMatchObject ( {
223+ stringField : 'huh' ,
224+ } ) ;
225+ } ) ;
226+
227+ it ( 'returns null when no record found' , async ( ) => {
228+ const queryContext = instance ( mock ( EntityQueryContext ) ) ;
229+ const databaseAdapter = new StubPostgresDatabaseAdapter < TestFields , 'customIdField' > (
230+ testEntityConfiguration ,
231+ new Map ( ) ,
232+ ) ;
233+
234+ const result = await databaseAdapter . fetchOneWhereAsync (
235+ queryContext ,
236+ new SingleFieldHolder ( 'stringField' ) ,
237+ new SingleFieldValueHolder ( 'huh' ) ,
238+ ) ;
239+ expect ( result ) . toBeNull ( ) ;
240+ } ) ;
241+
242+ it ( 'fetches one where composite' , async ( ) => {
243+ const queryContext = instance ( mock ( EntityQueryContext ) ) ;
244+ const databaseAdapter = new StubPostgresDatabaseAdapter < TestFields , 'customIdField' > (
245+ testEntityConfiguration ,
246+ StubPostgresDatabaseAdapter . convertFieldObjectsToDataStore (
247+ testEntityConfiguration ,
248+ new Map ( [
249+ [
250+ testEntityConfiguration . tableName ,
251+ [
252+ {
253+ customIdField : 'hello' ,
254+ testIndexedField : 'h1' ,
255+ intField : 5 ,
256+ stringField : 'huh' ,
257+ dateField : new Date ( ) ,
258+ nullableField : null ,
259+ } ,
260+ {
261+ customIdField : 'world' ,
262+ testIndexedField : 'h2' ,
263+ intField : 5 ,
264+ stringField : 'huh' ,
265+ dateField : new Date ( ) ,
266+ nullableField : null ,
267+ } ,
268+ ] ,
269+ ] ,
270+ ] ) ,
271+ ) ,
272+ ) ;
273+
274+ const result = await databaseAdapter . fetchOneWhereAsync (
275+ queryContext ,
276+ new CompositeFieldHolder < TestFields , 'customIdField' > ( [ 'stringField' , 'intField' ] ) ,
277+ new CompositeFieldValueHolder ( { stringField : 'huh' , intField : 5 } ) ,
278+ ) ;
279+ expect ( result ) . toMatchObject ( {
280+ stringField : 'huh' ,
281+ intField : 5 ,
282+ } ) ;
283+ } ) ;
284+ } ) ;
285+
184286 describe ( 'fetchManyByFieldEqualityConjunctionAsync' , ( ) => {
185287 it ( 'supports conjuntions and query modifiers' , async ( ) => {
186288 const queryContext = instance ( mock ( EntityQueryContext ) ) ;
0 commit comments