Initial commit

This commit is contained in:
forceoranj
2021-10-16 01:53:56 +02:00
commit ebdd8dccdd
104 changed files with 29770 additions and 0 deletions

View File

@@ -0,0 +1,96 @@
import axios from "axios"
import mockStore from "../../utils/mockStore"
import javGameList, {
initialState,
getRequesting,
getSuccess,
getFailure,
fetchJavGameList,
} from "../javGameList"
jest.mock("axios")
const mockData = [
{
id: 5,
titre: "6 qui prend!",
auteur: "Wolfgang Kramer",
editeur: "(uncredited) , Design Edge , B",
minJoueurs: 2,
maxJoueurs: 10,
duree: 45,
type: "Ambiance",
poufpaf: "0-9-2/6-qui-prend-6-nimmt",
photo: "https://cf.geekdo-images.com/thumb/img/lzczxR5cw7an7tRWeHdOrRtLyes=/fit-in/200x150/pic772547.jpg",
bggPhoto: "",
bggId: 432,
exemplaires: 1,
dispoPret: 1,
nonRangee: 0,
horodatage: "0000-00-00",
ean: "3421272101313",
},
]
const mockError = "Oops! Something went wrong."
describe("javGameList reducer", () => {
it("should handle initial state", () => {
// @ts-expect-error
expect(javGameList(undefined, {})).toEqual(initialState)
})
it("should handle requesting correctly", () => {
expect(javGameList(undefined, { type: getRequesting.type })).toEqual({
readyStatus: "request",
items: [],
error: null,
})
})
it("should handle success correctly", () => {
expect(javGameList(undefined, { type: getSuccess.type, payload: mockData })).toEqual({
...initialState,
readyStatus: "success",
items: mockData,
})
})
it("should handle failure correctly", () => {
expect(javGameList(undefined, { type: getFailure.type, payload: mockError })).toEqual({
...initialState,
readyStatus: "failure",
error: mockError,
})
})
})
describe("javGameList action", () => {
it("fetches javGame list successful", async () => {
const { dispatch, getActions } = mockStore()
const expectedActions = [
{ type: getRequesting.type },
{ type: getSuccess.type, payload: mockData },
]
// @ts-expect-error
axios.get.mockResolvedValue({ data: mockData })
await dispatch(fetchJavGameList())
expect(getActions()).toEqual(expectedActions)
})
it("fetches javGame list failed", async () => {
const { dispatch, getActions } = mockStore()
const expectedActions = [
{ type: getRequesting.type },
{ type: getFailure.type, payload: mockError },
]
// @ts-expect-error
axios.get.mockRejectedValue({ message: mockError })
await dispatch(fetchJavGameList())
expect(getActions()).toEqual(expectedActions)
})
})

View File

@@ -0,0 +1,83 @@
import axios from "axios"
import mockStore from "../../utils/mockStore"
import userData, { getRequesting, getSuccess, getFailure, fetchUserData } from "../userData"
jest.mock("axios")
const mockData = {
id: 1,
name: "PeL",
phone: "+886 0970...",
email: "forceoranj@gmail.com",
website: "https://www.parisestludique.fr",
}
const { id } = mockData
const mockError = "Oops! Something went wrong."
describe("userData reducer", () => {
it("should handle initial state correctly", () => {
// @ts-expect-error
expect(userData(undefined, {})).toEqual({})
})
it("should handle requesting correctly", () => {
expect(userData(undefined, { type: getRequesting.type, payload: id })).toEqual({
[id]: { readyStatus: "request" },
})
})
it("should handle success correctly", () => {
expect(
userData(undefined, {
type: getSuccess.type,
payload: { id, item: mockData },
})
).toEqual({
[id]: { readyStatus: "success", item: mockData },
})
})
it("should handle failure correctly", () => {
expect(
userData(undefined, {
type: getFailure.type,
payload: { id, error: mockError },
})
).toEqual({
[id]: { readyStatus: "failure", error: mockError },
})
})
})
describe("userData action", () => {
const strId = id.toString()
it("fetches user data successful", async () => {
const { dispatch, getActions } = mockStore()
const expectedActions = [
{ type: getRequesting.type, payload: strId },
{ type: getSuccess.type, payload: { id: strId, item: mockData } },
]
// @ts-expect-error
axios.get.mockResolvedValue({ data: mockData })
await dispatch(fetchUserData(strId))
expect(getActions()).toEqual(expectedActions)
})
it("fetches user data failed", async () => {
const { dispatch, getActions } = mockStore()
const expectedActions = [
{ type: getRequesting.type, payload: strId },
{ type: getFailure.type, payload: { id: strId, error: mockError } },
]
// @ts-expect-error
axios.get.mockRejectedValue({ message: mockError })
await dispatch(fetchUserData(strId))
expect(getActions()).toEqual(expectedActions)
})
})

View File

@@ -0,0 +1,84 @@
import axios from "axios"
import mockStore from "../../utils/mockStore"
import userList, {
initialState,
getRequesting,
getSuccess,
getFailure,
fetchUserList,
} from "../userList"
jest.mock("axios")
const mockData = [
{
id: 1,
name: "PeL",
phone: "+886 0970...",
email: "forceoranj@gmail.com",
website: "https://www.parisestludique.fr",
},
]
const mockError = "Oops! Something went wrong."
describe("userList reducer", () => {
it("should handle initial state", () => {
// @ts-expect-error
expect(userList(undefined, {})).toEqual(initialState)
})
it("should handle requesting correctly", () => {
expect(userList(undefined, { type: getRequesting.type })).toEqual({
readyStatus: "request",
items: [],
error: null,
})
})
it("should handle success correctly", () => {
expect(userList(undefined, { type: getSuccess.type, payload: mockData })).toEqual({
...initialState,
readyStatus: "success",
items: mockData,
})
})
it("should handle failure correctly", () => {
expect(userList(undefined, { type: getFailure.type, payload: mockError })).toEqual({
...initialState,
readyStatus: "failure",
error: mockError,
})
})
})
describe("userList action", () => {
it("fetches user list successful", async () => {
const { dispatch, getActions } = mockStore()
const expectedActions = [
{ type: getRequesting.type },
{ type: getSuccess.type, payload: mockData },
]
// @ts-expect-error
axios.get.mockResolvedValue({ data: mockData })
await dispatch(fetchUserList())
expect(getActions()).toEqual(expectedActions)
})
it("fetches user list failed", async () => {
const { dispatch, getActions } = mockStore()
const expectedActions = [
{ type: getRequesting.type },
{ type: getFailure.type, payload: mockError },
]
// @ts-expect-error
axios.get.mockRejectedValue({ message: mockError })
await dispatch(fetchUserList())
expect(getActions()).toEqual(expectedActions)
})
})