1
1
import { expect } from "@open-wc/testing" ;
2
2
3
- import { processErrorMessage } from "../../../src/compas-services/foundation.js" ;
3
+ import {
4
+ isNotFoundError ,
5
+ NOT_FOUND_ERROR ,
6
+ processErrorMessage ,
7
+ SERVER_ERROR
8
+ } from "../../../src/compas-services/foundation.js" ;
4
9
5
10
const errorBody =
6
11
`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
@@ -19,13 +24,29 @@ describe('compas-services-foundation', () => {
19
24
const result = await processErrorMessage ( response ) ;
20
25
expect ( result ) . to . be . equal ( statusText ) ;
21
26
} )
22
-
23
27
it ( 'when there is a body in the response, the message is retrieved from the body' , async ( ) => {
24
28
const expectedMessage = 'Name is not a correct name to be used later as filename. (CORE-8000)'
25
29
const statusText = 'some status text' ;
26
30
const response = new Response ( errorBody , < ResponseInit > { statusText : statusText } ) ;
27
31
const result = await processErrorMessage ( response ) ;
28
32
expect ( result ) . to . be . equal ( expectedMessage ) ;
33
+
34
+ } )
35
+
36
+ it ( 'when the error is caused by a status 404 then return true' , ( ) => {
37
+ const reason = { type : NOT_FOUND_ERROR } ;
38
+ const result = isNotFoundError ( reason ) ;
39
+ expect ( result ) . to . be . true ;
40
+ } )
41
+ it ( 'when the error is caused by other status then return false' , ( ) => {
42
+ const reason = { type : SERVER_ERROR } ;
43
+ const result = isNotFoundError ( reason ) ;
44
+ expect ( result ) . to . be . false ;
45
+ } )
46
+ it ( 'when no type of error found then return false' , ( ) => {
47
+ const reason = { } ;
48
+ const result = isNotFoundError ( reason ) ;
49
+ expect ( result ) . to . be . false ;
29
50
} )
30
51
} ) ;
31
52
0 commit comments