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

Commit

Permalink
unit(fetcher): ensure updating of attached roles
Browse files Browse the repository at this point in the history
  • Loading branch information
lemredd committed Nov 20, 2022
1 parent 5cf358a commit 9dc6d8e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
1 change: 1 addition & 0 deletions common_front-end/fetchers/post.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { COUNT_COMMENTS, UPDATE_TAG_OF_POST_LINK } from "$/constants/template_li
import specializePath from "$/helpers/specialize_path"
import stringifyQuery from "$@/fetchers/stringify_query"
import RequestEnvironment from "$/singletons/request_environment"

import Fetcher from "./post"

describe("Fetcher: Post", () => {
Expand Down
22 changes: 13 additions & 9 deletions common_front-end/fetchers/user.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
/* eslint-disable no-undef */
import type { UnitError } from "$/types/server"

import { UPDATE_PASSWORD_LINK } from "$/constants/template_links"
import {
UPDATE_PASSWORD_LINK,
UPDATE_ROLE_OF_USER_LINK
} from "$/constants/template_links"

import UserFetcher from "$@/fetchers/user"
import specializePath from "$/helpers/specialize_path"
import RequestEnvironment from "$/singletons/request_environment"

import Fetcher from "./user"

describe("Fetcher: User", () => {
it("can log in", async() => {
fetchMock.mockResponse(
Expand All @@ -19,7 +23,7 @@ describe("Fetcher: User", () => {
{ "status": RequestEnvironment.status.OK }
)

const fetcher = new UserFetcher()
const fetcher = new Fetcher()
const response = await fetcher.logIn({
"email": "sample@example.com",
"password": "1234"
Expand All @@ -44,7 +48,7 @@ describe("Fetcher: User", () => {
{ "status": RequestEnvironment.status.NO_CONTENT }
)

const fetcher = new UserFetcher()
const fetcher = new Fetcher()
const response = await fetcher.logOut()
expect(response).toHaveProperty("body", null)
expect(response).toHaveProperty("status", RequestEnvironment.status.NO_CONTENT)
Expand All @@ -64,7 +68,7 @@ describe("Fetcher: User", () => {
}),
{ "status": RequestEnvironment.status.UNAUTHORIZED }
)
const fetcher = new UserFetcher()
const fetcher = new Fetcher()

const response = await fetcher.logOut()
const { body } = response
Expand All @@ -87,7 +91,7 @@ describe("Fetcher: User", () => {
}),
{ "status": RequestEnvironment.status.CREATED }
)
const fetcher = new UserFetcher()
const fetcher = new Fetcher()

const response = await fetcher.import({} as FormData)

Expand All @@ -114,7 +118,7 @@ describe("Fetcher: User", () => {
const CONFIRM_NEW_PASSWORD = "!"
fetchMock.mockResponse("", { "status": RequestEnvironment.status.NO_CONTENT })

const fetcher = new UserFetcher()
const fetcher = new Fetcher()
const response = await fetcher.updatePassword(
USER_ID,
CURRENT_PASSWORD,
Expand Down Expand Up @@ -154,12 +158,12 @@ describe("Fetcher: User", () => {
const tagIDs = [ "1" ]
const fetcher = new Fetcher()

const response = await fetcher.updateAttachedTags(postID, tagIDs)
const response = await fetcher.updateAttachedRole(postID, tagIDs)

const castFetch = fetch as jest.Mock<any, any>
const [ [ request ] ] = castFetch.mock.calls
expect(request).toHaveProperty("method", "PATCH")
expect(request).toHaveProperty("url", specializePath(UPDATE_TAG_OF_POST_LINK, {
expect(request).toHaveProperty("url", specializePath(UPDATE_ROLE_OF_USER_LINK, {
"id": postID
}))
expect(response).toHaveProperty("status", RequestEnvironment.status.NO_CONTENT)
Expand Down

0 comments on commit 9dc6d8e

Please sign in to comment.