Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

1.6 KB
Raw Blame
import mongoose from 'mongoose';
import { MongoMemoryServer } from 'mongodb-memory-server';
import { createMethods, createModels } from '@librechat/data-schemas';
import { createInvite, getInvite } from './invite';

let mongoServer: MongoMemoryServer;
let deps: Parameters<typeof getInvite>[2];

beforeAll(async () => {
  mongoServer = await MongoMemoryServer.create();
  await mongoose.connect(mongoServer.getUri());
  createModels(mongoose);

  const { createToken, findToken } = createMethods(mongoose);
  deps = { createToken, findToken } as Parameters<typeof getInvite>[2];
});

afterAll(async () => {
  await mongoose.disconnect();
  await mongoServer.stop();
});

beforeEach(async () => {
  await mongoose.models.Token.deleteMany({});
});

describe('getInvite', () => {
  it('returns the invite for the address it was issued to', async () => {
    const token = (await createInvite('[email protected]', deps)) as string;

    await expect(getInvite(token, '[email protected]', deps)).resolves.toMatchObject({
      email: '[email protected]',
    });
  });

  it('refuses an address the invite was not issued to', async () => {
    const token = (await createInvite('[email protected]', deps)) as string;

    await expect(getInvite(token, '[email protected]', deps)).resolves.toMatchObject({
      error: true,
    });
  });

  it('refuses a lookup carrying no address at all', async () => {
    const token = (await createInvite('[email protected]', deps)) as string;

    await expect(getInvite(token, undefined as unknown as string, deps)).resolves.toMatchObject({
      error: true,
    });
  });
});