Skip to content

Commit

Permalink
move userTags pagination utils
Browse files Browse the repository at this point in the history
  • Loading branch information
meetulr committed Nov 2, 2024
1 parent edb525d commit f60d605
Show file tree
Hide file tree
Showing 12 changed files with 366 additions and 364 deletions.
4 changes: 2 additions & 2 deletions src/resolvers/Organization/userTags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import type { OrganizationResolvers } from "../../types/generatedGraphQLTypes";
import type { InterfaceOrganizationTagUser } from "../../models";
import { OrganizationTagUser } from "../../models";
import {
getUserTagGraphQLConnectionFilter,
getUserTagGraphQLConnectionSort,
parseGraphQLConnectionArgumentsWithSortedByAndWhere,
transformToDefaultGraphQLConnection,
type DefaultGraphQLArgumentError,
Expand All @@ -14,6 +12,8 @@ import { GraphQLError } from "graphql";
import { MAXIMUM_FETCH_LIMIT } from "../../constants";
import type { Types } from "mongoose";
import {
getUserTagGraphQLConnectionFilter,
getUserTagGraphQLConnectionSort,
parseUserTagSortedBy,
parseUserTagWhere,
} from "../../utilities/userTagsPaginationUtils";
Expand Down
4 changes: 2 additions & 2 deletions src/resolvers/UserTag/childTags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import type { UserTagResolvers } from "../../types/generatedGraphQLTypes";
import type { InterfaceOrganizationTagUser } from "../../models";
import { OrganizationTagUser } from "../../models";
import {
getUserTagGraphQLConnectionFilter,
getUserTagGraphQLConnectionSort,
parseGraphQLConnectionArgumentsWithSortedByAndWhere,
transformToDefaultGraphQLConnection,
type DefaultGraphQLArgumentError,
Expand All @@ -14,6 +12,8 @@ import { GraphQLError } from "graphql";
import { MAXIMUM_FETCH_LIMIT } from "../../constants";
import type { Types } from "mongoose";
import {
getUserTagGraphQLConnectionFilter,
getUserTagGraphQLConnectionSort,
parseUserTagSortedBy,
parseUserTagWhere,
} from "../../utilities/userTagsPaginationUtils";
Expand Down
4 changes: 2 additions & 2 deletions src/resolvers/UserTag/usersAssignedTo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
type DefaultGraphQLArgumentError,
type ParseGraphQLConnectionCursorArguments,
type ParseGraphQLConnectionCursorResult,
getUserTagGraphQLConnectionSort,
parseGraphQLConnectionArgumentsWithSortedByAndWhere,
transformToDefaultGraphQLConnection,
} from "../../utilities/graphQLConnection";
Expand All @@ -15,8 +14,9 @@ import { Types } from "mongoose";
import {
parseUserTagSortedBy,
parseUserTagMemberWhere,
getUserTagMemberGraphQLConnectionFilter,
getUserTagGraphQLConnectionSort,
} from "../../utilities/userTagsPaginationUtils";
import { getUserTagMemberGraphQLConnectionFilter } from "../../utilities/graphQLConnection";

/**
* Resolver function for the `usersAssignedTo` field of a `UserTag`.
Expand Down
6 changes: 4 additions & 2 deletions src/resolvers/UserTag/usersToAssignTo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import {
getCommonGraphQLConnectionSort,
parseGraphQLConnectionArgumentsWithWhere,
transformToDefaultGraphQLConnection,
getUserTagMemberGraphQLConnectionFilter,
} from "../../utilities/graphQLConnection";

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

/**
* Resolver function for the `usersToAssignTo` field of a `UserTag`.
Expand Down
3 changes: 0 additions & 3 deletions src/utilities/graphQLConnection/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,3 @@ export * from "./parseGraphQLConnectionArgumentsWithSortedBy";
export * from "./parseGraphQLConnectionArgumentsWithSortedByAndWhere";
export * from "./parseGraphQLConnectionArgumentsWithWhere";
export * from "./transformToDefaultGraphQLConnection";
export * from "./getUserTagGraphQLConnectionFilter";
export * from "./getUserTagGraphQLConnectionSort";
export * from "./getUserTagMemberGraphQLConnectionFilter";
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { GraphQLConnectionTraversalDirection } from ".";
import type { GraphQLConnectionTraversalDirection } from "../graphQLConnection";
import type {
ParseSortedByResult,
ParseUserTagWhereResult,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { GraphQLConnectionTraversalDirection } from ".";
import type { GraphQLConnectionTraversalDirection } from "../graphQLConnection";
import type { ParseSortedByResult } from "../userTagsPaginationUtils";

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Types } from "mongoose";
import type { GraphQLConnectionTraversalDirection } from ".";
import type { GraphQLConnectionTraversalDirection } from "../graphQLConnection";
import type {
ParseSortedByResult,
ParseUserTagMemberWhereResult,
Expand Down
3 changes: 3 additions & 0 deletions src/utilities/userTagsPaginationUtils/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
export * from "./parseUserTagSortedBy";
export * from "./parseUserTagWhere";
export * from "./parseUserTagMemberWhere";
export * from "./getUserTagGraphQLConnectionSort";
export * from "./getUserTagGraphQLConnectionFilter";
export * from "./getUserTagMemberGraphQLConnectionFilter";
230 changes: 0 additions & 230 deletions tests/utilities/graphqlConnection.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ import {
parseGraphQLConnectionArgumentsWithSortedByAndWhere,
getCommonGraphQLConnectionFilter,
getCommonGraphQLConnectionSort,
getUserTagGraphQLConnectionSort,
getUserTagMemberGraphQLConnectionFilter,
getUserTagGraphQLConnectionFilter,
} from "../../src/utilities/graphQLConnection";
import { Types } from "mongoose";

describe("isNotNullish function", () => {
it("returns false when argument value is undefined", () => {
Expand Down Expand Up @@ -633,232 +629,6 @@ describe("getCommonGraphQLConnectionSort function", () => {
});
});

describe("getUserTagGraphQLConnectionFilter function", () => {
it(`when sort order is "ASCENDING" argument cursor is non-null and argument direction corresponds to backward`, async () => {
const cursor = "cursor";

expect(
getUserTagGraphQLConnectionFilter({
cursor,
direction: "BACKWARD",
sortById: "ASCENDING",
nameStartsWith: "userName",
}),
).toEqual({
_id: {
$lt: cursor,
},
name: {
$regex: /^userName/i,
},
});
});

it(`when sort order is "ASCENDING" argument cursor is non-null and argument direction corresponds to forward`, async () => {
const cursor = "cursor";

expect(
getUserTagGraphQLConnectionFilter({
cursor,
direction: "FORWARD",
sortById: "ASCENDING",
nameStartsWith: "userName",
}),
).toEqual({
_id: {
$gt: cursor,
},
name: {
$regex: /^userName/i,
},
});
});

it(`when sort order is "DESCENDING" argument cursor is non-null and argument direction corresponds to backward`, async () => {
const cursor = "cursor";

expect(
getUserTagGraphQLConnectionFilter({
cursor,
direction: "BACKWARD",
sortById: "DESCENDING",
nameStartsWith: "userName",
}),
).toEqual({
_id: {
$gt: cursor,
},
name: {
$regex: /^userName/i,
},
});
});

it(`when sort order is "DESCENDING" argument cursor is non-null and argument direction corresponds to forward`, async () => {
const cursor = "cursor";

expect(
getUserTagGraphQLConnectionFilter({
cursor,
direction: "FORWARD",
sortById: "DESCENDING",
nameStartsWith: "userName",
}),
).toEqual({
_id: {
$lt: cursor,
},
name: {
$regex: /^userName/i,
},
});
});
});

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(
getUserTagMemberGraphQLConnectionFilter({
cursor,
direction: "BACKWARD",
sortById: "ASCENDING",
firstNameStartsWith: "firstName",
lastNameStartsWith: "lastName",
}),
).toEqual({
_id: {
$lt: new Types.ObjectId(cursor),
},
firstName: {
$regex: /^firstName/i,
},
lastName: {
$regex: /^lastName/i,
},
});
});

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

expect(
getUserTagMemberGraphQLConnectionFilter({
cursor,
direction: "FORWARD",
sortById: "ASCENDING",
firstNameStartsWith: "firstName",
lastNameStartsWith: "lastName",
}),
).toEqual({
_id: {
$gt: new Types.ObjectId(cursor),
},
firstName: {
$regex: /^firstName/i,
},
lastName: {
$regex: /^lastName/i,
},
});
});

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

expect(
getUserTagMemberGraphQLConnectionFilter({
cursor,
direction: "BACKWARD",
sortById: "DESCENDING",
firstNameStartsWith: "firstName",
lastNameStartsWith: "lastName",
}),
).toEqual({
_id: {
$gt: new Types.ObjectId(cursor),
},
firstName: {
$regex: /^firstName/i,
},
lastName: {
$regex: /^lastName/i,
},
});
});

it(`when sort order is "DESCENDING" argument cursor is non-null and argument direction corresponds to forward`, async () => {
const cursor = new Types.ObjectId().toString();

expect(
getUserTagMemberGraphQLConnectionFilter({
cursor,
direction: "FORWARD",
sortById: "DESCENDING",
firstNameStartsWith: "firstName",
lastNameStartsWith: "lastName",
}),
).toEqual({
_id: {
$lt: new Types.ObjectId(cursor),
},
firstName: {
$regex: /^firstName/i,
},
lastName: {
$regex: /^lastName/i,
},
});
});
});

describe("getUserTagGraphQLConnectionSort function", () => {
it(`when sort order is "ASCENDING" and argument direction corresponds to backward`, async () => {
expect(
getUserTagGraphQLConnectionSort({
direction: "BACKWARD",
sortById: "ASCENDING",
}),
).toEqual({
_id: -1,
});
});

it(`when sort order is "ASCENDING" and argument direction corresponds to forward`, async () => {
expect(
getUserTagGraphQLConnectionSort({
direction: "FORWARD",
sortById: "ASCENDING",
}),
).toEqual({
_id: 1,
});
});

it(`when sort order is "DESCENDING" and argument direction corresponds to backward`, async () => {
expect(
getUserTagGraphQLConnectionSort({
direction: "BACKWARD",
sortById: "DESCENDING",
}),
).toEqual({
_id: 1,
});
});

it(`when sort order is "DESCENDING" and argument direction corresponds to forward`, async () => {
expect(
getUserTagGraphQLConnectionSort({
direction: "FORWARD",
sortById: "DESCENDING",
}),
).toEqual({
_id: -1,
});
});
});

describe("transformToDefaultGraphQLConnection function", () => {
it(`when totalCount is 0, returns default graphql connection object with default fields
that correspond to a connection with no data and no traversal possible in any direction.`, () => {
Expand Down
Loading

0 comments on commit f60d605

Please sign in to comment.