Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Commit

Permalink
unit(post): remove unnecessary test
Browse files Browse the repository at this point in the history
  • Loading branch information
KennethTrecy committed Nov 27, 2022
1 parent 4614292 commit c6e5e6f
Showing 1 changed file with 0 additions and 107 deletions.
107 changes: 0 additions & 107 deletions components/post/multiviewer/viewer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,120 +13,13 @@ import RequestEnvironment from "$/singletons/request_environment"

import PermissionGroup from "$/permissions/post"
import {
UPDATE_PERSONAL_POST_ON_OWN_DEPARTMENT,
ARCHIVE_AND_RESTORE_PERSONAL_POST_ON_OWN_DEPARTMENT
} from "$/permissions/post_combinations"

import Component from "./viewer.vue"

jest.useFakeTimers()
describe("Component: post/viewer", () => {
it("should submit post errors", async() => {
const userID = "1"
const postID = "2"
const roleID = "3"
const modelValue = {
"content": "Hello world!",
"createdAt": new Date(),
"deletedAt": null,
"id": postID,
"poster": {
"data": {
"id": userID,
"type": "user"
}
} as DeserializedUserDocument<"roles">,
"posterRole": {
"data": {
"id": roleID,
"type": "role"
}
} as DeserializedRoleDocument,
"type": "post",
"updatedAt": new Date()
} as DeserializedPostResource<"poster"|"posterRole">
fetchMock.mockResponseOnce("", { "status": RequestEnvironment.status.NO_CONTENT })
const wrapper = shallowMount<any>(Component, {
"global": {
"provide": {
"pageContext": {
"pageProps": {
"userProfile": {
"data": {
"id": userID,
"roles": {
"data": [
{
"id": "1",
"postFlags": new PermissionGroup().generateFlags(
...UPDATE_PERSONAL_POST_ON_OWN_DEPARTMENT
)
}
]
},
"type": "user"
}
}
}
}
},
"stubs": {
"Dropdown": false
}
},
"props": {
"commentCount": 0,
modelValue
}
})

const menu = wrapper.findComponent({ "name": "Menu" })
await menu.vm.$emit("updatePost")
const updatePostForm = wrapper.findComponent({ "name": "UpdatePostForm" })
await updatePostForm.vm.$emit("submit")
await flushPromises()

const castWrapper = wrapper.vm as any
expect(castWrapper.mustUpdate).toBeTruthy()
const castFetch = fetch as jest.Mock<any, any>
expect(castFetch).toHaveBeenCalledTimes(1)
const [ [ request ] ] = castFetch.mock.calls
expect(request).toHaveProperty("method", "PATCH")
expect(request).toHaveProperty("url", specializePath(POST_LINK.bound, { "id": postID }))
expect(request.headers.get("Content-Type")).toBe(JSON_API_MEDIA_TYPE)
expect(request.headers.get("Accept")).toBe(JSON_API_MEDIA_TYPE)
const expectedBody = {
"data": {
"attributes": {
"content": modelValue.content,
"createdAt": modelValue.createdAt.toJSON(),
"deletedAt": modelValue.deletedAt,
"updatedAt": modelValue.updatedAt.toJSON()
},
"id": postID,
"relationships": {
"poster": {
"data": {
"id": modelValue.poster.data.id,
"type": "user"
}
},
"posterRole": {
"data": {
"id": modelValue.posterRole.data.id,
"type": "role"
}
}
},
"type": "post"
}
}
expect(await request.json()).toStrictEqual(expectedBody)

const updateEvent = wrapper.emitted("update:modelValue")
expect(updateEvent).toHaveProperty("0.0", modelValue)
})

it("should request for archiving the post", async() => {
const userID = "1"
const postID = "2"
Expand Down

0 comments on commit c6e5e6f

Please sign in to comment.