File tree Expand file tree Collapse file tree 5 files changed +37
-16
lines changed Expand file tree Collapse file tree 5 files changed +37
-16
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ plugins {
7
7
id " jacoco"
8
8
}
9
9
10
- version " 0.8.3 "
10
+ version " 0.8.4 "
11
11
group " com.objectcomputing.checkins"
12
12
13
13
repositories {
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " web-ui" ,
3
- "version" : " 0.8.3 " ,
3
+ "version" : " 0.8.4 " ,
4
4
"private" : true ,
5
5
"type" : " module" ,
6
6
"dependencies" : {
Original file line number Diff line number Diff line change @@ -34,6 +34,17 @@ import {getCertifications} from "../api/certification.js";
34
34
35
35
const AppContext = React . createContext ( ) ;
36
36
37
+ function getSessionCookieValue ( name ) {
38
+ const cookies = document ?. cookie ?. split ( ';' ) ;
39
+ for ( let i = 0 ; i < cookies . length ; i ++ ) {
40
+ const cookie = cookies [ i ] . trim ( ) ;
41
+ if ( cookie . startsWith ( name + '=' ) ) {
42
+ return decodeURIComponent ( cookie . substring ( name . length + 1 ) ) ;
43
+ }
44
+ }
45
+ return null ;
46
+ }
47
+
37
48
const AppContextProvider = props => {
38
49
const [ state , dispatch ] = useReducer (
39
50
reducer ,
@@ -64,12 +75,17 @@ const AppContextProvider = props => {
64
75
useEffect ( ( ) => {
65
76
const getCsrf = async ( ) => {
66
77
if ( ! csrf ) {
67
- const res = await fetch ( url , {
68
- responseType : 'text' ,
69
- credentials : 'include'
70
- } ) ;
71
- if ( res && res . ok ) {
72
- dispatch ( { type : SET_CSRF , payload : await res . text ( ) } ) ;
78
+ const payload = getSessionCookieValue ( '_csrf' ) ;
79
+ if ( payload ) {
80
+ dispatch ( { type : SET_CSRF , payload } ) ;
81
+ } else {
82
+ const res = await fetch ( url , {
83
+ responseType : 'text' ,
84
+ credentials : 'include'
85
+ } ) ;
86
+ if ( res && res . ok ) {
87
+ dispatch ( { type : SET_CSRF , payload : await res . text ( ) } ) ;
88
+ }
73
89
}
74
90
}
75
91
} ;
Original file line number Diff line number Diff line change @@ -14,26 +14,28 @@ const userStateWithPermission = {
14
14
15
15
it ( 'renders correctly' , ( ) => {
16
16
const mockDate = new Date ( 2022 , 1 , 1 ) ;
17
- const spy = vi . spyOn ( global , 'Date' ) . mockImplementation ( ( ) => mockDate ) ;
17
+ vi . useFakeTimers ( ) ;
18
+ vi . setSystemTime ( mockDate ) ;
18
19
19
20
snapshot (
20
21
< AppContextProvider value = { userStateWithPermission } >
21
22
< AnniversaryReportPage />
22
23
</ AppContextProvider >
23
24
) ;
24
25
25
- spy . mockRestore ( ) ;
26
+ vi . useRealTimers ( ) ;
26
27
} ) ;
27
28
28
29
it ( 'renders an error if user does not have appropriate permission' , ( ) => {
29
30
const mockDate = new Date ( 2022 , 1 , 1 ) ;
30
- const spy = vi . spyOn ( global , 'Date' ) . mockImplementation ( ( ) => mockDate ) ;
31
+ vi . useFakeTimers ( ) ;
32
+ vi . setSystemTime ( mockDate ) ;
31
33
32
34
snapshot (
33
35
< AppContextProvider >
34
36
< AnniversaryReportPage />
35
37
</ AppContextProvider >
36
38
) ;
37
39
38
- spy . mockRestore ( ) ;
40
+ vi . useRealTimers ( ) ;
39
41
} ) ;
Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
+ import { vi } from 'vitest' ;
2
3
import BirthdayReportPage from './BirthdayReportPage' ;
3
4
import { AppContextProvider } from '../context/AppContext' ;
4
5
@@ -14,26 +15,28 @@ const userStateWithPermission = {
14
15
15
16
it ( 'renders correctly' , ( ) => {
16
17
const mockDate = new Date ( 2022 , 1 , 1 ) ;
17
- const spy = vi . spyOn ( global , 'Date' ) . mockImplementation ( ( ) => mockDate ) ;
18
+ vi . useFakeTimers ( ) ;
19
+ vi . setSystemTime ( mockDate ) ;
18
20
19
21
snapshot (
20
22
< AppContextProvider value = { userStateWithPermission } >
21
23
< BirthdayReportPage />
22
24
</ AppContextProvider >
23
25
) ;
24
26
25
- spy . mockRestore ( ) ;
27
+ vi . useRealTimers ( ) ;
26
28
} ) ;
27
29
28
30
it ( 'renders an error if user does not have appropriate permission' , ( ) => {
29
31
const mockDate = new Date ( 2022 , 1 , 1 ) ;
30
- const spy = vi . spyOn ( global , 'Date' ) . mockImplementation ( ( ) => mockDate ) ;
32
+ vi . useFakeTimers ( ) ;
33
+ vi . setSystemTime ( mockDate ) ;
31
34
32
35
snapshot (
33
36
< AppContextProvider >
34
37
< BirthdayReportPage />
35
38
</ AppContextProvider >
36
39
) ;
37
40
38
- spy . mockRestore ( ) ;
41
+ vi . useRealTimers ( ) ;
39
42
} ) ;
You can’t perform that action at this time.
0 commit comments