-
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.
* toString isn't needed on string objects * Implemented reviews-service create method, added jest tests * Update reviews-service.ts camelCase * Node vulnerability fix * Add minor format fix * Add minor fix --------- Co-authored-by: Matthew M-B <[email protected]>
- Loading branch information
Showing
7 changed files
with
85 additions
and
14 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
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 |
---|---|---|
@@ -1,4 +1,38 @@ | ||
export const create = async () => { | ||
import { Ok, Err, Result } from "ts-results"; | ||
import { Review, Status } from "../models/Review"; | ||
import { db } from "../../../db"; | ||
import { reviews } from "../../../db/schema"; | ||
import { uuid } from "../../../app/common"; | ||
|
||
export const create = async ( | ||
status: Status, | ||
submissionId: number, | ||
body: string, | ||
): Promise<Result<Review, Error>> => { | ||
// TODO: add a check to make sure the submission exists | ||
// TODO: check if submission has already been approved or rejected, handle accordingly | ||
throw new Error("Not implemented yet"); | ||
|
||
const id = uuid.create(); | ||
|
||
try { | ||
const result = await db | ||
.insert(reviews) | ||
.values({ | ||
uuid: id, | ||
status: Status[status], | ||
body: body, | ||
submissionId: submissionId, | ||
}) | ||
.returning(); | ||
|
||
const review = new Review({ | ||
id: result[0].id, | ||
status: status, | ||
comment: result[0].body, | ||
}); | ||
|
||
return Ok(review); | ||
} catch (e) { | ||
return Err(new Error("Failed to create review")); | ||
} | ||
}; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,37 @@ | ||
import { ReviewsService } from "../../../app/challenges-platform"; | ||
import { Status } from "../../../app/challenges-platform/models"; | ||
import { submissionFactory } from "../factories/submission-factory"; | ||
|
||
describe("ReviewsService", () => { | ||
describe("create", () => { | ||
describe("when submission exists", () => { | ||
it("succesfully creates a review", async () => { | ||
const submission = await submissionFactory(); | ||
const body = "Nice work"; | ||
|
||
const result = await ReviewsService.create( | ||
Status.APPROVED, | ||
submission.id, | ||
body, | ||
); | ||
|
||
if (!result.ok) fail("Expected result to be Ok"); | ||
expect(result.val.status).toBe(Status.APPROVED); | ||
expect(result.val.comment).toBe(body); | ||
}); | ||
}); | ||
describe("when submission does not exist", () => { | ||
it("returns an error", async () => { | ||
const invalidId = -1; | ||
const result = await ReviewsService.create( | ||
Status.REJECTED, | ||
invalidId, | ||
"body", | ||
); | ||
|
||
expect(result.err).toBe(true); | ||
expect(result.val.toString()).toBe("Error: Failed to create review"); | ||
}); | ||
}); | ||
}); | ||
}); |