Repository: freeCodeCamp/freeCodeCamp
File: api/src/plugins/auth-dev.test.ts (TypeScript)

Code before:
import { GrowthBook } from '@growthbook/growthbook';

import { checkCanConnectToDb, defaultUserEmail } from '../../vitest.utils.js';
import { HOME_LOCATION } from '../utils/env.js';
import { devAuth } from '../plugins/auth-dev.js';
import prismaPlugin from '../db/prisma.js';
import auth from './auth.js';
import cookies from './cookies.js';

import { newUser } from './__fixtures__/user.js';

describe('dev login', () => {
  let fastify: FastifyInstance;

  beforeAll(async () => {
    fastify = Fastify();

    await fastify.register(cookies);
    await fastify.register(auth);
    await fastify.register(devAuth);
    await fastify.register(prismaPlugin);
    await checkCanConnectToDb(fastify.prisma);
    // Mock the GrowthBook plugin
    fastify.decorate('gb', {
      isOn: () => false
    } as Partial<GrowthBook> as GrowthBook);
  });

  beforeEach(async () => {
    await fastify.prisma.user.deleteMany({
      where: { email: defaultUserEmail }
    });
  });

  afterAll(async () => {
    await fastify.prisma.user.deleteMany({
      where: { email: defaultUserEmail }
    });
    await fastify.prisma.$runCommandRaw({ dropDatabase: 1 });
    await fastify.close();
  });

  describe('GET /signin', () => {
    test('should create an account if one does not exist', async () => {
      const before = await fastify.prisma.user.count({});
      await fastify.inject({
        method: 'GET',
        url: '/signin'
      });

      const after = await fastify.prisma.user.count({});

Review comment (suggestion):
```suggestion
    await fastify.register(growthBook, {
      apiHost: GROWTHBOOK_FASTIFY_API_HOST,
      clientKey: GROWTHBOOK_FASTIFY_CLIENT_KEY
    });
```
No need to mock it. This is a little ugly because we're inconsistently passing in variables, rather than simply grabbing them inside the plugin, but that's out of scope.

Code after:

import { checkCanConnectToDb, defaultUserEmail } from '../../vitest.utils.js';
import {
  HOME_LOCATION,
  GROWTHBOOK_FASTIFY_API_HOST,
  GROWTHBOOK_FASTIFY_CLIENT_KEY
} from '../utils/env.js';
import { devAuth } from '../plugins/auth-dev.js';
import prismaPlugin from '../db/prisma.js';
import auth from './auth.js';
import cookies from './cookies.js';
import growthBook from './growth-book.js';

import { newUser } from './__fixtures__/user.js';

describe('dev login', () => {
  let fastify: FastifyInstance;

  beforeAll(async () => {
    fastify = Fastify();

    await fastify.register(cookies);
    await fastify.register(auth);
    await fastify.register(devAuth);
    await fastify.register(prismaPlugin);
    await checkCanConnectToDb(fastify.prisma);
    await fastify.register(growthBook, {
      apiHost: GROWTHBOOK_FASTIFY_API_HOST,
      clientKey: GROWTHBOOK_FASTIFY_CLIENT_KEY
    });
  });

  beforeEach(async () => {
    await fastify.prisma.user.deleteMany({
      where: { email: defaultUserEmail }
    });
  });

  afterAll(async () => {
    await fastify.prisma.user.deleteMany({
      where: { email: defaultUserEmail }
    });
    await fastify.prisma.$runCommandRaw({ dropDatabase: 1 });
    await fastify.close();
  });

  describe('GET /signin', () => {
    test('should create an account if one does not exist', async () => {
      const before = await fastify.prisma.user.count({});
      await fastify.inject({
        method: 'GET',