Skip to content

Commit edb0d54

Browse files
authored
Merge pull request #2726 from objectcomputing/release/0.8
Release v0.8.4
2 parents d445fb6 + 3b38133 commit edb0d54

File tree

5 files changed

+37
-16
lines changed

5 files changed

+37
-16
lines changed

server/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ plugins {
77
id "jacoco"
88
}
99

10-
version "0.8.3"
10+
version "0.8.4"
1111
group "com.objectcomputing.checkins"
1212

1313
repositories {

web-ui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "web-ui",
3-
"version": "0.8.3",
3+
"version": "0.8.4",
44
"private": true,
55
"type": "module",
66
"dependencies": {

web-ui/src/context/AppContext.jsx

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ import {getCertifications} from "../api/certification.js";
3434

3535
const AppContext = React.createContext();
3636

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+
3748
const AppContextProvider = props => {
3849
const [state, dispatch] = useReducer(
3950
reducer,
@@ -64,12 +75,17 @@ const AppContextProvider = props => {
6475
useEffect(() => {
6576
const getCsrf = async () => {
6677
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+
}
7389
}
7490
}
7591
};

web-ui/src/pages/AnniversaryReportPage.test.jsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,28 @@ const userStateWithPermission = {
1414

1515
it('renders correctly', () => {
1616
const mockDate = new Date(2022, 1, 1);
17-
const spy = vi.spyOn(global, 'Date').mockImplementation(() => mockDate);
17+
vi.useFakeTimers();
18+
vi.setSystemTime(mockDate);
1819

1920
snapshot(
2021
<AppContextProvider value={userStateWithPermission}>
2122
<AnniversaryReportPage />
2223
</AppContextProvider>
2324
);
2425

25-
spy.mockRestore();
26+
vi.useRealTimers();
2627
});
2728

2829
it('renders an error if user does not have appropriate permission', () => {
2930
const mockDate = new Date(2022, 1, 1);
30-
const spy = vi.spyOn(global, 'Date').mockImplementation(() => mockDate);
31+
vi.useFakeTimers();
32+
vi.setSystemTime(mockDate);
3133

3234
snapshot(
3335
<AppContextProvider>
3436
<AnniversaryReportPage />
3537
</AppContextProvider>
3638
);
3739

38-
spy.mockRestore();
40+
vi.useRealTimers();
3941
});

web-ui/src/pages/BirthdayReportPage.test.jsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import { vi } from 'vitest';
23
import BirthdayReportPage from './BirthdayReportPage';
34
import { AppContextProvider } from '../context/AppContext';
45

@@ -14,26 +15,28 @@ const userStateWithPermission = {
1415

1516
it('renders correctly', () => {
1617
const mockDate = new Date(2022, 1, 1);
17-
const spy = vi.spyOn(global, 'Date').mockImplementation(() => mockDate);
18+
vi.useFakeTimers();
19+
vi.setSystemTime(mockDate);
1820

1921
snapshot(
2022
<AppContextProvider value={userStateWithPermission}>
2123
<BirthdayReportPage />
2224
</AppContextProvider>
2325
);
2426

25-
spy.mockRestore();
27+
vi.useRealTimers();
2628
});
2729

2830
it('renders an error if user does not have appropriate permission', () => {
2931
const mockDate = new Date(2022, 1, 1);
30-
const spy = vi.spyOn(global, 'Date').mockImplementation(() => mockDate);
32+
vi.useFakeTimers();
33+
vi.setSystemTime(mockDate);
3134

3235
snapshot(
3336
<AppContextProvider>
3437
<BirthdayReportPage />
3538
</AppContextProvider>
3639
);
3740

38-
spy.mockRestore();
41+
vi.useRealTimers();
3942
});

0 commit comments

Comments
 (0)