This repository has been archived by the owner on Sep 12, 2023. It is now read-only.
generated from KennethTrecy/web_template
-
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.
unit(route): ensure comment archive route works
- Loading branch information
Angelo Magtoto
committed
Oct 10, 2022
1 parent
ba2837d
commit db1a080
Showing
1 changed file
with
83 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,83 @@ | ||
import ErrorBag from "$!/errors/error_bag" | ||
import MockRequester from "~/setups/mock_requester" | ||
import CommentFactory from "~/factories/comment" | ||
|
||
import Controller from "./archive.delete" | ||
|
||
const BODY_VALIDATION_INDEX = 0 | ||
|
||
describe("Controller: DELETE /api/comment", () => { | ||
const requester = new MockRequester() | ||
|
||
it("can accept valid info", async() => { | ||
const controller = new Controller() | ||
const { validations } = controller | ||
const bodyValidation = validations[BODY_VALIDATION_INDEX] | ||
const bodyValidationFunction = bodyValidation.intermediate.bind(bodyValidation) | ||
const model = await new CommentFactory().insertOne() | ||
requester.customizeRequest({ | ||
"body": { | ||
"data": [ | ||
{ | ||
"id": String(model.id), | ||
"type": "comment" | ||
} | ||
] | ||
} | ||
}) | ||
|
||
await requester.runMiddleware(bodyValidationFunction) | ||
|
||
requester.expectSuccess() | ||
}) | ||
|
||
it("cannot accept already-archived resources", async() => { | ||
const controller = new Controller() | ||
const { validations } = controller | ||
const bodyValidation = validations[BODY_VALIDATION_INDEX] | ||
const bodyValidationFunction = bodyValidation.intermediate.bind(bodyValidation) | ||
const model = await new CommentFactory().insertOne() | ||
await model.destroy({ "force": false }) | ||
requester.customizeRequest({ | ||
"body": { | ||
"data": [ | ||
{ | ||
"id": String(model.id), | ||
"type": "comment" | ||
} | ||
] | ||
} | ||
}) | ||
|
||
await requester.runMiddleware(bodyValidationFunction) | ||
|
||
const body = requester.expectFailure(ErrorBag).toJSON() | ||
expect(body).toHaveLength(1) | ||
expect(body).toHaveProperty("0.source.pointer", "data.0.id") | ||
}) | ||
|
||
it("cannot delete non-existent resources", async() => { | ||
const controller = new Controller() | ||
const { validations } = controller | ||
const bodyValidation = validations[BODY_VALIDATION_INDEX] | ||
const bodyValidationFunction = bodyValidation.intermediate.bind(bodyValidation) | ||
const model = await new CommentFactory().insertOne() | ||
await model.destroy({ "force": false }) | ||
requester.customizeRequest({ | ||
"body": { | ||
"data": [ | ||
{ | ||
"id": String(model.id), | ||
"type": "comment" | ||
} | ||
] | ||
} | ||
}) | ||
|
||
await requester.runMiddleware(bodyValidationFunction) | ||
|
||
const body = requester.expectFailure(ErrorBag).toJSON() | ||
expect(body).toHaveLength(1) | ||
expect(body).toHaveProperty("0.source.pointer", "data.0.id") | ||
}) | ||
}) |