Repository: freeCodeCamp/freeCodeCamp
File: api/src/routes/protected/user.test.ts (TypeScript)

Code before:
  devLogin,
  setupServer,
  superRequest,
  createSuperRequest,
  defaultUsername,
  resetDefaultUser
} from '../../../jest.utils';
import { JWT_SECRET } from '../../utils/env';
import {
  clearEnvExam,
  seedEnvExam,
  seedEnvExamAttempt,
  seedExamEnvExamAuthToken
} from '../../../__mocks__/exam-environment-exam';
import { getMsTranscriptApiUrl } from './user';

const mockedFetch = jest.fn();
jest.spyOn(globalThis, 'fetch').mockImplementation(mockedFetch);

jest.mock('../../utils/env', () => {
  // eslint-disable-next-line @typescript-eslint/no-unsafe-return
  return {
    ...jest.requireActual('../../utils/env'),
    DEPLOYMENT_ENV: 'production'
  };
});

// This is used to build a test user.
const testUserData: Prisma.userCreateInput = {
  ...createUserInput(defaultUserEmail),
  username: 'foobar',
  usernameDisplay: 'Foo Bar',
  progressTimestamps: [1520002973119, 1520440323273],
  completedChallenges: [
    {
      id: 'a6b0bb188d873cb2c8729495',
      completedDate: 1520002973119,
      solution: null,
      challengeType: 5,
      files: [
        {
          contents: 'test',
          ext: 'js',
          key: 'indexjs',
          name: 'test',
          path: 'path-test'
        },
        {
          contents: 'test2',
          ext: 'html',
          key: 'html-test',

Review comment (security):
We could make the getter return a variable instead of a fixed value:

```suggestion
let mockDeploymentEnv = 'production';

jest.mock('../../utils/env', () => {
  const actualEnv = jest.requireActual('../../utils/env');
  // eslint-disable-next-line @typescript-eslint/no-unsafe-return
  return {
    ...actualEnv,
    get DEPLOYMENT_ENV() {
      return mockDeploymentEnv;
    },
    JWT_SECRET: actualEnv.JWT_SECRET
  };
});
```

Code after:
  devLogin,
  setupServer,
  superRequest,
  createSuperRequest,
  defaultUsername,
  resetDefaultUser
} from '../../../jest.utils';
import { JWT_SECRET } from '../../utils/env';
import {
  clearEnvExam,
  seedEnvExam,
  seedEnvExamAttempt,
  seedExamEnvExamAuthToken
} from '../../../__mocks__/exam-environment-exam';
import { getMsTranscriptApiUrl } from './user';

const mockedFetch = jest.fn();
jest.spyOn(globalThis, 'fetch').mockImplementation(mockedFetch);

let mockDeploymentEnv = 'staging';
jest.mock('../../utils/env', () => {
  const actualEnv = jest.requireActual('../../utils/env');
  // eslint-disable-next-line @typescript-eslint/no-unsafe-return
  return {
    ...actualEnv,
    get DEPLOYMENT_ENV() {
      return mockDeploymentEnv;
    },
    JWT_SECRET: actualEnv.JWT_SECRET
  };
});

// This is used to build a test user.
const testUserData: Prisma.userCreateInput = {
  ...createUserInput(defaultUserEmail),
  username: 'foobar',
  usernameDisplay: 'Foo Bar',
  progressTimestamps: [1520002973119, 1520440323273],
  completedChallenges: [
    {
      id: 'a6b0bb188d873cb2c8729495',
      completedDate: 1520002973119,
      solution: null,
      challengeType: 5,
      files: [
        {
          contents: 'test',
          ext: 'js',
          key: 'indexjs',
          name: 'test',
          path: 'path-test'