Skip to content

Commit

Permalink
does not need args.id
Browse files Browse the repository at this point in the history
  • Loading branch information
git-init-priyanshu committed Mar 15, 2024
1 parent c47a921 commit 0991f5c
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 53 deletions.
18 changes: 9 additions & 9 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,7 @@ type Mutation {
removeUserFromUserFamily(familyId: ID!, userId: ID!): UserFamily!
removeUserImage: User!
removeUserTag(id: ID!): UserTag
resetCommunity(id: ID!): Boolean!
resetCommunity: Boolean!
revokeRefreshTokenForUser: Boolean!
saveFcmToken(token: String): Boolean!
sendMembershipRequest(organizationId: ID!): MembershipRequest!
Expand Down Expand Up @@ -1407,14 +1407,14 @@ type SocialMediaUrls {
}

input SocialMediaUrlsInput {
facebook: String!
gitHub: String!
instagram: String!
linkedIn: String!
reddit: String!
slack: String!
twitter: String!
youTube: String!
facebook: String
gitHub: String
instagram: String
linkedIn: String
reddit: String
slack: String
twitter: String
youTube: String
}

"""
Expand Down
4 changes: 2 additions & 2 deletions src/resolvers/Mutation/resetCommunity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { superAdminCheck } from "../../utilities";
*/
export const resetCommunity: MutationResolvers["resetCommunity"] = async (
_parent,
args,
_args,
context,
) => {
const user = await User.findById(context.userId);
Expand All @@ -29,7 +29,7 @@ export const resetCommunity: MutationResolvers["resetCommunity"] = async (

superAdminCheck(user);

await Community.deleteOne({ _id: args.id });
await Community.deleteMany();

return true;
};
16 changes: 8 additions & 8 deletions src/typeDefs/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,14 +344,14 @@ export const inputs = gql`
}
input SocialMediaUrlsInput {
facebook: String!
gitHub: String!
instagram: String!
linkedIn: String!
reddit: String!
slack: String!
twitter: String!
youTube: String!
facebook: String
gitHub: String
instagram: String
linkedIn: String
reddit: String
slack: String
twitter: String
youTube: String
}
input ToggleUserTagAssignInput {
Expand Down
2 changes: 1 addition & 1 deletion src/typeDefs/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ export const mutations = gql`
removeUserImage: User! @auth
resetCommunity(id: ID!): Boolean! @auth @role(requires: SUPERADMIN)
resetCommunity: Boolean! @auth @role(requires: SUPERADMIN)
revokeRefreshTokenForUser: Boolean! @auth
Expand Down
23 changes: 9 additions & 14 deletions src/types/generatedGraphQLTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1630,11 +1630,6 @@ export type MutationRemoveUserTagArgs = {
};


export type MutationResetCommunityArgs = {
id: Scalars['ID']['input'];
};


export type MutationSaveFcmTokenArgs = {
token?: InputMaybe<Scalars['String']['input']>;
};
Expand Down Expand Up @@ -2406,14 +2401,14 @@ export type SocialMediaUrls = {
};

export type SocialMediaUrlsInput = {
facebook: Scalars['String']['input'];
gitHub: Scalars['String']['input'];
instagram: Scalars['String']['input'];
linkedIn: Scalars['String']['input'];
reddit: Scalars['String']['input'];
slack: Scalars['String']['input'];
twitter: Scalars['String']['input'];
youTube: Scalars['String']['input'];
facebook?: InputMaybe<Scalars['String']['input']>;
gitHub?: InputMaybe<Scalars['String']['input']>;
instagram?: InputMaybe<Scalars['String']['input']>;
linkedIn?: InputMaybe<Scalars['String']['input']>;
reddit?: InputMaybe<Scalars['String']['input']>;
slack?: InputMaybe<Scalars['String']['input']>;
twitter?: InputMaybe<Scalars['String']['input']>;
youTube?: InputMaybe<Scalars['String']['input']>;
};

/**
Expand Down Expand Up @@ -3915,7 +3910,7 @@ export type MutationResolvers<ContextType = any, ParentType extends ResolversPar
removeUserFromUserFamily?: Resolver<ResolversTypes['UserFamily'], ParentType, ContextType, RequireFields<MutationRemoveUserFromUserFamilyArgs, 'familyId' | 'userId'>>;
removeUserImage?: Resolver<ResolversTypes['User'], ParentType, ContextType>;
removeUserTag?: Resolver<Maybe<ResolversTypes['UserTag']>, ParentType, ContextType, RequireFields<MutationRemoveUserTagArgs, 'id'>>;
resetCommunity?: Resolver<ResolversTypes['Boolean'], ParentType, ContextType, RequireFields<MutationResetCommunityArgs, 'id'>>;
resetCommunity?: Resolver<ResolversTypes['Boolean'], ParentType, ContextType>;
revokeRefreshTokenForUser?: Resolver<ResolversTypes['Boolean'], ParentType, ContextType>;
saveFcmToken?: Resolver<ResolversTypes['Boolean'], ParentType, ContextType, Partial<MutationSaveFcmTokenArgs>>;
sendMembershipRequest?: Resolver<ResolversTypes['MembershipRequest'], ParentType, ContextType, RequireFields<MutationSendMembershipRequestArgs, 'organizationId'>>;
Expand Down
22 changes: 3 additions & 19 deletions tests/resolvers/Mutation/resetCommunity.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import "dotenv/config";
import type mongoose from "mongoose";
import { Types } from "mongoose";
import type { MutationResetCommunityArgs } from "../../../src/types/generatedGraphQLTypes";
import { connect, disconnect } from "../../helpers/db";
import {
beforeAll,
Expand All @@ -13,9 +12,7 @@ import {
expect,
} from "vitest";
import type { TestUserType } from "../../helpers/user";
import type { TestCommunityType } from "../../helpers/community";
import { createTestUserWithUserTypeFunc } from "../../helpers/user";
import { createTestCommunityFunc } from "../../helpers/community";
import {
USER_NOT_AUTHORIZED_SUPERADMIN,
USER_NOT_FOUND_ERROR,
Expand All @@ -25,13 +22,11 @@ import { Community } from "../../../src/models";
let MONGOOSE_INSTANCE: typeof mongoose;
let testUser1: TestUserType;
let testUser2: TestUserType;
let testCommunity: TestCommunityType;

beforeAll(async () => {
MONGOOSE_INSTANCE = await connect();
testUser1 = await createTestUserWithUserTypeFunc("SUPERADMIN");
testUser2 = await createTestUserWithUserTypeFunc("USER");
testCommunity = await createTestCommunityFunc();
});

afterAll(async () => {
Expand All @@ -51,17 +46,13 @@ describe("resolvers -> Mutation -> resetCommunity", () => {
.mockImplementation((message) => `Translated ${message}`);

try {
const args: MutationResetCommunityArgs = {
id: testCommunity?._id.toString() as string,
};

const context = { userId: Types.ObjectId().toString() };

const { resetCommunity: resetCommunityResolver } = await import(
"../../../src/resolvers/Mutation/resetCommunity"
);

await resetCommunityResolver?.({}, args, context);
await resetCommunityResolver?.({}, {}, context);
} catch (error: unknown) {
if (error instanceof Error) {
expect(spy).toHaveBeenCalledWith(USER_NOT_FOUND_ERROR.MESSAGE);
Expand All @@ -78,10 +69,6 @@ describe("resolvers -> Mutation -> resetCommunity", () => {
.spyOn(requestContext, "translate")
.mockImplementation((message) => `Translated ${message}`);

const args: MutationResetCommunityArgs = {
id: testCommunity?._id.toString() as string,
};

const context = {
userId: testUser2?._id,
};
Expand All @@ -91,7 +78,7 @@ describe("resolvers -> Mutation -> resetCommunity", () => {
"../../../src/resolvers/Mutation/resetCommunity"
);

await resetCommunityResolver?.({}, args, context);
await resetCommunityResolver?.({}, {}, context);
} catch (error: unknown) {
expect(spy).toHaveBeenCalledWith(USER_NOT_AUTHORIZED_SUPERADMIN.MESSAGE);
expect((error as Error).message).toEqual(
Expand All @@ -101,9 +88,6 @@ describe("resolvers -> Mutation -> resetCommunity", () => {
});

it(`deletes the previous data and returns true`, async () => {
const args: MutationResetCommunityArgs = {
id: testCommunity?._id.toString() as string,
};
const context = {
userId: testUser1?._id,
};
Expand All @@ -112,7 +96,7 @@ describe("resolvers -> Mutation -> resetCommunity", () => {
"../../../src/resolvers/Mutation/resetCommunity"
);

await resetCommunityResolver?.({}, args, context);
await resetCommunityResolver?.({}, {}, context);

expect(await Community.findOne()).toBe(null);
});
Expand Down

0 comments on commit 0991f5c

Please sign in to comment.