-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dd7e53d
commit 45e1ae5
Showing
2 changed files
with
51 additions
and
2 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
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 |
---|---|---|
|
@@ -52,6 +52,25 @@ const post: Post & { | |
} | ||
} | ||
|
||
const closedPost: Post & { | ||
authorEmail: string, | ||
author: { | ||
email: string | ||
} | ||
} = { | ||
id: "1", | ||
authorId: "1", | ||
authorEmail: "[email protected]", | ||
source: "source", | ||
destination: "destination", | ||
costInPoints: 10, | ||
service: "service", | ||
status: "closed", | ||
author: { | ||
email: "[email protected]" | ||
} | ||
} | ||
|
||
const completedPost: Post & { | ||
authorEmail: string, | ||
author: { | ||
|
@@ -78,6 +97,13 @@ const request: Request = { | |
status: "open" | ||
} | ||
|
||
const completedRequest: Request = { | ||
id: "1", | ||
postId: "1", | ||
senderEmail: "[email protected]", | ||
status: "completed" | ||
} | ||
|
||
describe("Create a new post", () => { | ||
it("should create a new post", () => { | ||
|
||
|
@@ -392,6 +418,31 @@ describe("Complete post", () => { | |
data: "Some error occurred while completing the post" | ||
}); | ||
}); | ||
|
||
it("should throw error if user does not have enough karma", () => { | ||
prismaMock.user.findUnique.mockResolvedValue(userWith0KarmaPoints); | ||
prismaMock.post.findUnique.mockResolvedValue(closedPost); | ||
prismaMock.request.findMany.mockResolvedValue([completedRequest]); | ||
prismaMock.$transaction.mockResolvedValue([[completedRequest], closedPost]); | ||
|
||
expect(completePost(closedPost.id, userWith0KarmaPoints.email)).resolves.toEqual({ | ||
error: true, | ||
data: "Not enough karma to complete this post." | ||
}); | ||
}) | ||
|
||
it("should complete successfully if user does have enough karma", () => { | ||
prismaMock.user.findUnique.mockResolvedValue(userWith10KarmaPoints); | ||
prismaMock.post.findUnique.mockResolvedValue(closedPost); | ||
prismaMock.request.findMany.mockResolvedValue([completedRequest]); | ||
prismaMock.$transaction.mockResolvedValue([[completedRequest], closedPost]); | ||
prismaMock.post.update.mockResolvedValue(completedPost); | ||
|
||
expect(completePost(closedPost.id, userWith10KarmaPoints.email)).resolves.toEqual({ | ||
error: false, | ||
data: completedPost | ||
}); | ||
}) | ||
}) | ||
|
||
describe("Delete post", () => { | ||
|