Skip to content

Commit

Permalink
change utility function names
Browse files Browse the repository at this point in the history
  • Loading branch information
meetulr committed Oct 31, 2024
1 parent 9353e15 commit 0a40b7e
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 32 deletions.
8 changes: 4 additions & 4 deletions src/resolvers/UserTag/usersAssignedTo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import { MAXIMUM_FETCH_LIMIT } from "../../constants";
import { Types } from "mongoose";
import {
parseUserTagSortedBy,
parseUserTagUserWhere,
parseUserTagMemberWhere,
} from "../../utilities/userTagsPaginationUtils";
import { getUserTagUserGraphQLConnectionFilter } from "../../utilities/graphQLConnection";
import { getUserTagMemberGraphQLConnectionFilter } from "../../utilities/graphQLConnection";

/**
* Resolver function for the `usersAssignedTo` field of a `UserTag`.
Expand All @@ -41,7 +41,7 @@ export const usersAssignedTo: UserTagResolvers["usersAssignedTo"] = async (
parent,
args,
) => {
const parseWhereResult = parseUserTagUserWhere(args.where);
const parseWhereResult = parseUserTagMemberWhere(args.where);
const parseSortedByResult = parseUserTagSortedBy(args.sortedBy);

const parseGraphQLConnectionArgumentsResult =
Expand Down Expand Up @@ -69,7 +69,7 @@ export const usersAssignedTo: UserTagResolvers["usersAssignedTo"] = async (

const { parsedArgs } = parseGraphQLConnectionArgumentsResult;

const objectListFilter = getUserTagUserGraphQLConnectionFilter({
const objectListFilter = getUserTagMemberGraphQLConnectionFilter({
cursor: parsedArgs.cursor,
direction: parsedArgs.direction,
sortById: parsedArgs.sort.sortById,
Expand Down
10 changes: 5 additions & 5 deletions src/resolvers/UserTag/usersToAssignTo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import {
getCommonGraphQLConnectionSort,
parseGraphQLConnectionArgumentsWithWhere,
transformToDefaultGraphQLConnection,
getUserTagUserGraphQLConnectionFilter } from "../../utilities/graphQLConnection";
getUserTagMemberGraphQLConnectionFilter,
} from "../../utilities/graphQLConnection";

import { GraphQLError } from "graphql";
import { MAXIMUM_FETCH_LIMIT } from "../../constants";
import { Types } from "mongoose";
import { parseUserTagUserWhere } from "../../utilities/userTagsPaginationUtils";

import { parseUserTagMemberWhere } from "../../utilities/userTagsPaginationUtils";

/**
* Resolver function for the `usersToAssignTo` field of a `UserTag`.
Expand All @@ -40,7 +40,7 @@ export const usersToAssignTo: UserTagResolvers["usersToAssignTo"] = async (
parent,
args,
) => {
const parseWhereResult = parseUserTagUserWhere(args.where);
const parseWhereResult = parseUserTagMemberWhere(args.where);

const parseGraphQLConnectionArgumentsResult =
await parseGraphQLConnectionArgumentsWithWhere({
Expand All @@ -65,7 +65,7 @@ export const usersToAssignTo: UserTagResolvers["usersToAssignTo"] = async (

const { parsedArgs } = parseGraphQLConnectionArgumentsResult;

const objectListFilter = getUserTagUserGraphQLConnectionFilter({
const objectListFilter = getUserTagMemberGraphQLConnectionFilter({
cursor: parsedArgs.cursor,
direction: parsedArgs.direction,
sortById: "DESCENDING",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Types } from "mongoose";
import type { GraphQLConnectionTraversalDirection } from ".";
import type {
ParseSortedByResult,
ParseUserTagUserWhereResult,
ParseUserTagMemberWhereResult,
} from "../userTagsPaginationUtils";

/**
Expand Down Expand Up @@ -35,14 +35,14 @@ type GraphQLConnectionFilter =
/**
* This function is used to get an object containing filtering logic.
*/
export function getUserTagUserGraphQLConnectionFilter({
export function getUserTagMemberGraphQLConnectionFilter({
cursor,
direction,
sortById,
firstNameStartsWith,
lastNameStartsWith,
}: ParseSortedByResult &
ParseUserTagUserWhereResult & {
ParseUserTagMemberWhereResult & {
cursor: string | null;
direction: GraphQLConnectionTraversalDirection;
}): GraphQLConnectionFilter {
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/graphQLConnection/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ export * from "./parseGraphQLConnectionArgumentsWithWhere";
export * from "./transformToDefaultGraphQLConnection";
export * from "./getUserTagGraphQLConnectionFilter";
export * from "./getUserTagGraphQLConnectionSort";
export * from "./getUserTagUserGraphQLConnectionFilter";
export * from "./getUserTagMemberGraphQLConnectionFilter";
2 changes: 1 addition & 1 deletion src/utilities/userTagsPaginationUtils/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from "./parseUserTagSortedBy";
export * from "./parseUserTagWhere";
export * from "./parseUserTagUserWhere";
export * from "./parseUserTagMemberWhere";
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import type {
* function to parse the args.where for UserTag member assignment queries
*/

export type ParseUserTagUserWhereResult = {
export type ParseUserTagMemberWhereResult = {
firstNameStartsWith: string;
lastNameStartsWith: string;
};

export function parseUserTagUserWhere(
export function parseUserTagMemberWhere(
where: UserTagUsersAssignedToWhereInput | null | undefined,
): ParseGraphQLConnectionWhereResult<ParseUserTagUserWhereResult> {
): ParseGraphQLConnectionWhereResult<ParseUserTagMemberWhereResult> {
const errors: DefaultGraphQLArgumentError[] = [];

if (!where) {
Expand Down
12 changes: 6 additions & 6 deletions tests/utilities/graphqlConnection.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
getCommonGraphQLConnectionFilter,
getCommonGraphQLConnectionSort,
getUserTagGraphQLConnectionSort,
getUserTagUserGraphQLConnectionFilter,
getUserTagMemberGraphQLConnectionFilter,
getUserTagGraphQLConnectionFilter,
} from "../../src/utilities/graphQLConnection";
import { Types } from "mongoose";
Expand Down Expand Up @@ -715,12 +715,12 @@ describe("getUserTagGraphQLConnectionFilter function", () => {
});
});

describe("getUserTagUserGraphQLConnectionFilter function", () => {
describe("getUserTagMemberGraphQLConnectionFilter function", () => {
it(`when sort order is "ASCENDING" argument cursor is non-null and argument direction corresponds to backward`, async () => {
const cursor = new Types.ObjectId().toString();

expect(
getUserTagUserGraphQLConnectionFilter({
getUserTagMemberGraphQLConnectionFilter({
cursor,
direction: "BACKWARD",
sortById: "ASCENDING",
Expand All @@ -744,7 +744,7 @@ describe("getUserTagUserGraphQLConnectionFilter function", () => {
const cursor = new Types.ObjectId().toString();

expect(
getUserTagUserGraphQLConnectionFilter({
getUserTagMemberGraphQLConnectionFilter({
cursor,
direction: "FORWARD",
sortById: "ASCENDING",
Expand All @@ -768,7 +768,7 @@ describe("getUserTagUserGraphQLConnectionFilter function", () => {
const cursor = new Types.ObjectId().toString();

expect(
getUserTagUserGraphQLConnectionFilter({
getUserTagMemberGraphQLConnectionFilter({
cursor,
direction: "BACKWARD",
sortById: "DESCENDING",
Expand All @@ -792,7 +792,7 @@ describe("getUserTagUserGraphQLConnectionFilter function", () => {
const cursor = new Types.ObjectId().toString();

expect(
getUserTagUserGraphQLConnectionFilter({
getUserTagMemberGraphQLConnectionFilter({
cursor,
direction: "FORWARD",
sortById: "DESCENDING",
Expand Down
18 changes: 9 additions & 9 deletions tests/utilities/userTagsPagniationUtils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, it } from "vitest";
import {
parseUserTagSortedBy,
parseUserTagUserWhere,
parseUserTagMemberWhere,
parseUserTagWhere,
} from "../../src/utilities/userTagsPaginationUtils";
import type { SortedByOrder } from "../../src/types/generatedGraphQLTypes";
Expand Down Expand Up @@ -34,23 +34,23 @@ describe("parseUserTagWhere function", () => {
});
});

describe("parseUserTagUserWhere function", () => {
describe("parseUserTagMemberWhere function", () => {
it("returns the failure state if neither firstName nor lastName is provided", async () => {
const result = await parseUserTagUserWhere({});
const result = await parseUserTagMemberWhere({});

expect(result.isSuccessful).toEqual(false);
});

it("returns the failure state if firstName isn't a string", async () => {
const result = await parseUserTagUserWhere({
const result = await parseUserTagMemberWhere({
firstName: { starts_with: Math.random() as unknown as string },
});

expect(result.isSuccessful).toEqual(false);
});

it("returns the failure state if lastName isn't a string", async () => {
const result = await parseUserTagUserWhere({
const result = await parseUserTagMemberWhere({
firstName: { starts_with: "firstName" },
lastName: { starts_with: Math.random() as unknown as string },
});
Expand All @@ -59,29 +59,29 @@ describe("parseUserTagUserWhere function", () => {
});

it("returns the success state if where input is nullish", async () => {
const result = await parseUserTagUserWhere(undefined);
const result = await parseUserTagMemberWhere(undefined);

expect(result.isSuccessful).toEqual(true);
});

it("returns the success state if provided firstName is provided and lastName isn't", async () => {
const result = await parseUserTagUserWhere({
const result = await parseUserTagMemberWhere({
firstName: { starts_with: "firstName" },
});

expect(result.isSuccessful).toEqual(true);
});

it("returns the success state if provided lastName is provided and firstName isn't", async () => {
const result = await parseUserTagUserWhere({
const result = await parseUserTagMemberWhere({
lastName: { starts_with: "lastName" },
});

expect(result.isSuccessful).toEqual(true);
});

it("returns the success state if provided names are non-empty and valid strings", async () => {
const result = await parseUserTagUserWhere({
const result = await parseUserTagMemberWhere({
firstName: { starts_with: "firstName" },
lastName: { starts_with: "lastName" },
});
Expand Down

0 comments on commit 0a40b7e

Please sign in to comment.