11import { setActivePinia } from "pinia"
22import { createTestingPinia } from "@pinia/testing"
3- import { describe , test , expect , expectTypeOf , beforeEach } from "vitest"
3+ import { describe , test , expect , expectTypeOf , beforeEach , vi } from "vitest"
44import { registerEndpoint } from "@nuxt/test-utils/runtime"
55import back_schemas from "@geode/opengeodeweb-back/schemas.json"
66
@@ -20,7 +20,7 @@ describe("Geode Store", () => {
2020 } )
2121
2222 describe ( "state" , ( ) => {
23- test ( "initial state" , async ( ) => {
23+ test ( "initial state" , ( ) => {
2424 expectTypeOf ( geode_store . default_local_port ) . toBeString ( )
2525 expectTypeOf ( geode_store . request_counter ) . toBeNumber ( )
2626 expectTypeOf ( geode_store . is_running ) . toBeBoolean ( )
@@ -52,8 +52,8 @@ describe("Geode Store", () => {
5252
5353 test ( "test override default_local_port" , ( ) => {
5454 infra_store . is_cloud = false
55- geode_store . default_local_port = "8080 "
56- expect ( geode_store . port ) . toBe ( "8080 " )
55+ geode_store . default_local_port = "12 "
56+ expect ( geode_store . port ) . toBe ( "12 " )
5757 } )
5858 } )
5959
@@ -63,17 +63,15 @@ describe("Geode Store", () => {
6363 infra_store . domain_name = "localhost"
6464 expect ( geode_store . base_url ) . toBe ( "http://localhost:5000" )
6565 } )
66-
67- test ( "test is_cloud true" , async ( ) => {
66+ test ( "test is_cloud true" , ( ) => {
6867 infra_store . is_cloud = true
6968 infra_store . ID = "123456"
7069 infra_store . domain_name = "example.com"
7170 expect ( geode_store . base_url ) . toBe (
7271 "https://example.com:443/123456/geode" ,
7372 )
7473 } )
75-
76- test ( "test is_cloud true, ID empty" , async ( ) => {
74+ test ( "test is_cloud true, ID empty" , ( ) => {
7775 infra_store . is_cloud = true
7876 infra_store . ID = ""
7977 infra_store . domain_name = "example.com"
@@ -97,28 +95,28 @@ describe("Geode Store", () => {
9795
9896 describe ( "actions" , ( ) => {
9997 describe ( "do_ping" , ( ) => {
100- test ( "request_error" , async ( ) => {
101- geode_store . base_url = ""
102- try {
103- await geode_store . do_ping ( )
104- } catch ( e ) {
105- console . log ( "e" , e )
106- }
107- expect ( geode_store . is_running ) . toBe ( false )
108- expect ( feedback_store . server_error ) . toBe ( true )
109- } )
98+ const getFakeCall = vi . fn ( )
99+ registerEndpoint ( back_schemas . opengeodeweb_back . ping . $id , getFakeCall )
110100
111101 test ( "response" , async ( ) => {
112102 geode_store . base_url = ""
113- geode_store . is_running = true
114- registerEndpoint ( back_schemas . opengeodeweb_back . ping . $id , {
115- method : "POST" ,
116- handler : ( ) => ( { } ) ,
117- } )
103+ getFakeCall . mockImplementation ( ( ) => ( { } ) )
118104 await geode_store . do_ping ( )
119105 expect ( geode_store . is_running ) . toBe ( true )
120106 expect ( feedback_store . server_error ) . toBe ( false )
121107 } )
108+ test ( "response_error" , async ( ) => {
109+ geode_store . base_url = ""
110+ getFakeCall . mockImplementation ( ( ) => {
111+ throw createError ( {
112+ status : 500 ,
113+ } )
114+ } )
115+
116+ await geode_store . do_ping ( )
117+ expect ( geode_store . is_running ) . toBe ( false )
118+ expect ( feedback_store . server_error ) . toBe ( true )
119+ } )
122120 } )
123121
124122 describe ( "start_request" , ( ) => {
0 commit comments