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.
intg(attached chat file): prepare test to delete attached chat message
- Loading branch information
1 parent
3657864
commit 870e37c
Showing
2 changed files
with
71 additions
and
19 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
t/integration/api/attached_chat_file/destroy.delete.spec.ts
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,49 @@ | ||
import { JSON_API_MEDIA_TYPE } from "$/types/server" | ||
|
||
import App from "~/set-ups/app" | ||
import RoleFactory from "~/factories/role" | ||
import Model from "%/models/attached_chat_file" | ||
import Factory from "~/factories/attached_chat_file" | ||
import ChatMessageFactory from "~/factories/chat_message" | ||
import RequestEnvironment from "$!/singletons/request_environment" | ||
import ChatMessageActivityFactory from "~/factories/chat_message_activity" | ||
|
||
import Route from "!%/api/attached_chat_file/destroy.delete" | ||
|
||
describe("DELETE /api/attached_chat_file", () => { | ||
beforeAll(async() => { | ||
await App.create(new Route()) | ||
}) | ||
|
||
it("can be accessed by authenticated user", async() => { | ||
const adminRole = await new RoleFactory().insertOne() | ||
const { user, cookie } = await App.makeAuthenticatedCookie(adminRole, userFactory => { | ||
return userFactory.beStudent() | ||
}) | ||
|
||
const chatMessageActivity = await new ChatMessageActivityFactory() | ||
.user(() => Promise.resolve(user)) | ||
.insertOne() | ||
const chatMessage = await new ChatMessageFactory() | ||
.chatMessageActivity(() => Promise.resolve(chatMessageActivity)) | ||
.insertOne() | ||
const model = await new Factory().chatMessage(() => Promise.resolve(chatMessage)).insertOne() | ||
|
||
const response = await App.request | ||
.delete("/api/attached_chat_file") | ||
.send({ | ||
"data": [ | ||
{ | ||
"id": String(model.id), | ||
"type": "attached_chat_file" | ||
} | ||
] | ||
}) | ||
.set("Cookie", cookie) | ||
.type(JSON_API_MEDIA_TYPE) | ||
.accept(JSON_API_MEDIA_TYPE) | ||
|
||
expect(response.statusCode).toBe(RequestEnvironment.status.NO_CONTENT) | ||
expect(await Model.findOne({ "where": { "id": model.id } } )).toBeNull() | ||
}) | ||
}) |
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,38 +1,41 @@ | ||
import { JSON_API_MEDIA_TYPE } from "$/types/server" | ||
|
||
import App from "~/set-ups/app" | ||
import Role from "%/models/role" | ||
import RoleFactory from "~/factories/role" | ||
import Model from "%/models/role" | ||
import Factory from "~/factories/role" | ||
import RequestEnvironment from "$!/singletons/request_environment" | ||
import { ARCHIVE_AND_RESTORE } from "$/permissions/role_combinations" | ||
import { role as permissionGroup } from "$/permissions/permission_list" | ||
|
||
import Route from "!%/api/role/archive.delete" | ||
|
||
describe("DELETE /api/role", () => { | ||
beforeAll(async () => { | ||
beforeAll(async() => { | ||
await App.create(new Route()) | ||
}) | ||
|
||
it("can be accessed by authenticated user", async () => { | ||
const adminRole = await new RoleFactory() | ||
.roleFlags(permissionGroup.generateMask(...ARCHIVE_AND_RESTORE)) | ||
.insertOne() | ||
const { user, cookie } = await App.makeAuthenticatedCookie(adminRole) | ||
const role = await (new RoleFactory()).insertOne() | ||
it("can be accessed by authenticated user", async() => { | ||
const adminRole = await new Factory() | ||
.roleFlags(permissionGroup.generateMask(...ARCHIVE_AND_RESTORE)) | ||
.insertOne() | ||
const { cookie } = await App.makeAuthenticatedCookie(adminRole) | ||
const model = await new Factory().insertOne() | ||
|
||
const response = await App.request | ||
.delete("/api/role") | ||
.send({ | ||
data: [ | ||
{ type: "role", id: String(role.id) } | ||
] | ||
}) | ||
.set("Cookie", cookie) | ||
.type(JSON_API_MEDIA_TYPE) | ||
.accept(JSON_API_MEDIA_TYPE) | ||
.delete("/api/role") | ||
.send({ | ||
"data": [ | ||
{ | ||
"id": String(model.id), | ||
"type": "role" | ||
} | ||
] | ||
}) | ||
.set("Cookie", cookie) | ||
.type(JSON_API_MEDIA_TYPE) | ||
.accept(JSON_API_MEDIA_TYPE) | ||
|
||
expect(response.statusCode).toBe(RequestEnvironment.status.NO_CONTENT) | ||
expect(await Role.findOne({ where: { id: role.id } })).toBeNull() | ||
expect(await Model.findOne({ "where": { "id": model.id } })).toBeNull() | ||
}) | ||
}) |