first commit
This commit is contained in:
25
calcom/apps/api/v2/test/mocks/api-auth-mock.strategy.ts
Normal file
25
calcom/apps/api/v2/test/mocks/api-auth-mock.strategy.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { BaseStrategy } from "@/lib/passport/strategies/types";
|
||||
import { UsersRepository } from "@/modules/users/users.repository";
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { PassportStrategy } from "@nestjs/passport";
|
||||
|
||||
@Injectable()
|
||||
export class ApiAuthMockStrategy extends PassportStrategy(BaseStrategy, "api-auth") {
|
||||
constructor(private readonly email: string, private readonly usersRepository: UsersRepository) {
|
||||
super();
|
||||
}
|
||||
|
||||
async authenticate() {
|
||||
try {
|
||||
const user = await this.usersRepository.findByEmailWithProfile(this.email);
|
||||
if (!user) {
|
||||
throw new Error("User with the provided ID not found");
|
||||
}
|
||||
|
||||
return this.success(user);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
if (error instanceof Error) return this.error(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
58
calcom/apps/api/v2/test/mocks/calendars-service-mock.ts
Normal file
58
calcom/apps/api/v2/test/mocks/calendars-service-mock.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import { CalendarsService } from "@/ee/calendars/services/calendars.service";
|
||||
|
||||
export class CalendarsServiceMock {
|
||||
async getCalendars() {
|
||||
return {
|
||||
connectedCalendars: [
|
||||
{
|
||||
integration: {
|
||||
installed: false,
|
||||
type: "google_calendar",
|
||||
title: "",
|
||||
name: "",
|
||||
description: "",
|
||||
variant: "calendar",
|
||||
slug: "",
|
||||
locationOption: null,
|
||||
categories: ["calendar"],
|
||||
logo: "",
|
||||
publisher: "",
|
||||
url: "",
|
||||
email: "",
|
||||
},
|
||||
credentialId: 1,
|
||||
error: { message: "" },
|
||||
},
|
||||
{
|
||||
integration: {
|
||||
installed: false,
|
||||
type: "office365_calendar",
|
||||
title: "",
|
||||
name: "",
|
||||
description: "",
|
||||
variant: "calendar",
|
||||
slug: "",
|
||||
locationOption: null,
|
||||
categories: ["calendar"],
|
||||
logo: "",
|
||||
publisher: "",
|
||||
url: "",
|
||||
email: "",
|
||||
},
|
||||
credentialId: 2,
|
||||
error: { message: "" },
|
||||
},
|
||||
],
|
||||
destinationCalendar: {
|
||||
name: "destinationCalendar",
|
||||
eventTypeId: 1,
|
||||
credentialId: 1,
|
||||
primaryEmail: "primaryEmail",
|
||||
integration: "google_calendar",
|
||||
externalId: "externalId",
|
||||
userId: null,
|
||||
id: 0,
|
||||
},
|
||||
} satisfies Awaited<ReturnType<typeof CalendarsService.prototype.getCalendars>>;
|
||||
}
|
||||
}
|
||||
15
calcom/apps/api/v2/test/mocks/mock-redis-service.ts
Normal file
15
calcom/apps/api/v2/test/mocks/mock-redis-service.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { RedisService } from "@/modules/redis/redis.service";
|
||||
import { Provider } from "@nestjs/common";
|
||||
|
||||
export const MockedRedisService = {
|
||||
provide: RedisService,
|
||||
useValue: {
|
||||
redis: {
|
||||
get: jest.fn(),
|
||||
hgetall: jest.fn(),
|
||||
set: jest.fn(),
|
||||
hmset: jest.fn(),
|
||||
expireat: jest.fn(),
|
||||
},
|
||||
},
|
||||
} as Provider;
|
||||
24
calcom/apps/api/v2/test/mocks/next-auth-mock.strategy.ts
Normal file
24
calcom/apps/api/v2/test/mocks/next-auth-mock.strategy.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { NextAuthPassportStrategy } from "@/lib/passport/strategies/types";
|
||||
import { UsersRepository } from "@/modules/users/users.repository";
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { PassportStrategy } from "@nestjs/passport";
|
||||
|
||||
@Injectable()
|
||||
export class NextAuthMockStrategy extends PassportStrategy(NextAuthPassportStrategy, "next-auth") {
|
||||
constructor(private readonly email: string, private readonly userRepository: UsersRepository) {
|
||||
super();
|
||||
}
|
||||
async authenticate() {
|
||||
try {
|
||||
const user = await this.userRepository.findByEmailWithProfile(this.email);
|
||||
if (!user) {
|
||||
throw new Error("User with the provided email not found");
|
||||
}
|
||||
|
||||
return this.success(user);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
if (error instanceof Error) return this.error(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user