@@ -2,6 +2,10 @@ import { ResultRecord } from "./result-record";
22import { ErrorType } from "../enumerations/error-type" ;
33import { ResultErrorRecord } from "./result-error-record" ;
44import { ResultError } from "../interfaces/result-error" ;
5+ import {
6+ ResultRecordFactory ,
7+ ResultErrorRecordFactory ,
8+ } from "../tests/factories" ;
59
610describe ( "ResultRecord" , ( ) => {
711 // -----------------------------------------------------------------------------------------
@@ -203,6 +207,82 @@ describe("ResultRecord", () => {
203207
204208 // #endregion errorCount
205209
210+ // -----------------------------------------------------------------------------------------
211+ // #region doesNotHaveErrors
212+ // -----------------------------------------------------------------------------------------
213+
214+ describe ( "doesNotHaveErrors" , ( ) => {
215+ test ( "when errors is null, returns true" , ( ) => {
216+ expect (
217+ ResultRecordFactory . build ( {
218+ errors : ( null as unknown ) as any [ ] ,
219+ } ) . doesNotHaveErrors ( )
220+ ) . toBeTrue ( ) ;
221+ } ) ;
222+
223+ test ( "when errors is undefined, returns true" , ( ) => {
224+ expect (
225+ ResultRecordFactory . build ( {
226+ errors : undefined ,
227+ } ) . doesNotHaveErrors ( )
228+ ) . toBeTrue ( ) ;
229+ } ) ;
230+
231+ test ( "when errors is empty array, returns true" , ( ) => {
232+ expect (
233+ ResultRecordFactory . build ( { errors : [ ] } ) . doesNotHaveErrors ( )
234+ ) . toBeTrue ( ) ;
235+ } ) ;
236+
237+ test ( "when errors is not empty, returns false" , ( ) => {
238+ // Arrange
239+ const errors = ResultErrorRecordFactory . buildList ( 1 ) ;
240+
241+ // Act & Assert
242+ expect (
243+ ResultRecordFactory . build ( {
244+ errors : errors ,
245+ } ) . doesNotHaveErrors ( )
246+ ) . toBeFalse ( ) ;
247+ } ) ;
248+ } ) ; // end doesNotHaveErrors
249+
250+ // -----------------------------------------------------------------------------------------
251+ // #region getErrorMessageFor
252+ // -----------------------------------------------------------------------------------------
253+
254+ describe ( "#getErrorMessageFor" , ( ) => {
255+ it ( "When no error exists for given key, then returns undefined" , ( ) => {
256+ // Arrange
257+ const errorKey = "TEST_ERROR_KEY" ;
258+ const resultRecord = ResultRecordFactory . build ( {
259+ errors : [ ] ,
260+ } ) ;
261+
262+ // Act
263+ const result = resultRecord . getErrorMessageFor ( errorKey ) ;
264+
265+ // Assert
266+ expect ( result ) . toBeNil ( ) ;
267+ } ) ;
268+
269+ it ( "When an error exists for the given key, then returns the error message" , ( ) => {
270+ // Arrange
271+ const errorKey = "TEST_ERROR_KEY" ;
272+ const resultRecord = ResultRecordFactory . build ( {
273+ errors : ResultErrorRecordFactory . buildList ( 1 , {
274+ key : errorKey ,
275+ } ) ,
276+ } ) ;
277+
278+ // Act
279+ const result = resultRecord . getErrorMessageFor ( errorKey ) ;
280+
281+ // Assert
282+ expect ( result ) . not . toBeNil ( ) ;
283+ } ) ;
284+ } ) ; // end getErrorMessageFor
285+
206286 // -----------------------------------------------------------------------------------------
207287 // #region hasErrorFor
208288 // -----------------------------------------------------------------------------------------
0 commit comments