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

Commit

Permalink
unit(consultation): remove client request to create the status message
Browse files Browse the repository at this point in the history
  • Loading branch information
KennethTrecy committed Sep 17, 2022
1 parent 6c576be commit 91d2061
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 47 deletions.
60 changes: 14 additions & 46 deletions components/consultation/chat_window.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ import { shallowMount, flushPromises } from "@vue/test-utils"
import RequestEnvironment from "$/singletons/request_environment"
import type { DeserializedConsultationResource } from "$/types/documents/consultation"
import type { DeserializedChatMessageListDocument } from "$/types/documents/chat_message"
import type {
DeserializedChatMessageActivityResource
} from "$/types/documents/chat_message_activity"

import convertTimeToMinutes from "$/object/convert_time_to_minutes"
import Component from "./chat_window.vue"
Expand All @@ -25,17 +22,10 @@ describe("Component: consultation/chat_window", () => {
const fakeChatMessage = {
"data": []
} as DeserializedChatMessageListDocument
const fakeChatMessageActivity = {
"id": "1",
"receivedMessageAt": new Date(),
"seenMessageAt": new Date(),
"type": "chat_message_activity"
} as DeserializedChatMessageActivityResource
const wrapper = shallowMount<any>(Component, {
"props": {
"chatMessages": fakeChatMessage,
"consultation": fakeConsultation,
"ownChatMessageActivity": fakeChatMessageActivity
"consultation": fakeConsultation
}
})

Expand All @@ -46,7 +36,7 @@ describe("Component: consultation/chat_window", () => {
const events = wrapper.emitted("updatedConsultationAttributes")
expect(events).toHaveLength(1)
const castFetch = fetch as jest.Mock<any, any>
const [ [ firstRequest ], [ secondRequest ] ] = castFetch.mock.calls
const [ [ firstRequest ] ] = castFetch.mock.calls
expect(firstRequest).toHaveProperty("method", "PATCH")
expect(firstRequest).toHaveProperty("url", "/api/consultation/1")
const firstRequestBody = await firstRequest.json()
Expand All @@ -60,14 +50,6 @@ describe("Component: consultation/chat_window", () => {
expect(firstRequestBody).not.toHaveProperty("data.attributes.startedAt", null)
expect(firstRequestBody).toHaveProperty("data.id", "1")
expect(firstRequestBody).toHaveProperty("data.type", "consultation")
expect(secondRequest).toHaveProperty("method", "POST")
expect(secondRequest).toHaveProperty("url", "/api/chat_message")
const secondRequestBody = await secondRequest.json()
expect(secondRequestBody).toHaveProperty("data.attributes.kind", "status")
expect(secondRequestBody).toHaveProperty(
"data.attributes.relationships.chatMessageActivity.data.",
fakeChatMessageActivity.id
)
})

it("should automatically terminate the consultation", async() => {
Expand All @@ -85,29 +67,23 @@ describe("Component: consultation/chat_window", () => {
const fakeChatMessage = {
"data": []
} as DeserializedChatMessageListDocument
const fakeChatMessageActivity = {
"id": "1",
"receivedMessageAt": new Date(),
"seenMessageAt": new Date(),
"type": "chat_message_activity"
} as DeserializedChatMessageActivityResource
const wrapper = shallowMount<any>(Component, {
"props": {
"chatMessages": fakeChatMessage,
"consultation": fakeConsultation,
"ownChatMessageActivity": fakeChatMessageActivity
"consultation": fakeConsultation
}
})

const userController = wrapper.findComponent({ "name": "UserController" })
await userController.trigger("start-consultation")
await flushPromises()
jest.advanceTimersByTime(convertTimeToMinutes("05:00"))
await flushPromises()

const events = wrapper.emitted("updatedConsultationAttributes")
expect(events).toHaveLength(1)
const castFetch = fetch as jest.Mock<any, any>
const [ [ firstRequest ], [ secondRequest ], [ thirdRequest ] ] = castFetch.mock.calls
const [ [ firstRequest ], [ secondRequest ] ] = castFetch.mock.calls
expect(firstRequest).toHaveProperty("method", "PATCH")
expect(firstRequest).toHaveProperty("url", "/api/consultation/1")
const firstRequestBody = await firstRequest.json()
Expand All @@ -122,27 +98,19 @@ describe("Component: consultation/chat_window", () => {
expect(firstRequestBody).toHaveProperty("data.attributes.finsihedAt", null)
expect(firstRequestBody).toHaveProperty("data.id", "1")
expect(firstRequestBody).toHaveProperty("data.type", "consultation")
expect(secondRequest).toHaveProperty("method", "POST")
expect(secondRequest).toHaveProperty("url", "/api/chat_message")
expect(secondRequest).toHaveProperty("method", "PATCH")
expect(secondRequest).toHaveProperty("url", "/api/consultation/1")
const secondRequestBody = await secondRequest.json()
expect(secondRequestBody).toHaveProperty("data.attributes.kind", "status")
expect(secondRequestBody).toHaveProperty("data.attributes.actionTaken", null)
expect(secondRequestBody).toHaveProperty("data.attributes.finishedAt", null)
expect(secondRequestBody).toHaveProperty("data.attributes.reason", "")
expect(secondRequestBody).toHaveProperty(
"data.attributes.relationships.chatMessageActivity.data.",
fakeChatMessageActivity.id
)
expect(thirdRequest).toHaveProperty("method", "PATCH")
expect(thirdRequest).toHaveProperty("url", "/api/consultation/1")
const thirdRequestBody = await thirdRequest.json()
expect(thirdRequestBody).toHaveProperty("data.attributes.actionTaken", null)
expect(thirdRequestBody).toHaveProperty("data.attributes.finishedAt", null)
expect(thirdRequestBody).toHaveProperty("data.attributes.reason", "")
expect(thirdRequestBody).toHaveProperty(
"data.attributes.scheduledStartAt",
scheduledStartAt.toJSON()
)
expect(thirdRequestBody).not.toHaveProperty("data.attributes.startedAt", null)
expect(firstRequestBody).not.toHaveProperty("data.attributes.finsihedAt", null)
expect(thirdRequestBody).toHaveProperty("data.id", "1")
expect(thirdRequestBody).toHaveProperty("data.type", "consultation")
expect(secondRequestBody).not.toHaveProperty("data.attributes.startedAt", null)
expect(secondRequestBody).not.toHaveProperty("data.attributes.finsihedAt", null)
expect(secondRequestBody).toHaveProperty("data.id", "1")
expect(secondRequestBody).toHaveProperty("data.type", "consultation")
})
})
1 change: 0 additions & 1 deletion pages/consultation/read.page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,6 @@ describe("UI Page: Read resource by ID", () => {
}),
{ "status": RequestEnvironment.status.OK }
)

fetchMock.mockResponseOnce("{}", { "status": RequestEnvironment.status.NO_CONTENT })

const wrapper = mount(Page, {
Expand Down

0 comments on commit 91d2061

Please sign in to comment.