diff --git a/docs/services/consulta_padron_alcance_13.md b/docs/services/consulta_padron_alcance_13.md index 494691f..bcf3fb2 100644 --- a/docs/services/consulta_padron_alcance_13.md +++ b/docs/services/consulta_padron_alcance_13.md @@ -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) @@ -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 ``` @@ -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); diff --git a/src/afip.ts b/src/afip.ts index 900e3e9..dd1ff38 100644 --- a/src/afip.ts +++ b/src/afip.ts @@ -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) { @@ -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 ); } @@ -47,8 +47,8 @@ export class Afip { return this._registerScopeTenService; } - get registerScopeTThirteenService(): RegisterScopeThirteenService { - return this._registerScopeTThirteenService; + get registerScopeThirteenService(): RegisterScopeThirteenService { + return this._registerScopeThirteenService; } public genericService( diff --git a/src/services/register-scope-five.service.ts b/src/services/register-scope-five.service.ts index ca50a5c..14e23aa 100644 --- a/src/services/register-scope-five.service.ts +++ b/src/services/register-scope-five.service.ts @@ -59,7 +59,7 @@ export class RegisterScopeFiveService extends AfipService { const client = await this.getClient(); const { Auth } = await this.getWsAuth(); @@ -67,7 +67,7 @@ export class RegisterScopeFiveService extends AfipService { describe("getSign", () => { diff --git a/tests/mocks/data/soapClient.mock.ts b/tests/mocks/data/soapClient.mock.ts index 70f07ec..ba96876 100644 --- a/tests/mocks/data/soapClient.mock.ts +++ b/tests/mocks/data/soapClient.mock.ts @@ -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", + }, + }, + }, +]; diff --git a/tests/mocks/data/voucher.mock.ts b/tests/mocks/data/voucher.mock.ts index 32c04ae..a3f3b45 100644 --- a/tests/mocks/data/voucher.mock.ts +++ b/tests/mocks/data/voucher.mock.ts @@ -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; diff --git a/tests/services/register-scope-five.service.test.ts b/tests/services/register-scope-five.service.test.ts new file mode 100644 index 0000000..2253cff --- /dev/null +++ b/tests/services/register-scope-five.service.test.ts @@ -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 + ); + }); +}); diff --git a/tests/services/register-scope-four.service.test.ts b/tests/services/register-scope-four.service.test.ts new file mode 100644 index 0000000..b41c351 --- /dev/null +++ b/tests/services/register-scope-four.service.test.ts @@ -0,0 +1,68 @@ +import { testCuit } from "../mocks/data/voucher.mock"; +import { Afip } from "../../src/afip"; +import { TestConfigUtils } from "../utils/config.utils"; +import { + scopeFourDummyAsyncReturnMocks, + scopeFourGetPersonaAsyncReturnMocks, +} from "../mocks/data/soapClient.mock"; +import { mockLoginCredentials } from "../mocks/data/credential-json.mock"; +import { RegisterScopeFourService } from "../../src/services/register-scope-four.service"; + +describe("Register Scope Four Service", () => { + const originalNodeTlsRejectUnauthStatus = + process.env.NODE_TLS_REJECT_UNAUTHORIZED; + let registerScopeFourService: RegisterScopeFourService; + const cuitPayload = 20111111111; + + beforeAll(() => { + process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; + }); + + afterAll(() => { + process.env.NODE_TLS_REJECT_UNAUTHORIZED = + originalNodeTlsRejectUnauthStatus; + }); + + beforeEach(async () => { + registerScopeFourService = new Afip({ + key: await TestConfigUtils.getKey(), + cert: await TestConfigUtils.getCert(), + cuit: testCuit, + }).registerScopeFourService; + + registerScopeFourService.getWsAuth = jest.fn().mockReturnValue({ + Auth: { + Token: mockLoginCredentials.credentials.token, + Sign: mockLoginCredentials.credentials.sign, + Cuit: testCuit, + }, + }); + + const afipMockParams = { + dummyAsync: jest.fn().mockResolvedValue(scopeFourDummyAsyncReturnMocks), + getPersonaAsync: jest + .fn() + .mockResolvedValue(scopeFourGetPersonaAsyncReturnMocks), + } as any; + + jest + .spyOn(registerScopeFourService, "getClient") + .mockReturnValue(afipMockParams); + }); + + afterEach(() => { + jest.clearAllMocks(); + }); + + it("should get server status", async () => { + expect(await registerScopeFourService.getServerStatus()).toEqual( + scopeFourDummyAsyncReturnMocks[0] + ); + }); + + it("should get taxpayer details", async () => { + expect( + await registerScopeFourService.getTaxpayerDetails(cuitPayload) + ).toStrictEqual(scopeFourGetPersonaAsyncReturnMocks[0].personaReturn); + }); +}); diff --git a/tests/services/register-scope-ten.service.test.ts b/tests/services/register-scope-ten.service.test.ts new file mode 100644 index 0000000..dccb212 --- /dev/null +++ b/tests/services/register-scope-ten.service.test.ts @@ -0,0 +1,68 @@ +import { testCuit } from "../mocks/data/voucher.mock"; +import { Afip } from "../../src/afip"; +import { TestConfigUtils } from "../utils/config.utils"; +import { mockLoginCredentials } from "../mocks/data/credential-json.mock"; +import { RegisterScopeTenService } from "../../src/services/register-scope-ten.service"; +import { + scopeTenDummyAsyncReturnMocks, + scopeTenGetPersonaAsyncReturnMocks, +} from "../mocks/data/soapClient.mock"; + +describe("Register Scope Ten Service", () => { + const originalNodeTlsRejectUnauthStatus = + process.env.NODE_TLS_REJECT_UNAUTHORIZED; + let registerScopeTenService: RegisterScopeTenService; + const cuitPayload = 20111111111; + + beforeAll(() => { + process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; + }); + + afterAll(() => { + process.env.NODE_TLS_REJECT_UNAUTHORIZED = + originalNodeTlsRejectUnauthStatus; + }); + + beforeEach(async () => { + registerScopeTenService = new Afip({ + key: await TestConfigUtils.getKey(), + cert: await TestConfigUtils.getCert(), + cuit: testCuit, + }).registerScopeTenService; + + registerScopeTenService.getWsAuth = jest.fn().mockReturnValue({ + Auth: { + Token: mockLoginCredentials.credentials.token, + Sign: mockLoginCredentials.credentials.sign, + Cuit: testCuit, + }, + }); + + const afipMockParams = { + dummyAsync: jest.fn().mockResolvedValue(scopeTenDummyAsyncReturnMocks), + getPersonaAsync: jest + .fn() + .mockResolvedValue(scopeTenGetPersonaAsyncReturnMocks), + } as any; + + jest + .spyOn(registerScopeTenService, "getClient") + .mockReturnValue(afipMockParams); + }); + + afterEach(() => { + jest.clearAllMocks(); + }); + + it("should get server status", async () => { + expect(await registerScopeTenService.getServerStatus()).toEqual( + scopeTenDummyAsyncReturnMocks[0] + ); + }); + + it("should get taxpayer details", async () => { + expect( + await registerScopeTenService.getTaxpayerDetails(cuitPayload) + ).toStrictEqual(scopeTenGetPersonaAsyncReturnMocks[0].personaReturn); + }); +}); diff --git a/tests/services/register-scope-thirteen.service.test.ts b/tests/services/register-scope-thirteen.service.test.ts new file mode 100644 index 0000000..619fb2d --- /dev/null +++ b/tests/services/register-scope-thirteen.service.test.ts @@ -0,0 +1,70 @@ +import { testCuit } from "../mocks/data/voucher.mock"; +import { Afip } from "../../src/afip"; +import { TestConfigUtils } from "../utils/config.utils"; +import { mockLoginCredentials } from "../mocks/data/credential-json.mock"; +import { RegisterScopeThirteenService } from "../../src/services/register-scope-thirteen.service"; +import { + scopeThirteenDummyAsyncReturnMocks, + scopeThirteenGetPersonaAsyncReturnMocks, +} from "../mocks/data/soapClient.mock"; + +describe("Register Scope Thirteen Service", () => { + const originalNodeTlsRejectUnauthStatus = + process.env.NODE_TLS_REJECT_UNAUTHORIZED; + let registerScopeThirteenService: RegisterScopeThirteenService; + const cuitPayload = 20111111111; + + beforeAll(() => { + process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; + }); + + afterAll(() => { + process.env.NODE_TLS_REJECT_UNAUTHORIZED = + originalNodeTlsRejectUnauthStatus; + }); + + beforeEach(async () => { + registerScopeThirteenService = new Afip({ + key: await TestConfigUtils.getKey(), + cert: await TestConfigUtils.getCert(), + cuit: testCuit, + }).registerScopeThirteenService; + + registerScopeThirteenService.getWsAuth = jest.fn().mockReturnValue({ + Auth: { + Token: mockLoginCredentials.credentials.token, + Sign: mockLoginCredentials.credentials.sign, + Cuit: testCuit, + }, + }); + + const afipMockParams = { + dummyAsync: jest + .fn() + .mockResolvedValue(scopeThirteenDummyAsyncReturnMocks), + getPersonaAsync: jest + .fn() + .mockResolvedValue(scopeThirteenGetPersonaAsyncReturnMocks), + } as any; + + jest + .spyOn(registerScopeThirteenService, "getClient") + .mockReturnValue(afipMockParams); + }); + + afterEach(() => { + jest.clearAllMocks(); + }); + + it("should get server status", async () => { + expect(await registerScopeThirteenService.getServerStatus()).toEqual( + scopeThirteenDummyAsyncReturnMocks[0] + ); + }); + + it("should get taxpayer details", async () => { + expect( + await registerScopeThirteenService.getTaxpayerDetails(cuitPayload) + ).toStrictEqual(scopeThirteenGetPersonaAsyncReturnMocks[0].personaReturn); + }); +}); diff --git a/tests/utils/config.utils.ts b/tests/utils/config.utils.ts index f388d6a..c7ba6bb 100644 --- a/tests/utils/config.utils.ts +++ b/tests/utils/config.utils.ts @@ -2,7 +2,7 @@ import { resolve } from "path"; import { readFileSync } from "fs"; import { config } from "dotenv"; import { promises as fs } from "fs"; -import EnvTest from "../env-test"; +import EnvTest from "../utils/env-test"; config(); export class TestConfigUtils { diff --git a/tests/env-test.ts b/tests/utils/env-test.ts similarity index 94% rename from tests/env-test.ts rename to tests/utils/env-test.ts index 58bcc27..8869fe6 100644 --- a/tests/env-test.ts +++ b/tests/utils/env-test.ts @@ -1,4 +1,4 @@ -import { Environment } from "../src/utils/env"; +import { Environment } from "../../src/utils/env"; class EnvirnonmentTest extends Environment { cuit: string;