-
-
Notifications
You must be signed in to change notification settings - Fork 963
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests for src/resolvers/Query/helperFunctions/getSort.ts (#1946)
* Modified Tests for currentUserExists.ts * added tests for getSort.ts --------- Co-authored-by: Peter Harrison <16875803+palisadoes@users.noreply.github.com>
- Loading branch information
1 parent
d34aa8a
commit a518b00
Showing
1 changed file
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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({}); | ||
}); | ||
}); |