1
1
import { describe , expect , it , vi , beforeEach , afterEach } from "vitest" ;
2
2
import { exchangeAuthCode } from "." ;
3
3
import { MemoryStorage , StorageKeys } from "../sessionManager" ;
4
- import { setActiveStorage } from "./token" ;
4
+ import { getActiveStorage , setActiveStorage } from "./token" ;
5
5
import createFetchMock from "vitest-fetch-mock" ;
6
6
import { frameworkSettings } from "./exchangeAuthCode" ;
7
7
8
8
const fetchMock = createFetchMock ( vi ) ;
9
9
10
- describe ( "exhangeAuthCode " , ( ) => {
10
+ describe ( "exchangeAuthCode " , ( ) => {
11
11
beforeEach ( ( ) => {
12
12
fetchMock . enableMocks ( ) ;
13
13
} ) ;
@@ -56,13 +56,16 @@ describe("exhangeAuthCode", () => {
56
56
urlParams . append ( "code" , "test" ) ;
57
57
58
58
expect (
59
- exchangeAuthCode ( {
59
+ await exchangeAuthCode ( {
60
60
urlParams,
61
61
domain : "http://test.kinde.com" ,
62
62
clientId : "test" ,
63
- redirectURL : "http://test.kinde.com " ,
63
+ redirectURL : "http://test.kinde.coma " ,
64
64
} ) ,
65
- ) . rejects . toThrowError ( "No active storage found" ) ;
65
+ ) . toStrictEqual ( {
66
+ error : "Authentication storage is not initialized" ,
67
+ success : false ,
68
+ } ) ;
66
69
} ) ;
67
70
68
71
it ( "state mismatch" , async ( ) => {
@@ -192,7 +195,7 @@ describe("exhangeAuthCode", () => {
192
195
} ) ;
193
196
} ) ;
194
197
195
- it ( "set the framework and version on header " , async ( ) => {
198
+ it ( "should handle token exchange failure " , async ( ) => {
196
199
const store = new MemoryStorage ( ) ;
197
200
setActiveStorage ( store ) ;
198
201
@@ -202,9 +205,6 @@ describe("exhangeAuthCode", () => {
202
205
[ StorageKeys . state ] : state ,
203
206
} ) ;
204
207
205
- frameworkSettings . framework = "Framework" ;
206
- frameworkSettings . frameworkVersion = "Version" ;
207
-
208
208
const input = "hello" ;
209
209
210
210
const urlParams = new URLSearchParams ( ) ;
0 commit comments