diff --git a/README.md b/README.md index bdf939c79f..ddf41d33ec 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Core features include: `talawa` is based on the original `quito` code created by the [Palisadoes Foundation](http://www.palisadoes.org) as part of its annual Calico Challenge program. Calico provides paid summer internships for Jamaican university students to work on selected open source projects. They are mentored by software professionals and receive stipends based on the completion of predefined milestones. Calico was started in 2015. Visit [The Palisadoes Foundation's website](http://www.palisadoes.org/) for more details on its origin and activities. -## Table of Contents +## Table of Contents diff --git a/locales/en.json b/locales/en.json index 1769c40537..d989fa282c 100644 --- a/locales/en.json +++ b/locales/en.json @@ -29,6 +29,7 @@ "invalid.fileType": "Invalid file type", "invalid.refreshToken": "Invalid refresh token", "invalid.credentials": "Invalid credentials", + "invalid.timeoutRange": "Invalid timeout range", "registrant.alreadyExist": "Already registered for the event", "member.notFound": "Member not found", "registrant.alreadyUnregistered": "Already unregistered for the event", diff --git a/locales/fr.json b/locales/fr.json index 39fea9082c..4b299485c5 100644 --- a/locales/fr.json +++ b/locales/fr.json @@ -28,6 +28,7 @@ "invalid.fileType": "Type de fichier non valide", "invalid.refreshToken": "Jeton d'actualisation non valide", "invalid.credentials": "Informations d'identification non valides", + "invalid.timeoutRange": "Plage de temps d'attente non valide", "registrant.alreadyExist": "Déjà inscrit à l'événement", "member.notFound": "Membre introuvable", "registrant.alreadyUnregistered": "Déjà non inscrit à l'événement", diff --git a/locales/hi.json b/locales/hi.json index 74d3372fb0..b21fb5775b 100644 --- a/locales/hi.json +++ b/locales/hi.json @@ -29,6 +29,7 @@ "invalid.fileType": "अमान्य फ़ाइल प्रकार", "invalid.refreshToken": "अमान्य रीफ़्रेश टोकन", "invalid.credentials": "अवैध प्रत्यय पत्र", + "invalid.timeoutRange": "अमान्य टाइमआउट रेंज", "registrant.alreadyExist": "घटना के लिए पहले से पंजीकृत", "member.notFound": "सदस्य अनुपस्थित", "registrant.alreadyUnregistered": "घटना के लिए पहले से ही अपंजीकृत", diff --git a/locales/sp.json b/locales/sp.json index cec263813a..e468585977 100644 --- a/locales/sp.json +++ b/locales/sp.json @@ -28,6 +28,7 @@ "invalid.fileType": "Tipo de archivo no válido", "invalid.refreshToken": "Token de actualización no válido", "invalid.credentials": "Credenciales no válidas", + "invalid.timeoutRange": "Rango de tiempo de espera no válido", "registrant.alreadyExist": "Ya inscrito para el evento", "member.notFound": "Miembro no encontrado", "registrant.alreadyUnregistered": "Ya no está registrado para el evento", diff --git a/locales/zh.json b/locales/zh.json index 16453c5236..511a75784a 100644 --- a/locales/zh.json +++ b/locales/zh.json @@ -28,6 +28,7 @@ "invalid.fileType": "無效的文件類型", "invalid.refreshToken": "無效的刷新令牌", "invalid.credentials": "無效的憑據", + "invalid.timeoutRange": "无效的超时范围", "registrant.alreadyExist": "已经报名参加活动", "member.notFound": "未找到成员", "registrant.alreadyUnregistered": "已取消注册该活动", diff --git a/schema.graphql b/schema.graphql index c5fb18a0dd..76c86b291f 100644 --- a/schema.graphql +++ b/schema.graphql @@ -239,6 +239,7 @@ type Community { logoUrl: String name: String! socialMediaUrls: SocialMediaUrls + timeout: Int websiteLink: String } @@ -1192,6 +1193,7 @@ type Mutation { updateOrganization(data: UpdateOrganizationInput, file: String, id: ID!): Organization! updatePluginStatus(id: ID!, orgId: ID!): Plugin! updatePost(data: PostUpdateInput, id: ID!): Post! + updateSessionTimeout(timeout: Int!): Boolean! updateUserPassword(data: UpdateUserPasswordInput!): UserData! updateUserProfile(data: UpdateUserInput, file: String): User! updateUserRoleInOrganization(organizationId: ID!, role: String!, userId: ID!): Organization! diff --git a/src/constants.ts b/src/constants.ts index fab3f2b12d..dcb04c3a95 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -43,6 +43,13 @@ export const AGENDA_CATEGORY_NOT_FOUND_ERROR = Object.freeze({ PARAM: "agendaCategory", }); +export const APP_USER_PROFILE_NOT_FOUND_ERROR = Object.freeze({ + DESC: "appUserProfile not found", + CODE: "appUserProfile.notFound", + MESSAGE: "appUserProfile.notFound", + PARAM: "appUserProfile", +}); + export const BASE_RECURRING_EVENT_NOT_FOUND = Object.freeze({ DESC: "Base Recurring Event not found", CODE: "baseRecurringEvent.notFound", @@ -57,6 +64,13 @@ export const CHAT_NOT_FOUND_ERROR = Object.freeze({ PARAM: "chat", }); +export const COMMUNITY_NOT_FOUND_ERROR = Object.freeze({ + DESC: "Community not found", + CODE: "community.notFound", + MESSAGE: "community.notFound", + PARAM: "community", +}); + export const VENUE_ALREADY_EXISTS_ERROR = Object.freeze({ DESC: "Venue already exists", CODE: "venue.alreadyExists", @@ -144,6 +158,14 @@ export const FUND_NOT_FOUND_ERROR = Object.freeze({ export const INVALID_OTP = "Invalid OTP"; export const IN_PRODUCTION = process.env.NODE_ENV === "production"; + +export const INVALID_TIMEOUT_RANGE = Object.freeze({ + DESC: "Timeout should be in the range of 15 to 60 minutes.", + CODE: "invalid.timeoutRange", + MESSAGE: "invalid.timeoutRange", + PARAM: "timeout", +}); + export const MEMBER_NOT_FOUND_ERROR = Object.freeze({ DESC: "Member not found", CODE: "member.notFound", @@ -696,6 +718,9 @@ export const PRELOGIN_IMAGERY_FIELD_EMPTY = Object.freeze({ PARAM: "preLoginImagery.empty", }); +export const MINIMUM_TIMEOUT_MINUTES = 15; +export const MAXIMUM_TIMEOUT_MINUTES = 60; + export const MAXIMUM_FETCH_LIMIT = 100; export const MAXIMUM_IMAGE_SIZE_LIMIT_KB = 20000; diff --git a/src/models/Community.ts b/src/models/Community.ts index 329254aae7..2301ed2e2a 100644 --- a/src/models/Community.ts +++ b/src/models/Community.ts @@ -19,6 +19,7 @@ export interface InterfaceCommunity { slack: string; reddit: string; }; // Object containing various social media URLs for the community. + timeout: number; } /** @@ -35,6 +36,9 @@ export interface InterfaceCommunity { * @param youTube - YouTube URL. * @param slack - Slack URL. * @param reddit - Reddit URL. + * @param websiteLink - Community website URL. + * @param name - Community name. + * @param timeout - Timeout duration in minutes (default is 30 minutes). */ const communitySchema = new Schema({ name: { @@ -73,6 +77,12 @@ const communitySchema = new Schema({ type: String, }, }, + timeout: { + type: Number, + default: 30, + min: [15, "Timeout should be at least 15 minutes."], + max: [60, "Timeout should not exceed 60 minutes."], + }, }); /** diff --git a/src/resolvers/Mutation/index.ts b/src/resolvers/Mutation/index.ts index 390dea99dd..353670e350 100644 --- a/src/resolvers/Mutation/index.ts +++ b/src/resolvers/Mutation/index.ts @@ -114,6 +114,7 @@ import { updateLanguage } from "./updateLanguage"; import { updateOrganization } from "./updateOrganization"; import { updatePluginStatus } from "./updatePluginStatus"; import { updatePost } from "./updatePost"; +import { updateSessionTimeout } from "./updateSessionTimeout"; import { updateUserPassword } from "./updateUserPassword"; import { updateUserProfile } from "./updateUserProfile"; import { updateUserRoleInOrganization } from "./updateUserRoleInOrganization"; @@ -236,6 +237,7 @@ export const Mutation: MutationResolvers = { updateLanguage, updateOrganization, updatePluginStatus, + updateSessionTimeout, updateUserProfile, updateUserPassword, updateUserTag, diff --git a/src/resolvers/Mutation/login.ts b/src/resolvers/Mutation/login.ts index cb825c961d..22a7d9ecc3 100644 --- a/src/resolvers/Mutation/login.ts +++ b/src/resolvers/Mutation/login.ts @@ -14,7 +14,7 @@ import { createRefreshToken, } from "../../utilities"; /** - * This function enables login. + * This function enables login. (note: only works when using the last resort SuperAdmin credentials) * @param _parent - parent of current request * @param args - payload provided with the request * @remarks The following checks are done: @@ -55,29 +55,43 @@ export const login: MutationResolvers["login"] = async (_parent, args) => { } let appUserProfile: InterfaceAppUserProfile | null = await AppUserProfile.findOne({ - userId: user._id.toString(), + userId: user._id, appLanguageCode: "en", tokenVersion: 0, }).lean(); if (!appUserProfile) { appUserProfile = await AppUserProfile.create({ - userId: user._id.toString(), + userId: user._id, appLanguageCode: "en", tokenVersion: 0, isSuperAdmin: false, }); - await User.updateOne( + + user = await User.findOneAndUpdate( { - _id: user._id.toString(), + _id: user._id, }, { - appUserProfileId: appUserProfile?._id?.toString(), + appUserProfileId: appUserProfile?._id, }, + { new: true, lean: true }, ); + + // user = await User.findOne({ + // email: args.data.email.toLowerCase(), + // }).lean(); + + if (!user) { + throw new errors.NotFoundError( + requestContext.translate(USER_NOT_FOUND_ERROR.MESSAGE), + USER_NOT_FOUND_ERROR.CODE, + USER_NOT_FOUND_ERROR.PARAM, + ); + } } - const accessToken = createAccessToken( + const accessToken = await createAccessToken( user, appUserProfile as InterfaceAppUserProfile, ); @@ -104,7 +118,7 @@ export const login: MutationResolvers["login"] = async (_parent, args) => { // ); await AppUserProfile.findOneAndUpdate( { - user: user._id, + _id: user.appUserProfileId, }, { isSuperAdmin: true, diff --git a/src/resolvers/Mutation/updateSessionTimeout.ts b/src/resolvers/Mutation/updateSessionTimeout.ts new file mode 100644 index 0000000000..cf3a840011 --- /dev/null +++ b/src/resolvers/Mutation/updateSessionTimeout.ts @@ -0,0 +1,88 @@ +import type { InterfaceAppUserProfile } from "../../models"; +import { User, AppUserProfile } from "../../models"; +import { + COMMUNITY_NOT_FOUND_ERROR, + INVALID_TIMEOUT_RANGE, + USER_NOT_FOUND_ERROR, + APP_USER_PROFILE_NOT_FOUND_ERROR, + MINIMUM_TIMEOUT_MINUTES, + MAXIMUM_TIMEOUT_MINUTES, +} from "../../constants"; +import type { MutationResolvers } from "../../types/generatedGraphQLTypes"; +import { errors, requestContext } from "../../libraries"; +import { superAdminCheck } from "../../utilities"; +import { Community } from "../../models/Community"; + +/** + * This function updates the session timeout and can only be performed by superadmin users. + * @param _parent - parent of the current request + * @param args - payload provided with the request, including organizationId and timeout + * @param context - context of the entire application, containing user information + * @returns - A message true if the organization timeout is updated successfully + * @throws - NotFoundError: If the user, appuserprofile or organization is not found + * @throws - ValidationError: If the user is not an admin or superadmin, or if the timeout is outside the valid range + * @throws - InternalServerError: If there is an error updating the organization timeout + */ + +export const updateSessionTimeout: MutationResolvers["updateSessionTimeout"] = + async (_parent, args, context) => { + const userId = context.userId; + const user = await User.findById(userId).lean(); + + if (!user) { + throw new errors.NotFoundError( + requestContext.translate(USER_NOT_FOUND_ERROR.MESSAGE), + USER_NOT_FOUND_ERROR.CODE, + USER_NOT_FOUND_ERROR.PARAM, + ); + } + + //const appuserprofile: InterfaceAppUserProfile | null = await AppUserProfile.findOne({userId: userId}).lean(); + const appuserprofile: InterfaceAppUserProfile | null = + await AppUserProfile.findById(user.appUserProfileId).lean(); //more appropriate since it shows the link between the user and the userprofile + + if (!appuserprofile) { + throw new errors.NotFoundError( + requestContext.translate(APP_USER_PROFILE_NOT_FOUND_ERROR.MESSAGE), + APP_USER_PROFILE_NOT_FOUND_ERROR.CODE, + APP_USER_PROFILE_NOT_FOUND_ERROR.PARAM, + ); + } + + superAdminCheck(appuserprofile); + + const community = await Community.findOne().lean(); + + if (!community) { + throw new errors.NotFoundError( + requestContext.translate(COMMUNITY_NOT_FOUND_ERROR.MESSAGE), + COMMUNITY_NOT_FOUND_ERROR.CODE, + COMMUNITY_NOT_FOUND_ERROR.PARAM, + ); + } + + if ( + args.timeout < MINIMUM_TIMEOUT_MINUTES || + args.timeout > MAXIMUM_TIMEOUT_MINUTES || + args.timeout % 5 !== 0 + ) { + throw new errors.ValidationError( + [ + { + message: requestContext.translate(INVALID_TIMEOUT_RANGE.MESSAGE), + code: INVALID_TIMEOUT_RANGE.CODE, + param: INVALID_TIMEOUT_RANGE.PARAM, + }, + ], + INVALID_TIMEOUT_RANGE.MESSAGE, + ); + } + + await Community.findByIdAndUpdate( + community._id, + { timeout: args.timeout }, + { new: true }, + ); + + return true; + }; diff --git a/src/setup/superAdmin.ts b/src/setup/superAdmin.ts index aeef732b1f..2d62240aba 100644 --- a/src/setup/superAdmin.ts +++ b/src/setup/superAdmin.ts @@ -17,7 +17,7 @@ export async function askForSuperAdminEmail(): Promise { name: "email", message: "Enter the email which you wish to assign as the Super Admin of last resort :", - validate: (input: string) => + validate: (input: string): boolean | string => isValidEmail(input) || "Invalid email. Please try again.", }, ]); diff --git a/src/typeDefs/mutations.ts b/src/typeDefs/mutations.ts index bca74770e5..6bb217447f 100644 --- a/src/typeDefs/mutations.ts +++ b/src/typeDefs/mutations.ts @@ -337,6 +337,8 @@ export const mutations = gql` updatePluginStatus(id: ID!, orgId: ID!): Plugin! + updateSessionTimeout(timeout: Int!): Boolean! @auth + updateUserTag(input: UpdateUserTagInput!): UserTag @auth updateUserProfile(data: UpdateUserInput, file: String): User! @auth diff --git a/src/typeDefs/types.ts b/src/typeDefs/types.ts index 8faf1a6521..c0be08e183 100644 --- a/src/typeDefs/types.ts +++ b/src/typeDefs/types.ts @@ -130,6 +130,7 @@ export const types = gql` logoUrl: String websiteLink: String socialMediaUrls: SocialMediaUrls + timeout: Int } type CreateAdminPayload { user: AppUserProfile diff --git a/src/types/generatedGraphQLTypes.ts b/src/types/generatedGraphQLTypes.ts index 0f4178071b..2e83523f49 100644 --- a/src/types/generatedGraphQLTypes.ts +++ b/src/types/generatedGraphQLTypes.ts @@ -318,6 +318,7 @@ export type Community = { logoUrl?: Maybe; name: Scalars['String']['output']; socialMediaUrls?: Maybe; + timeout?: Maybe; websiteLink?: Maybe; }; @@ -1283,6 +1284,7 @@ export type Mutation = { updateOrganization: Organization; updatePluginStatus: Plugin; updatePost: Post; + updateSessionTimeout: Scalars['Boolean']['output']; updateUserPassword: UserData; updateUserProfile: User; updateUserRoleInOrganization: Organization; @@ -1918,6 +1920,11 @@ export type MutationUpdatePostArgs = { }; +export type MutationUpdateSessionTimeoutArgs = { + timeout: Scalars['Int']['input']; +}; + + export type MutationUpdateUserPasswordArgs = { data: UpdateUserPasswordInput; }; @@ -3911,6 +3918,7 @@ export type CommunityResolvers, ParentType, ContextType>; name?: Resolver; socialMediaUrls?: Resolver, ParentType, ContextType>; + timeout?: Resolver, ParentType, ContextType>; websiteLink?: Resolver, ParentType, ContextType>; __isTypeOf?: IsTypeOfResolverFn; }; @@ -4428,6 +4436,7 @@ export type MutationResolvers>; updatePluginStatus?: Resolver>; updatePost?: Resolver>; + updateSessionTimeout?: Resolver>; updateUserPassword?: Resolver>; updateUserProfile?: Resolver>; updateUserRoleInOrganization?: Resolver>; diff --git a/src/utilities/auth.ts b/src/utilities/auth.ts index 84389ac1f4..9df4712c76 100644 --- a/src/utilities/auth.ts +++ b/src/utilities/auth.ts @@ -1,7 +1,7 @@ import jwt from "jsonwebtoken"; import { ACCESS_TOKEN_SECRET, REFRESH_TOKEN_SECRET } from "../constants"; import type { InterfaceAppUserProfile, InterfaceUser } from "../models"; -import { User } from "../models"; +import { Community, User } from "../models"; /** * Interface representing the payload of a JWT token. @@ -22,10 +22,17 @@ export interface InterfaceJwtTokenPayload { * @param appUserProfile - Application user profile data * @returns JSON Web Token string payload */ -export const createAccessToken = ( +export const createAccessToken = async ( user: InterfaceUser, appUserProfile: InterfaceAppUserProfile, -): string => { +): Promise => { + let timeout = 30; //in minutes + const community = await Community.findOne().lean(); + + if (community) { + timeout = community.timeout; + } + return jwt.sign( { tokenVersion: appUserProfile.tokenVersion, @@ -33,6 +40,7 @@ export const createAccessToken = ( firstName: user.firstName, lastName: user.lastName, email: user.email, + timeout: timeout, }, ACCESS_TOKEN_SECRET as string, { diff --git a/tests/resolvers/Mutation/UpdateSessionTimeout.spec.ts b/tests/resolvers/Mutation/UpdateSessionTimeout.spec.ts new file mode 100644 index 0000000000..ab3aead5bb --- /dev/null +++ b/tests/resolvers/Mutation/UpdateSessionTimeout.spec.ts @@ -0,0 +1,232 @@ +import "dotenv/config"; +import type mongoose from "mongoose"; +import { Types } from "mongoose"; + +import { User, AppUserProfile, Community } from "../../../src/models"; +import type { MutationUpdateSessionTimeoutArgs } from "../../../src/types/generatedGraphQLTypes"; +import { connect, disconnect } from "../../helpers/db"; + +import { nanoid } from "nanoid"; +import { + afterAll, + afterEach, + beforeAll, + beforeEach, + describe, + expect, + it, + vi, +} from "vitest"; +import { + COMMUNITY_NOT_FOUND_ERROR, + INVALID_TIMEOUT_RANGE, + USER_NOT_FOUND_ERROR, + APP_USER_PROFILE_NOT_FOUND_ERROR, + USER_NOT_AUTHORIZED_SUPERADMIN, +} from "../../../src/constants"; +import { updateSessionTimeout as updateSessionTimeoutResolver } from "../../../src/resolvers/Mutation/updateSessionTimeout"; +import type { + TestAppUserProfileType, + TestUserType, +} from "../../helpers/userAndOrg"; + +import { requestContext } from "../../../src/libraries"; + +import bcrypt from "bcryptjs"; +let MONGOOSE_INSTANCE: typeof mongoose; +let testUser: TestUserType; +let testAppUserProfile: TestAppUserProfileType; + +vi.mock("../../utilities/uploadEncodedImage", () => ({ + uploadEncodedImage: vi.fn(), +})); + +beforeAll(async () => { + MONGOOSE_INSTANCE = await connect(); +}); + +afterAll(async () => { + await disconnect(MONGOOSE_INSTANCE); +}); + +beforeEach(async () => { + const hashedPassword = await bcrypt.hash("password", 12); + + testUser = await User.create({ + email: `email${nanoid().toLowerCase()}@gmail.com`, + password: hashedPassword, + firstName: "firstName", + lastName: "lastName", + }); + + testAppUserProfile = await AppUserProfile.create({ + userId: testUser._id, + appLanguageCode: "en", + tokenVersion: 0, + isSuperAdmin: true, + }); + + await User.updateOne( + { + _id: testUser._id.toString(), + }, + { + appUserProfileId: testAppUserProfile?._id?.toString(), + }, + ); + + await Community.create({ + name: "test community", + timeout: 25, + }); +}); + +afterEach(() => { + vi.restoreAllMocks(); + vi.doUnmock("../../../src/constants"); + vi.resetModules(); +}); + +describe("resolvers -> Mutation -> updateSessionTimeout", () => { + it("throws NotFoundError if community does not exist", async () => { + const spy = vi + .spyOn(requestContext, "translate") + .mockImplementationOnce((message) => `Translated ${message}`); + + const args: MutationUpdateSessionTimeoutArgs = { + timeout: 15, + }; + + const context = { + userId: testUser?._id, + }; + + await Community.deleteMany({}); + + try { + await updateSessionTimeoutResolver?.({}, args, context); + } catch (error: unknown) { + expect(spy).toHaveBeenCalledWith(COMMUNITY_NOT_FOUND_ERROR.MESSAGE); + expect((error as Error).message).toEqual( + `Translated ${COMMUNITY_NOT_FOUND_ERROR.MESSAGE}`, + ); + } + }); + + it("throws NotFoundError if user does not exist", async () => { + const spy = vi + .spyOn(requestContext, "translate") + .mockImplementationOnce((message) => `Translated ${message}`); + + try { + const args: MutationUpdateSessionTimeoutArgs = { + timeout: 15, + }; + + const context = { + userId: new Types.ObjectId().toString(), + }; + + await updateSessionTimeoutResolver?.({}, args, context); + } catch (error: unknown) { + expect(spy).toHaveBeenCalledWith(USER_NOT_FOUND_ERROR.MESSAGE); + expect((error as Error).message).toEqual( + `Translated ${USER_NOT_FOUND_ERROR.MESSAGE}`, + ); + } + }); + + it("throws NotFoundError if appUserProfile does not exist", async () => { + const spy = vi + .spyOn(requestContext, "translate") + .mockImplementationOnce((message) => `Translated ${message}`); + + const args: MutationUpdateSessionTimeoutArgs = { + timeout: 15, + }; + + const context = { + userId: testUser?._id, + }; + + await AppUserProfile.deleteOne({ userId: testUser?._id }); + + try { + await updateSessionTimeoutResolver?.({}, args, context); + } catch (error: unknown) { + expect(spy).toHaveBeenCalledWith( + APP_USER_PROFILE_NOT_FOUND_ERROR.MESSAGE, + ); + expect((error as Error).message).toEqual( + `Translated ${APP_USER_PROFILE_NOT_FOUND_ERROR.MESSAGE}`, + ); + } + }); + + it("throws ValidationError if timeout is out of range", async () => { + const spy = vi + .spyOn(requestContext, "translate") + .mockImplementation((message) => message); + + const args: MutationUpdateSessionTimeoutArgs = { + timeout: 3, + }; + + const context = { + userId: testUser?._id, + }; + + try { + await updateSessionTimeoutResolver?.({}, args, context); + } catch (error: unknown) { + expect(spy).toHaveBeenCalledWith(INVALID_TIMEOUT_RANGE.MESSAGE); + expect((error as Error).message).toEqual(INVALID_TIMEOUT_RANGE.MESSAGE); + } + }); + + it("throws UnauthorizedError if superAdmin is false", async () => { + const spy = vi + .spyOn(requestContext, "translate") + .mockImplementation((message) => message); + + const args: MutationUpdateSessionTimeoutArgs = { + timeout: 15, + }; + + const context = { + userId: testUser?._id, + }; + + AppUserProfile.findByIdAndUpdate( + { + _id: testUser?.appUserProfileId, + }, + { + isSuperAdmin: false, + }, + ); + + try { + await updateSessionTimeoutResolver?.({}, args, context); + } catch (error: unknown) { + expect(spy).toHaveBeenCalledWith(USER_NOT_AUTHORIZED_SUPERADMIN.MESSAGE); + expect((error as Error).message).toEqual( + USER_NOT_AUTHORIZED_SUPERADMIN.MESSAGE, + ); + } + }); + + it("updates session timeout successfully", async () => { + const args: MutationUpdateSessionTimeoutArgs = { + timeout: 15, + }; + + const context = { + userId: testUser?._id, + }; + + const result = await updateSessionTimeoutResolver?.({}, args, context); + + expect(result).toEqual(true); + }); +}); diff --git a/tests/utilities/auth.spec.ts b/tests/utilities/auth.spec.ts index b3c4d84a47..b00263e238 100644 --- a/tests/utilities/auth.spec.ts +++ b/tests/utilities/auth.spec.ts @@ -38,7 +38,7 @@ afterAll(async () => { describe("createAccessToken", () => { it("should create a JWT token with the correct payload", async () => { - const token = createAccessToken( + const token = await createAccessToken( user ? user.toObject() : ({} as InterfaceUser), appUserProfile ? appUserProfile.toObject()