fix(api): DEPLOYMENT_ENV not same as client (#61893)

This commit is contained in:
Shaun Hamilton
2025-08-21 03:28:05 +02:00
committed by GitHub
parent b9f2f72058
commit 3d78a31bc6
3 changed files with 7 additions and 7 deletions
@@ -21,7 +21,7 @@ jest.mock('../../utils/env', () => {
return {
...jest.requireActual('../../utils/env'),
FCC_ENABLE_EXAM_ENVIRONMENT: 'true',
DEPLOYMENT_ENV: 'production'
DEPLOYMENT_ENV: 'org'
};
});
+5 -5
View File
@@ -29,7 +29,7 @@ import { getMsTranscriptApiUrl } from './user';
const mockedFetch = jest.fn();
jest.spyOn(globalThis, 'fetch').mockImplementation(mockedFetch);
let mockDeploymentEnv = 'staging';
let mockDeploymentEnv = 'dev';
jest.mock('../../utils/env', () => {
const actualEnv = jest.requireActual('../../utils/env');
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
@@ -1287,11 +1287,11 @@ Thanks and regards,
describe('/user/exam-environment/token', () => {
beforeEach(() => {
mockDeploymentEnv = 'production';
mockDeploymentEnv = 'org';
});
afterAll(() => {
mockDeploymentEnv = 'staging';
mockDeploymentEnv = 'dev';
});
afterEach(async () => {
@@ -1359,14 +1359,14 @@ Thanks and regards,
test('POST does not generate a new token in non-production environments for non-staff', async () => {
// Override deployment environment for this test
mockDeploymentEnv = 'development';
mockDeploymentEnv = 'dev';
const response = await superPost('/user/exam-environment/token');
expect(response.status).toBe(403);
});
test('POST does generate a new token in non-production environments for staff', async () => {
// Override deployment environment for this test
mockDeploymentEnv = 'staging';
mockDeploymentEnv = 'dev';
await fastifyTestInstance.prisma.user.update({
where: {
id: defaultUserId
+1 -1
View File
@@ -519,7 +519,7 @@ async function examEnvironmentTokenHandler(
// In non-production environments, only staff are allowed to generate a token
if (
DEPLOYMENT_ENV !== 'production' &&
DEPLOYMENT_ENV !== 'org' &&
(!req.user?.email?.endsWith('@freecodecamp.org') ||
!req.user?.emailVerified)
) {