Pular para o conteúdo principal

ClientProfile Service

Serviço para buscar perfis de clientes.

Importação

import { ClientProfileService } from "@/services/client-profile/client-profile.service";

Métodos

fetchRemote

Busca perfis de clientes remotamente.

Parâmetros:

{
page?: number;
size?: number;
dataHora?: string;
}

Retorno: Promise<ClientProfile[]>

Exemplo:

const service = new ClientProfileService();
const profiles = await service.fetchRemote({
page: 0,
size: 10,
});

Endpoint da API

GET /perfil

Busca perfis de clientes paginados.

Query Params:

  • page (opcional, padrão: 0)
  • size (opcional, padrão: 999)
  • dataHora (opcional)

Resposta:

{
"content": [
{
"id": "c001",
"nome": "Mariana Silva",
"produtos": [
{
"id": "p001",
"nome": "Assinatura Básica",
"descricao": "Acesso mensal ao conteúdo padrão"
}
]
}
]
}

Tipos

ClientProfile

interface ClientProfile {
id: string;
nome: string;
produtos: BasicProducts[];
}

BasicProducts

interface BasicProducts {
id: string;
nome: string;
descricao: string;
}

Casos de Uso

Buscar todos os perfis

const service = new ClientProfileService();
const profiles = await service.fetchRemote();

Buscar perfis com paginação

const service = new ClientProfileService();
const profiles = await service.fetchRemote({
page: 0,
size: 20,
});

Testes

O serviço possui cobertura de testes automatizados:

describe("ClientProfileService", () => {
it("should throw error when status is not 2xx", async () => {
const service = new ClientProfileService();
await expect(service.fetchRemote()).rejects.toThrow(
"ClientProfileService.fetchRemote failed: 404",
);
});

it("should return profiles from content", async () => {
const service = new ClientProfileService();
const result = await service.fetchRemote();
expect(result).toEqual(clientProfileResponse.content);
});
});