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(attached chat file): prepare test to destroy attached chat file
- Loading branch information
1 parent
78df76b
commit 1507fb2
Showing
2 changed files
with
87 additions
and
4 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 "~/set-ups/mock_requester" | ||
import Factory from "~/factories/attached_chat_file" | ||
|
||
import Controller from "./destroy.delete" | ||
|
||
const BODY_VALIDATION_INDEX = 0 | ||
|
||
describe("Controller: DELETE /api/attached_chat_file", () => { | ||
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 Factory().insertOne() | ||
requester.customizeRequest({ | ||
"body": { | ||
"data": [ | ||
{ | ||
"id": String(model.id), | ||
"type": "attached_chat_file" | ||
} | ||
] | ||
} | ||
}) | ||
|
||
await requester.runMiddleware(bodyValidationFunction) | ||
|
||
requester.expectSuccess() | ||
}) | ||
|
||
it("cannot accept already-destroyed 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 Factory().insertOne() | ||
await model.destroy({ "force": false }) | ||
requester.customizeRequest({ | ||
"body": { | ||
"data": [ | ||
{ | ||
"id": String(model.id), | ||
"type": "attached_chat_file" | ||
} | ||
] | ||
} | ||
}) | ||
|
||
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 Factory().insertOne() | ||
await model.destroy({ "force": true }) | ||
requester.customizeRequest({ | ||
"body": { | ||
"data": [ | ||
{ | ||
"id": String(model.id), | ||
"type": "attached_chat_file" | ||
} | ||
] | ||
} | ||
}) | ||
|
||
await requester.runMiddleware(bodyValidationFunction) | ||
|
||
const body = requester.expectFailure(ErrorBag).toJSON() | ||
expect(body).toHaveLength(1) | ||
expect(body).toHaveProperty("0.source.pointer", "data.0.id") | ||
}) | ||
}) |
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