Skip to content

Commit

Permalink
Merge pull request #36 from ralcorta/fix-register-scope-services
Browse files Browse the repository at this point in the history
Fix register scope services
  • Loading branch information
ralcorta authored Oct 3, 2023
2 parents d44f49d + 939bd4c commit 33f2029
Show file tree
Hide file tree
Showing 13 changed files with 490 additions and 14 deletions.
6 changes: 3 additions & 3 deletions docs/services/consulta_padron_alcance_13.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Debemos utilizar el metodo `getTaxpayerDetails` pasando como parámetro el docum

```js
const taxpayerDetails =
await afip.registerScopeTThirteenService.getTaxpayerDetails(20111111111); //Devuelve los datos del contribuyente correspondiente al identificador 20111111111
await afip.registerScopeThirteenService.getTaxpayerDetails(20111111111); //Devuelve los datos del contribuyente correspondiente al identificador 20111111111
```

Para mas información acerca de este método ver el item 3.2 de la [especificación del Web service](http://www.afip.gob.ar/ws/ws-padron-a13/manual-ws-sr-padron-a13-v1.2.pdf)
Expand All @@ -25,7 +25,7 @@ Para mas información acerca de este método ver el item 3.2 de la [especificaci
Debemos utilizar el metodo `getTaxIDByDocument` pasando como parámetro el DNI del contribuyente. Nos devolverá el CUIT o `null` en caso de no existir en el padrón

```js
const taxID = await afip.registerScopeTThirteenService.getTaxIDByDocument(
const taxID = await afip.registerScopeThirteenService.getTaxIDByDocument(
11111111
); //Devuelve el CUIT correspondiente al DNI 11111111
```
Expand All @@ -35,7 +35,7 @@ const taxID = await afip.registerScopeTThirteenService.getTaxIDByDocument(
Para esto utilizaremos el método `getServerStatus`

```js
const serverStatus = await afip.registerScopeTThirteenService.getServerStatus();
const serverStatus = await afip.registerScopeThirteenService.getServerStatus();

console.log("Este es el estado del servidor:");
console.log(serverStatus);
Expand Down
8 changes: 4 additions & 4 deletions src/afip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class Afip {
private readonly _registerScopeFourService: RegisterScopeFourService;
private readonly _registerScopeFiveService: RegisterScopeFiveService;
private readonly _registerScopeTenService: RegisterScopeTenService;
private readonly _registerScopeTThirteenService: RegisterScopeThirteenService;
private readonly _registerScopeThirteenService: RegisterScopeThirteenService;
private readonly context: Context;

constructor(context: Context) {
Expand All @@ -26,7 +26,7 @@ export class Afip {
this._registerScopeFourService = new RegisterScopeFourService(this.context);
this._registerScopeFiveService = new RegisterScopeFiveService(this.context);
this._registerScopeTenService = new RegisterScopeTenService(this.context);
this._registerScopeTThirteenService = new RegisterScopeThirteenService(
this._registerScopeThirteenService = new RegisterScopeThirteenService(
this.context
);
}
Expand All @@ -47,8 +47,8 @@ export class Afip {
return this._registerScopeTenService;
}

get registerScopeTThirteenService(): RegisterScopeThirteenService {
return this._registerScopeTThirteenService;
get registerScopeThirteenService(): RegisterScopeThirteenService {
return this._registerScopeThirteenService;
}

public genericService<T extends Client>(
Expand Down
4 changes: 2 additions & 2 deletions src/services/register-scope-five.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ export class RegisterScopeFiveService extends AfipService<IPersonaServiceA5PortS
* @return [object] returns web service full response
**/
async getTaxpayersDetails(
identifier: number
identifiers: number[]
): Promise<PersonaServiceA5PortTypes.IpersonaListReturn> {
const client = await this.getClient();
const { Auth } = await this.getWsAuth();
const [output] = await client.getPersonaList_v2Async({
cuitRepresentada: Auth.Cuit,
sign: Auth.Sign,
token: Auth.Token,
idPersona: identifier,
idPersona: identifiers,
});
return output.personaListReturn;
}
Expand Down
3 changes: 2 additions & 1 deletion src/soap/interfaces/PersonaServiceA5/PersonaServiceA5Port.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-empty-interface */
import { Client } from "soap";
import { SoapAsyncFunc } from "../../../types";
/* tslint:disable:max-line-length no-empty-interface */
Expand Down Expand Up @@ -60,7 +61,7 @@ export interface IgetPersonaList_v2Input {
/** http://a5.soap.ws.server.puc.sr/#xs:long(undefined) */
cuitRepresentada: number;
/** http://a5.soap.ws.server.puc.sr/#xs:long(undefined) */
idPersona: number;
idPersona: number[];
}

export interface IgetPersonaList_v2Output {
Expand Down
2 changes: 1 addition & 1 deletion tests/auth/access-ticket.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { mockLoginCredentials } from "./../mocks/data/credential-json.mock";
import moment from "moment";
import { AccessTicket } from "../../src/auth/access-ticket";
import { ILoginCredentials } from "../../src/types";
import EnvTest from "../env-test";
import EnvTest from "../utils/env-test";

describe("Access Ticket", () => {
describe("getSign", () => {
Expand Down
185 changes: 185 additions & 0 deletions tests/mocks/data/soapClient.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1105,3 +1105,188 @@ export const FEParamGetTiposTributosAsyncReturnMocks = [
},
},
];

export const dummyAsyncReturnMocks = [
{
return: { appserver: "OK", authserver: "OK", dbserver: "OK" },
},
];

export const getPersona_v2AsyncReturnMocks = [
{
personaReturn: {
errorConstancia: {
apellido: "Doe",
error: ["Domicilio Incompleto"],
idPersona: 20111111111,
nombre: "John",
},
metadata: { fechaHora: "2023-9-03T19:32:13.721Z", servidor: "setiwsh2" },
},
},
];

export const getPersonaList_v2AsyncReturnMocks = [
{
personaListReturn: {
metadata: { fechaHora: "2023-9-03T19:32:13.721Z", servidor: "setiwsh2" },
persona: [
{
errorConstancia: {
apellido: "Doe",
error: ["Domicilio Incompleto"],
idPersona: 20111111111,
nombre: "John",
},
},
{
errorConstancia: {
apellido: "Doe",
error: ["Domicilio Incompleto"],
idPersona: 20111111111,
nombre: "John",
},
},
],
},
},
];

export const scopeFourDummyAsyncReturnMocks = [
{ return: { appserver: "OK", authserver: "OK", dbserver: "OK" } },
];

export const scopeFourGetPersonaAsyncReturnMocks = [
{
personaReturn: {
metadata: { fechaHora: "2023-10-02T22:45:02.984Z", servidor: "setiwsh2" },
persona: {
actividad: [
{
descripcionActividad:
"SERVICIOS DE ASESORAMIENTO, DIRECCIÓN Y GESTIÓN EMPRESARIAL REALIZADOS POR INTEGRANTES DE LOS ÓRGANOS DE ADMINISTRACIÓN Y/O FISCALIZACIÓN EN SOCIEDADES ANÓNIMAS",
idActividad: 702091,
nomenclador: 883,
orden: 1,
periodo: 201501,
},
],
apellido: "John",
estadoClave: "ACTIVO",
fechaInscripcion: "2009-11-07T15:00:00.000Z",
fechaNacimiento: "1991-10-15T15:00:00.000Z",
idPersona: 20111111111,
impuesto: [
{
descripcionImpuesto: "IVA",
diaPeriodo: 1,
estado: "ACTIVO",
ffInscripcion: "2010-10-29T15:40:13.000Z",
idImpuesto: 30,
periodo: 199101,
},
{
descripcionImpuesto: "SIRE - IVA",
diaPeriodo: 1,
estado: "ACTIVO",
ffInscripcion: "2017-01-01T15:00:00.000Z",
idImpuesto: 216,
periodo: 201701,
},
{
descripcionImpuesto: "IMP.A LAS GAN.- BENEF.DEL EXT.",
diaPeriodo: 1,
estado: "ACTIVO",
ffInscripcion: "2017-01-01T15:00:00.000Z",
idImpuesto: 218,
periodo: 201701,
},
{
descripcionImpuesto: "PRESENT. DJ SIRE IMPOSITIVO",
diaPeriodo: 1,
estado: "ACTIVO",
ffInscripcion: "2017-01-01T15:00:00.000Z",
idImpuesto: 785,
periodo: 201701,
},
{
descripcionImpuesto: "GANANCIAS PERSONAS FISICAS",
diaPeriodo: 1,
estado: "ACTIVO",
ffInscripcion: "2007-03-06T15:00:00.000Z",
idImpuesto: 11,
periodo: 200401,
},
],
mesCierre: 12,
nombre: "John Doe",
numeroDocumento: "11111111",
relacion: [
{
ffRelacion: "2010-08-23T15:05:43.000Z",
idPersona: 20111111111,
idPersonaAsociada: 20111111111,
tipoRelacion: "PERSONA JURIDICA/ PERSONA FISICA REPRESENTADA",
},
],
sexo: "MASCULINO",
tipoClave: "CUIT",
tipoDocumento: "DNI",
tipoPersona: "FISICA",
},
},
},
];

export const scopeTenDummyAsyncReturnMocks = [
{ return: { appserver: "OK", authserver: "OK", dbserver: "OK" } },
];

export const scopeTenGetPersonaAsyncReturnMocks = [
{
personaReturn: {
metadata: { fechaHora: "2023-10-03T11:26:32.010Z", servidor: "setiwsh2" },
persona: {
apellido: "Doe",
descripcionActividadPrincipal:
"SERVICIOS DE ASESORAMIENTO, DIRECCIÓN Y GESTIÓN EMPRESARIAL REALIZADOS POR INTEGRANTES DE LOS ÓRGANOS DE ADMINISTRACIÓN Y/O FISCALIZACIÓN EN SOCIEDADES ANÓNIMAS",
estadoClave: "ACTIVO",
idActividadPrincipal: 702091,
idPersona: 20111111111,
nombre: "John Doe",
numeroDocumento: "11111111",
tipoClave: "CUIT",
tipoDocumento: "DNI",
tipoPersona: "FISICA",
},
},
},
];

export const scopeThirteenDummyAsyncReturnMocks = [
{ return: { appserver: "OK", authserver: "OK", dbserver: "OK" } },
];

export const scopeThirteenGetPersonaAsyncReturnMocks = [
{
personaReturn: {
metadata: { fechaHora: "2023-10-03T11:39:33.448Z", servidor: "setiwsh2" },
persona: {
apellido: "Doe",
descripcionActividadPrincipal:
"SERVICIOS DE ASESORAMIENTO, DIRECCIÓN Y GESTIÓN EMPRESARIAL REALIZADOS POR INTEGRANTES DE LOS ÓRGANOS DE ADMINISTRACIÓN Y/O FISCALIZACIÓN EN SOCIEDADES ANÓNIMAS",
estadoClave: "ACTIVO",
fechaNacimiento: "1991-10-15T15:00:00.000Z",
idActividadPrincipal: 702091,
idPersona: 20111111111,
mesCierre: 12,
nombre: "John Doe",
numeroDocumento: "11111111",
periodoActividadPrincipal: 201501,
tipoClave: "CUIT",
tipoDocumento: "DNI",
tipoPersona: "FISICA",
},
},
},
];
2 changes: 1 addition & 1 deletion tests/mocks/data/voucher.mock.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IVoucher } from "../../../src/types";
import moment from "moment";
import EnvTest from "../../env-test";
import EnvTest from "../../utils/env-test";

export const testCuit = parseInt(EnvTest.cuit);
export const testPtoVta = 2;
Expand Down
84 changes: 84 additions & 0 deletions tests/services/register-scope-five.service.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { testCuit } from "./../mocks/data/voucher.mock";
import { Afip } from "../../src/afip";
import { TestConfigUtils } from "../utils/config.utils";
import {
dummyAsyncReturnMocks,
getPersonaList_v2AsyncReturnMocks,
getPersona_v2AsyncReturnMocks,
} from "../mocks/data/soapClient.mock";
import { mockLoginCredentials } from "../mocks/data/credential-json.mock";
import { RegisterScopeFiveService } from "../../src/services/register-scope-five.service";

describe("Register Scope Five Service", () => {
const originalNodeTlsRejectUnauthStatus =
process.env.NODE_TLS_REJECT_UNAUTHORIZED;
let registerScopeFiveService: RegisterScopeFiveService;
const cuitPayload = 20111111111;

beforeAll(() => {
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
});

afterAll(() => {
process.env.NODE_TLS_REJECT_UNAUTHORIZED =
originalNodeTlsRejectUnauthStatus;
});

beforeEach(async () => {
registerScopeFiveService = new Afip({
key: await TestConfigUtils.getKey(),
cert: await TestConfigUtils.getCert(),
cuit: testCuit,
}).registerScopeFiveService;

registerScopeFiveService.getWsAuth = jest.fn().mockReturnValue({
Auth: {
Token: mockLoginCredentials.credentials.token,
Sign: mockLoginCredentials.credentials.sign,
Cuit: testCuit,
},
});

const afipMockParams = {
dummyAsync: jest.fn().mockResolvedValue(dummyAsyncReturnMocks),
getPersona_v2Async: jest
.fn()
.mockResolvedValue(getPersona_v2AsyncReturnMocks),
getPersonaList_v2Async: jest
.fn()
.mockResolvedValue(getPersonaList_v2AsyncReturnMocks),
} as any;

jest
.spyOn(registerScopeFiveService, "getClient")
.mockReturnValue(afipMockParams);
});

afterEach(() => {
jest.clearAllMocks();
});

it("should get server status", async () => {
const status = await registerScopeFiveService.getServerStatus();
expect(status).toEqual(dummyAsyncReturnMocks[0]);
});

it("should get taxpayer details", async () => {
const details = await registerScopeFiveService.getTaxpayerDetails(
cuitPayload
);
expect(details).toStrictEqual(
getPersona_v2AsyncReturnMocks[0].personaReturn
);
});

it("should get taxpayers details", async () => {
const details = await registerScopeFiveService.getTaxpayersDetails([
cuitPayload,
cuitPayload,
]);
expect(details).toStrictEqual(
getPersonaList_v2AsyncReturnMocks[0].personaListReturn
);
});
});
Loading

0 comments on commit 33f2029

Please sign in to comment.