fix(environment): Use DEPLOYMENT_ENV and DEPLOYMENT_TLD (#61925)

This commit is contained in:
Mrugesh Mohapatra
2025-08-27 22:47:21 +05:30
committed by GitHub
parent 12b5905c60
commit 0c1498a84d
4 changed files with 13 additions and 8 deletions

View File

@@ -112,7 +112,8 @@ jobs:
# LOKI_URL
# Variables set from SetupJob
DEPLOYMENT_VERSION: ${{ needs.build.outputs.tagname }}
DEPLOYMENT_ENV: ${{ needs.setup-jobs.outputs.site_tld }}
DEPLOYMENT_ENV: ${{ needs.setup-jobs.outputs.tgt_env_long }}
DEPLOYMENT_TLD: ${{ needs.setup-jobs.outputs.site_tld }}
FCC_API_LOG_LEVEL: ${{ needs.setup-jobs.outputs.api_log_lvl }}
# Stack name
STACK_NAME: ${{ needs.setup-jobs.outputs.tgt_env_short }}-api
@@ -148,6 +149,7 @@ jobs:
echo -e '\nLOG:Adding deployment variables...'
{
echo \"DEPLOYMENT_VERSION=$DEPLOYMENT_VERSION\"
echo \"DEPLOYMENT_TLD=$DEPLOYMENT_TLD\"
echo \"DEPLOYMENT_ENV=$DEPLOYMENT_ENV\"
echo \"FCC_API_LOG_LEVEL=$FCC_API_LOG_LEVEL\"
} >> .env
@@ -173,6 +175,7 @@ jobs:
\"STRIPE_SECRET_KEY\"
\"LOKI_URL\"
\"DEPLOYMENT_VERSION\"
\"DEPLOYMENT_TLD\"
\"DEPLOYMENT_ENV\"
\"FCC_API_LOG_LEVEL\"
)

View File

@@ -31,7 +31,7 @@ vi.mock('../../utils/env', async importOriginal => {
return {
...actual,
FCC_ENABLE_EXAM_ENVIRONMENT: 'true',
DEPLOYMENT_ENV: 'org'
DEPLOYMENT_ENV: 'production'
};
});

View File

@@ -40,7 +40,7 @@ import { getMsTranscriptApiUrl } from './user';
const mockedFetch = vi.fn();
vi.spyOn(globalThis, 'fetch').mockImplementation(mockedFetch);
let mockDeploymentEnv = 'dev';
let mockDeploymentEnv = 'staging';
vi.mock('../../utils/env', async () => {
const actualEnv =
await vi.importActual<typeof import('../../utils/env')>('../../utils/env');
@@ -1300,11 +1300,11 @@ Thanks and regards,
describe('/user/exam-environment/token', () => {
beforeEach(() => {
mockDeploymentEnv = 'org';
mockDeploymentEnv = 'staging';
});
afterAll(() => {
mockDeploymentEnv = 'dev';
mockDeploymentEnv = 'production';
});
afterEach(async () => {
@@ -1316,6 +1316,7 @@ Thanks and regards,
});
test('POST generates a new token if one does not exist', async () => {
mockDeploymentEnv = 'production';
const response = await superPost('/user/exam-environment/token');
const { examEnvironmentAuthorizationToken } = response.body;
@@ -1338,6 +1339,7 @@ Thanks and regards,
});
test('POST only allows for one token per user id', async () => {
mockDeploymentEnv = 'production';
const token =
await fastifyTestInstance.prisma.examEnvironmentAuthorizationToken.create(
{
@@ -1372,14 +1374,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 = 'dev';
mockDeploymentEnv = 'staging';
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 = 'dev';
mockDeploymentEnv = 'staging';
await fastifyTestInstance.prisma.user.update({
where: {
id: defaultUserId

View File

@@ -519,7 +519,7 @@ async function examEnvironmentTokenHandler(
// In non-production environments, only staff are allowed to generate a token
if (
DEPLOYMENT_ENV !== 'org' &&
DEPLOYMENT_ENV !== 'production' &&
(!req.user?.email?.endsWith('@freecodecamp.org') ||
!req.user?.emailVerified)
) {