-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import { describe, it, expect, vi, beforeEach } from "vitest"; | ||
import { | ||
createMemberShip, | ||
getMemberShip, | ||
getMemberShipById, | ||
updateMemberStatus, | ||
updateMembership, | ||
deleteMember, | ||
} from "./memberShipService"; | ||
import { APIUsers } from "./BaseService"; | ||
|
||
vi.mock("../services/BaseService", () => ({ | ||
APIUsers: { | ||
post: vi.fn(), | ||
get: vi.fn(), | ||
patch: vi.fn(), | ||
delete: vi.fn(), | ||
}, | ||
})); | ||
|
||
describe("MembershipService", () => { | ||
beforeEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
it("deve retornar o status correto ao criar uma filiação", async () => { | ||
APIUsers.post.mockResolvedValueOnce({ status: 201 }); | ||
Check failure on line 27 in src/Services/memberShipService.test.js GitHub Actions / testsrc/Services/memberShipService.test.js > MembershipService > deve retornar o status correto ao criar uma filiação
|
||
|
||
const result = await createMemberShip({ name: "John Doe" }); | ||
|
||
expect(result).toBe(201); | ||
expect(APIUsers.post).toHaveBeenCalledWith("membership/create", { | ||
formData: { name: "John Doe" }, | ||
}); | ||
}); | ||
|
||
it("deve retornar dados da filiação com base no status", async () => { | ||
const mockData = [{ id: 1, status: "active" }]; | ||
APIUsers.get.mockResolvedValueOnce({ data: mockData }); | ||
Check failure on line 39 in src/Services/memberShipService.test.js GitHub Actions / testsrc/Services/memberShipService.test.js > MembershipService > deve retornar dados da filiação com base no status
|
||
|
||
const result = await getMemberShip("active"); | ||
|
||
expect(result).toEqual(mockData); | ||
expect(APIUsers.get).toHaveBeenCalledWith("membership", { | ||
params: { status: "active" }, | ||
}); | ||
}); | ||
|
||
it("deve retornar dados da filiação pelo ID", async () => { | ||
const mockData = { id: 1, name: "John Doe" }; | ||
APIUsers.get.mockResolvedValueOnce({ data: mockData }); | ||
Check failure on line 51 in src/Services/memberShipService.test.js GitHub Actions / testsrc/Services/memberShipService.test.js > MembershipService > deve retornar dados da filiação pelo ID
|
||
|
||
const result = await getMemberShipById(1); | ||
|
||
expect(result).toEqual(mockData); | ||
expect(APIUsers.get).toHaveBeenCalledWith("membership/1"); | ||
}); | ||
|
||
it("deve atualizar o status da filiação e retornar dados", async () => { | ||
const mockResponse = { success: true }; | ||
APIUsers.patch.mockResolvedValueOnce({ data: mockResponse }); | ||
Check failure on line 61 in src/Services/memberShipService.test.js GitHub Actions / testsrc/Services/memberShipService.test.js > MembershipService > deve atualizar o status da filiação e retornar dados
|
||
|
||
const result = await updateMemberStatus(1, { status: "inactive" }); | ||
|
||
expect(result).toEqual(mockResponse); | ||
expect(APIUsers.patch).toHaveBeenCalledWith("membership/updateStatus/1", { | ||
formData: { status: "inactive" }, | ||
}); | ||
}); | ||
|
||
it("deve retornar false quando atualizar a filiação com sucesso", async () => { | ||
APIUsers.patch.mockResolvedValueOnce({}); | ||
Check failure on line 72 in src/Services/memberShipService.test.js GitHub Actions / testsrc/Services/memberShipService.test.js > MembershipService > deve retornar false quando atualizar a filiação com sucesso
|
||
|
||
const result = await updateMembership(1, { name: "John Updated" }); | ||
|
||
expect(result).toBe(false); | ||
expect(APIUsers.patch).toHaveBeenCalledWith("membership/update/1", { | ||
formData: { name: "John Updated" }, | ||
}); | ||
}); | ||
|
||
it("deve retornar false ao deletar a filiação com sucesso", async () => { | ||
APIUsers.delete.mockResolvedValueOnce({}); | ||
Check failure on line 83 in src/Services/memberShipService.test.js GitHub Actions / testsrc/Services/memberShipService.test.js > MembershipService > deve retornar false ao deletar a filiação com sucesso
|
||
|
||
const result = await deleteMember(1); | ||
|
||
expect(result).toBe(false); | ||
expect(APIUsers.delete).toHaveBeenCalledWith("membership/delete/1"); | ||
}); | ||
|
||
it("deve retornar erro ao falhar no createMemberShip", async () => { | ||
const mockError = { response: { data: { erro: "Erro na requisição" } } }; | ||
APIUsers.post.mockRejectedValueOnce(mockError); | ||
Check failure on line 93 in src/Services/memberShipService.test.js GitHub Actions / testsrc/Services/memberShipService.test.js > MembershipService > deve retornar erro ao falhar no createMemberShip
|
||
|
||
const result = await createMemberShip({ name: "John Doe" }); | ||
|
||
expect(result).toBe("Erro na requisição"); | ||
expect(APIUsers.post).toHaveBeenCalledWith("membership/create", { | ||
formData: { name: "John Doe" }, | ||
}); | ||
}); | ||
}); |