Skip to content

Commit

Permalink
Added tests for src/resolvers/Query/helperFunctions/getSort.ts (#1946)
Browse files Browse the repository at this point in the history
* Modified Tests for currentUserExists.ts

* added tests for getSort.ts

---------

Co-authored-by: Peter Harrison <16875803+palisadoes@users.noreply.github.com>
  • Loading branch information
aarishshahmohsin and palisadoes authored Mar 11, 2024
1 parent d34aa8a commit a518b00
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions tests/resolvers/Query/helperFunctions/getSort.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { describe, expect, it } from "vitest";
import { getSort } from "../../../../src/resolvers/Query/helperFunctions/getSort";
import type {
EventOrderByInput,
OrganizationOrderByInput,
PostOrderByInput,
UserOrderByInput,
} from "../../../../src/types/generatedGraphQLTypes";

describe("getSort function", () => {
const testCases: [string, Record<string, number>][] = [
["id_ASC", { _id: 1 }],
["id_DESC", { _id: -1 }],
["title_ASC", { title: 1 }],
["title_DESC", { title: -1 }],
["description_ASC", { description: 1 }],
["description_DESC", { description: -1 }],
["startDate_ASC", { startDate: 1 }],
["startDate_DESC", { startDate: -1 }],
["endDate_ASC", { endDate: 1 }],
["endDate_DESC", { endDate: -1 }],
["allDay_ASC", { allDay: 1 }],
["allDay_DESC", { allDay: -1 }],
["startTime_ASC", { startTime: 1 }],
["startTime_DESC", { startTime: -1 }],
["endTime_ASC", { endTime: 1 }],
["endTime_DESC", { endTime: -1 }],
["recurrance_ASC", { recurrance: 1 }],
["recurrance_DESC", { recurrance: -1 }],
["location_ASC", { location: 1 }],
["location_DESC", { location: -1 }],
["createdAt_ASC", { createdAt: 1 }],
["createdAt_DESC", { createdAt: -1 }],
["name_ASC", { name: 1 }],
["name_DESC", { name: -1 }],
["apiUrl_ASC", { apiUrl: 1 }],
["apiUrl_DESC", { apiUrl: -1 }],
["firstName_ASC", { firstName: 1 }],
["firstName_DESC", { firstName: -1 }],
["lastName_ASC", { lastName: 1 }],
["lastName_DESC", { lastName: -1 }],
["appLanguageCode_ASC", { appLanguageCode: 1 }],
["appLanguageCode_DESC", { appLanguageCode: -1 }],
["email_ASC", { email: 1 }],
["email_DESC", { email: -1 }],
["text_ASC", { text: 1 }],
["text_DESC", { text: -1 }],
["imageUrl_ASC", { imageUrl: 1 }],
["imageUrl_DESC", { imageUrl: -1 }],
["videoUrl_ASC", { videoUrl: 1 }],
["videoUrl_DESC", { videoUrl: -1 }],
["likeCount_ASC", { likeCount: 1 }],
["likeCount_DESC", { likeCount: -1 }],
["commentCount_ASC", { commentCount: 1 }],
["commentCount_DESC", { commentCount: -1 }],
];

it.each(testCases)(
"should return correct sort for %s",
(orderBy, expected) => {
const result = getSort(
orderBy as
| EventOrderByInput
| OrganizationOrderByInput
| PostOrderByInput
| UserOrderByInput,
);
expect(result).toEqual(expected);
},
);

it("should return empty object for unknown orderBy value", () => {
const result = getSort("unknown" as UserOrderByInput);
expect(result).toEqual({});
});

it("should return empty object for undefined orderBy", () => {
const result = getSort(undefined);
expect(result).toEqual({});
});
});

0 comments on commit a518b00

Please sign in to comment.