1
1
import { expect } from "@open-wc/testing" ;
2
2
3
3
import {
4
+ COMMONS_NAMESPACE ,
5
+ getWebsocketUri ,
4
6
processErrorMessage ,
5
7
} from "../../../src/compas-services/foundation.js" ;
6
8
7
9
const errorBody =
8
10
`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
9
- <compas-commons:ErrorResponse xmlns:compas-commons="https://www.lfenergy.org/compas/commons/v1 ">
11
+ <compas-commons:ErrorResponse xmlns:compas-commons="${ COMMONS_NAMESPACE } ">
10
12
<compas-commons:ErrorMessage>
11
13
<compas-commons:Code>CORE-8000</compas-commons:Code>
12
14
<compas-commons:Message>Name is not a correct name to be used later as filename.</compas-commons:Message>
@@ -15,19 +17,31 @@ const errorBody =
15
17
</compas-commons:ErrorResponse>` ;
16
18
17
19
describe ( 'compas-services-foundation' , ( ) => {
18
- it ( 'when there is no body in the response, the status text will be returned' , async ( ) => {
19
- const statusText = 'some status text' ;
20
- const response = new Response ( null , < ResponseInit > { statusText : statusText } ) ;
21
- const result = await processErrorMessage ( response ) ;
22
- expect ( result ) . to . be . equal ( statusText ) ;
23
- } )
24
- it ( 'when there is a body in the response, the message is retrieved from the body' , async ( ) => {
25
- const expectedMessage = 'Name is not a correct name to be used later as filename. (CORE-8000)'
26
- const statusText = 'some status text' ;
27
- const response = new Response ( errorBody , < ResponseInit > { statusText : statusText } ) ;
28
- const result = await processErrorMessage ( response ) ;
29
- expect ( result ) . to . be . equal ( expectedMessage ) ;
20
+ describe ( 'execute processErrorMessage' , ( ) => {
21
+ it ( 'when there is no body in the response, the status text will be returned' , async ( ) => {
22
+ const statusText = 'some status text' ;
23
+ const response = new Response ( null , < ResponseInit > { statusText : statusText } ) ;
24
+ const result = await processErrorMessage ( response ) ;
25
+ expect ( result ) . to . be . equal ( statusText ) ;
26
+ } ) ;
30
27
31
- } )
28
+ it ( 'when there is a body in the response, the message is retrieved from the body' , async ( ) => {
29
+ const expectedMessage = 'Name is not a correct name to be used later as filename. (CORE-8000)'
30
+ const statusText = 'some status text' ;
31
+ const response = new Response ( errorBody , < ResponseInit > { statusText : statusText } ) ;
32
+ const result = await processErrorMessage ( response ) ;
33
+ expect ( result ) . to . be . equal ( expectedMessage ) ;
34
+ } ) ;
35
+ } ) ;
36
+
37
+ describe ( 'execute getWebsocketUri' , ( ) => {
38
+ it ( 'when full http url passed then http replaced with ws' , ( ) => {
39
+ expect ( getWebsocketUri ( "http://somesite.com/path" ) ) . to . be . equal ( "ws://somesite.com/path" )
40
+ } ) ;
41
+
42
+ it ( 'when full https url passed then http replaced with ws' , ( ) => {
43
+ expect ( getWebsocketUri ( "https://somesite.com/path" ) ) . to . be . equal ( "wss://somesite.com/path" )
44
+ } ) ;
45
+ } ) ;
32
46
} ) ;
33
47
0 commit comments