From 37d4bbfd29d40b9a6bb632ed09473ce6fdaa8a2c Mon Sep 17 00:00:00 2001 From: Rodrigo Alcorta Date: Mon, 2 Oct 2023 16:33:03 -0300 Subject: [PATCH 1/4] test: base test for scope five service --- .../PersonaServiceA5/PersonaServiceA5Port.ts | 1 + tests/auth/access-ticket.test.ts | 2 +- tests/mocks/data/soapClient.mock.ts | 6 +++ tests/mocks/data/voucher.mock.ts | 2 +- .../register-scope-five.service.test.ts | 54 +++++++++++++++++++ tests/utils/config.utils.ts | 2 +- tests/{ => utils}/env-test.ts | 2 +- 7 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 tests/services/register-scope-five.service.test.ts rename tests/{ => utils}/env-test.ts (94%) diff --git a/src/soap/interfaces/PersonaServiceA5/PersonaServiceA5Port.ts b/src/soap/interfaces/PersonaServiceA5/PersonaServiceA5Port.ts index 7dee488..1dd693d 100644 --- a/src/soap/interfaces/PersonaServiceA5/PersonaServiceA5Port.ts +++ b/src/soap/interfaces/PersonaServiceA5/PersonaServiceA5Port.ts @@ -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 */ diff --git a/tests/auth/access-ticket.test.ts b/tests/auth/access-ticket.test.ts index d62ecf2..b6d6c42 100644 --- a/tests/auth/access-ticket.test.ts +++ b/tests/auth/access-ticket.test.ts @@ -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", () => { diff --git a/tests/mocks/data/soapClient.mock.ts b/tests/mocks/data/soapClient.mock.ts index 70f07ec..0083dd0 100644 --- a/tests/mocks/data/soapClient.mock.ts +++ b/tests/mocks/data/soapClient.mock.ts @@ -1105,3 +1105,9 @@ export const FEParamGetTiposTributosAsyncReturnMocks = [ }, }, ]; + +export const dummyAsyncReturnMocks = [ + { + return: { appserver: "OK", authserver: "OK", dbserver: "OK" }, + }, +]; 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..cc851ed --- /dev/null +++ b/tests/services/register-scope-five.service.test.ts @@ -0,0 +1,54 @@ +import { testCuit } from "../mocks/data/voucher.mock"; +import { Afip } from "../../src/afip"; +import { TestConfigUtils } from "../utils/config.utils"; +import { dummyAsyncReturnMocks } from "../mocks/data/soapClient.mock"; + +describe("Register Scope Five Service", () => { + let afip: Afip; + const originalNodeTlsRejectUnauthStatus = + process.env.NODE_TLS_REJECT_UNAUTHORIZED; + + beforeAll(() => { + process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; + }); + + afterAll(() => { + process.env.NODE_TLS_REJECT_UNAUTHORIZED = + originalNodeTlsRejectUnauthStatus; + }); + + beforeEach(async () => { + afip = new Afip({ + key: await TestConfigUtils.getKey(), + cert: await TestConfigUtils.getCert(), + cuit: testCuit, + }); + + // const afipMockParams = { + // dummyAsync: jest.fn().mockResolvedValue(dummyAsyncReturnMocks), + // } as any; + + // jest + // .spyOn(afip.electronicBillingService, "getClient") + // .mockReturnValue(afipMockParams); + }); + + afterEach(() => { + jest.clearAllMocks(); + }); + + it("should get server status", async () => { + const { registerScopeFiveService } = afip; + const status = await registerScopeFiveService.getServerStatus(); + expect(status).toEqual(dummyAsyncReturnMocks[0]); + }); + + it("should get taxpayer details", async () => { + const { registerScopeFiveService } = afip; + const details = await registerScopeFiveService.getTaxpayerDetails( + 20111111111 + ); + console.dir(details, { depth: 50 }); + expect(details).toBeDefined(); + }); +}); 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; From b41ba3c5deeb9b79c2a04507b051ca83d1bd9897 Mon Sep 17 00:00:00 2001 From: Rodrigo Alcorta Date: Mon, 2 Oct 2023 19:40:12 -0300 Subject: [PATCH 2/4] test: register scope five service with tests --- src/services/register-scope-five.service.ts | 4 +- .../PersonaServiceA5/PersonaServiceA5Port.ts | 2 +- tests/mocks/data/soapClient.mock.ts | 40 ++++++++++++++ .../register-scope-five.service.test.ts | 55 ++++++++++++++----- 4 files changed, 85 insertions(+), 16 deletions(-) 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 { let afip: Afip; const originalNodeTlsRejectUnauthStatus = process.env.NODE_TLS_REJECT_UNAUTHORIZED; + let registerScopeFiveService: RegisterScopeFiveService; beforeAll(() => { process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; @@ -18,19 +25,33 @@ describe("Register Scope Five Service", () => { }); beforeEach(async () => { - afip = new Afip({ + 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), - // } as any; + 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(afip.electronicBillingService, "getClient") - // .mockReturnValue(afipMockParams); + jest + .spyOn(registerScopeFiveService, "getClient") + .mockReturnValue(afipMockParams); }); afterEach(() => { @@ -38,17 +59,25 @@ describe("Register Scope Five Service", () => { }); it("should get server status", async () => { - const { registerScopeFiveService } = afip; const status = await registerScopeFiveService.getServerStatus(); expect(status).toEqual(dummyAsyncReturnMocks[0]); }); it("should get taxpayer details", async () => { - const { registerScopeFiveService } = afip; const details = await registerScopeFiveService.getTaxpayerDetails( 20111111111 ); - console.dir(details, { depth: 50 }); - expect(details).toBeDefined(); + expect(details).toStrictEqual( + getPersona_v2AsyncReturnMocks[0].personaReturn + ); + }); + + it("should get taxpayer details", async () => { + const details = await registerScopeFiveService.getTaxpayersDetails([ + 20111111111, 20111111111, + ]); + expect(details).toStrictEqual( + getPersonaList_v2AsyncReturnMocks[0].personaListReturn + ); }); }); From 5a15a283be9f15127f15b5c68c7dca26c0ac74e7 Mon Sep 17 00:00:00 2001 From: Rodrigo Alcorta Date: Tue, 3 Oct 2023 08:44:08 -0300 Subject: [PATCH 3/4] fix: thirteen service method typo fixed with new test for other services --- .../.vuepress/dist/assets/js/14.0b212dd3.js | 444 +++++++++++++- ...Consulta-al-padron-de-AFIP-alcance-13.html | 553 ++++++++++++++++-- .../Consulta-al-padron-de-AFIP-alcance-13.md | 8 +- docs/services/consulta_padron_alcance_13.md | 6 +- src/afip.ts | 8 +- tests/mocks/data/soapClient.mock.ts | 139 +++++ .../register-scope-five.service.test.ts | 9 +- 7 files changed, 1110 insertions(+), 57 deletions(-) diff --git a/docs-old/.vuepress/dist/assets/js/14.0b212dd3.js b/docs-old/.vuepress/dist/assets/js/14.0b212dd3.js index 1e3aa09..01eb5a0 100644 --- a/docs-old/.vuepress/dist/assets/js/14.0b212dd3.js +++ b/docs-old/.vuepress/dist/assets/js/14.0b212dd3.js @@ -1 +1,443 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[14],{284:function(e,t,a){"use strict";a.r(t);var s=a(14),n=Object(s.a)({},(function(){var e=this,t=e._self._c;return t("ContentSlotsDistributor",{attrs:{"slot-key":e.$parent.slotKey}},[t("h1",{attrs:{id:"padron-de-afip-alcance-13"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#padron-de-afip-alcance-13"}},[e._v("#")]),e._v(" Padrón de AFIP alcance 13")]),e._v(" "),t("p",[e._v("Los métodos de este Web Service se encuentran disponibles en "),t("code",[e._v("afip.registerScopeTThirteenService")])]),e._v(" "),t("p",[e._v("La especificación de este Web Service se encuentra disponible en http://www.afip.gob.ar/ws/ws-padron-a13/manual-ws-sr-padron-a13-v1.2.pdf")]),e._v(" "),t("h3",{attrs:{id:"metodos-disponibles"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#metodos-disponibles"}},[e._v("#")]),e._v(" Métodos disponibles")]),e._v(" "),t("ol",[t("li",[t("a",{attrs:{href:"#obtener-datos-del-contribuyente"}},[e._v("Obtener datos del contribuyente "),t("em",[e._v("(getPersona)")])])]),e._v(" "),t("li",[t("a",{attrs:{href:"#obtener-cuit-a-partir-de-un-dni"}},[e._v("Obtener CUIT a partir de un DNI")])]),e._v(" "),t("li",[t("a",{attrs:{href:"#obtener-estado-del-servidor"}},[e._v("Obtener estado del servidor")])])]),e._v(" "),t("h2",{attrs:{id:"obtener-datos-del-contribuyente"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#obtener-datos-del-contribuyente"}},[e._v("#")]),e._v(" Obtener datos del contribuyente")]),e._v(" "),t("p",[e._v("Debemos utilizar el metodo "),t("code",[e._v("getTaxpayerDetails")]),e._v(" pasando como parámetro el documento identificador del contribuyente, por ej. el CUIT. Nos devolvera un objeto con los detalles o "),t("code",[e._v("null")]),e._v(" en caso de no existir en el padrón")]),e._v(" "),t("div",{staticClass:"language-js extra-class"},[t("pre",{pre:!0,attrs:{class:"language-js"}},[t("code",[t("span",{pre:!0,attrs:{class:"token keyword"}},[e._v("const")]),e._v(" taxpayerDetails "),t("span",{pre:!0,attrs:{class:"token operator"}},[e._v("=")]),e._v("\n "),t("span",{pre:!0,attrs:{class:"token keyword"}},[e._v("await")]),e._v(" afip"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v(".")]),e._v("registerScopeTThirteenService"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v(".")]),t("span",{pre:!0,attrs:{class:"token function"}},[e._v("getTaxpayerDetails")]),t("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v("(")]),t("span",{pre:!0,attrs:{class:"token number"}},[e._v("20111111111")]),t("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v(")")]),t("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v(";")]),e._v(" "),t("span",{pre:!0,attrs:{class:"token comment"}},[e._v("//Devuelve los datos del contribuyente correspondiente al identificador 20111111111")]),e._v("\n")])])]),t("p",[e._v("Para mas información acerca de este método ver el item 3.2 de la "),t("a",{attrs:{href:"http://www.afip.gob.ar/ws/ws-padron-a13/manual-ws-sr-padron-a13-v1.2.pdf",target:"_blank",rel:"noopener noreferrer"}},[e._v("especificación del Web service"),t("OutboundLink")],1)]),e._v(" "),t("h2",{attrs:{id:"obtener-cuit-a-partir-de-un-dni"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#obtener-cuit-a-partir-de-un-dni"}},[e._v("#")]),e._v(" Obtener CUIT a partir de un DNI")]),e._v(" "),t("p",[e._v("Debemos utilizar el metodo "),t("code",[e._v("getTaxIDByDocument")]),e._v(" pasando como parámetro el DNI del contribuyente. Nos devolverá el CUIT o "),t("code",[e._v("null")]),e._v(" en caso de no existir en el padrón")]),e._v(" "),t("div",{staticClass:"language-js extra-class"},[t("pre",{pre:!0,attrs:{class:"language-js"}},[t("code",[t("span",{pre:!0,attrs:{class:"token keyword"}},[e._v("const")]),e._v(" taxID "),t("span",{pre:!0,attrs:{class:"token operator"}},[e._v("=")]),e._v(" "),t("span",{pre:!0,attrs:{class:"token keyword"}},[e._v("await")]),e._v(" afip"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v(".")]),e._v("registerScopeTThirteenService"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v(".")]),t("span",{pre:!0,attrs:{class:"token function"}},[e._v("getTaxIDByDocument")]),t("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v("(")]),e._v("\n "),t("span",{pre:!0,attrs:{class:"token number"}},[e._v("11111111")]),e._v("\n"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v(")")]),t("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v(";")]),e._v(" "),t("span",{pre:!0,attrs:{class:"token comment"}},[e._v("//Devuelve el CUIT correspondiente al DNI 11111111")]),e._v("\n")])])]),t("h2",{attrs:{id:"obtener-estado-del-servidor"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#obtener-estado-del-servidor"}},[e._v("#")]),e._v(" Obtener estado del servidor")]),e._v(" "),t("p",[e._v("Para esto utilizaremos el método "),t("code",[e._v("getServerStatus")])]),e._v(" "),t("div",{staticClass:"language-js extra-class"},[t("pre",{pre:!0,attrs:{class:"language-js"}},[t("code",[t("span",{pre:!0,attrs:{class:"token keyword"}},[e._v("const")]),e._v(" serverStatus "),t("span",{pre:!0,attrs:{class:"token operator"}},[e._v("=")]),e._v(" "),t("span",{pre:!0,attrs:{class:"token keyword"}},[e._v("await")]),e._v(" afip"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v(".")]),e._v("registerScopeTThirteenService"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v(".")]),t("span",{pre:!0,attrs:{class:"token function"}},[e._v("getServerStatus")]),t("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v("(")]),t("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v(")")]),t("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v(";")]),e._v("\n\nconsole"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v(".")]),t("span",{pre:!0,attrs:{class:"token function"}},[e._v("log")]),t("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v("(")]),t("span",{pre:!0,attrs:{class:"token string"}},[e._v('"Este es el estado del servidor:"')]),t("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v(")")]),t("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v(";")]),e._v("\nconsole"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v(".")]),t("span",{pre:!0,attrs:{class:"token function"}},[e._v("log")]),t("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v("(")]),e._v("serverStatus"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v(")")]),t("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v(";")]),e._v("\n")])])]),t("p",[e._v("Para mas información acerca de este método ver el item 3.1 de la "),t("a",{attrs:{href:"http://www.afip.gob.ar/ws/ws-padron-a13/manual-ws-sr-padron-a13-v1.2.pdf",target:"_blank",rel:"noopener noreferrer"}},[e._v("especificación del Web service"),t("OutboundLink")],1)])])}),[],!1,null,null,null);t.default=n.exports}}]); \ No newline at end of file +(window.webpackJsonp = window.webpackJsonp || []).push([ + [14], + { + 284: function (e, t, a) { + "use strict"; + a.r(t); + var s = a(14), + n = Object(s.a)( + {}, + function () { + var e = this, + t = e._self._c; + return t( + "ContentSlotsDistributor", + { attrs: { "slot-key": e.$parent.slotKey } }, + [ + t("h1", { attrs: { id: "padron-de-afip-alcance-13" } }, [ + t( + "a", + { + staticClass: "header-anchor", + attrs: { href: "#padron-de-afip-alcance-13" }, + }, + [e._v("#")] + ), + e._v(" Padrón de AFIP alcance 13"), + ]), + e._v(" "), + t("p", [ + e._v( + "Los métodos de este Web Service se encuentran disponibles en " + ), + t("code", [e._v("afip.registerScopeThirteenService")]), + ]), + e._v(" "), + t("p", [ + e._v( + "La especificación de este Web Service se encuentra disponible en http://www.afip.gob.ar/ws/ws-padron-a13/manual-ws-sr-padron-a13-v1.2.pdf" + ), + ]), + e._v(" "), + t("h3", { attrs: { id: "metodos-disponibles" } }, [ + t( + "a", + { + staticClass: "header-anchor", + attrs: { href: "#metodos-disponibles" }, + }, + [e._v("#")] + ), + e._v(" Métodos disponibles"), + ]), + e._v(" "), + t("ol", [ + t("li", [ + t( + "a", + { attrs: { href: "#obtener-datos-del-contribuyente" } }, + [ + e._v("Obtener datos del contribuyente "), + t("em", [e._v("(getPersona)")]), + ] + ), + ]), + e._v(" "), + t("li", [ + t( + "a", + { attrs: { href: "#obtener-cuit-a-partir-de-un-dni" } }, + [e._v("Obtener CUIT a partir de un DNI")] + ), + ]), + e._v(" "), + t("li", [ + t( + "a", + { attrs: { href: "#obtener-estado-del-servidor" } }, + [e._v("Obtener estado del servidor")] + ), + ]), + ]), + e._v(" "), + t("h2", { attrs: { id: "obtener-datos-del-contribuyente" } }, [ + t( + "a", + { + staticClass: "header-anchor", + attrs: { href: "#obtener-datos-del-contribuyente" }, + }, + [e._v("#")] + ), + e._v(" Obtener datos del contribuyente"), + ]), + e._v(" "), + t("p", [ + e._v("Debemos utilizar el metodo "), + t("code", [e._v("getTaxpayerDetails")]), + e._v( + " pasando como parámetro el documento identificador del contribuyente, por ej. el CUIT. Nos devolvera un objeto con los detalles o " + ), + t("code", [e._v("null")]), + e._v(" en caso de no existir en el padrón"), + ]), + e._v(" "), + t("div", { staticClass: "language-js extra-class" }, [ + t("pre", { pre: !0, attrs: { class: "language-js" } }, [ + t("code", [ + t( + "span", + { pre: !0, attrs: { class: "token keyword" } }, + [e._v("const")] + ), + e._v(" taxpayerDetails "), + t( + "span", + { pre: !0, attrs: { class: "token operator" } }, + [e._v("=")] + ), + e._v("\n "), + t( + "span", + { pre: !0, attrs: { class: "token keyword" } }, + [e._v("await")] + ), + e._v(" afip"), + t( + "span", + { pre: !0, attrs: { class: "token punctuation" } }, + [e._v(".")] + ), + e._v("registerScopeThirteenService"), + t( + "span", + { pre: !0, attrs: { class: "token punctuation" } }, + [e._v(".")] + ), + t( + "span", + { pre: !0, attrs: { class: "token function" } }, + [e._v("getTaxpayerDetails")] + ), + t( + "span", + { pre: !0, attrs: { class: "token punctuation" } }, + [e._v("(")] + ), + t("span", { pre: !0, attrs: { class: "token number" } }, [ + e._v("20111111111"), + ]), + t( + "span", + { pre: !0, attrs: { class: "token punctuation" } }, + [e._v(")")] + ), + t( + "span", + { pre: !0, attrs: { class: "token punctuation" } }, + [e._v(";")] + ), + e._v(" "), + t( + "span", + { pre: !0, attrs: { class: "token comment" } }, + [ + e._v( + "//Devuelve los datos del contribuyente correspondiente al identificador 20111111111" + ), + ] + ), + e._v("\n"), + ]), + ]), + ]), + t("p", [ + e._v( + "Para mas información acerca de este método ver el item 3.2 de la " + ), + t( + "a", + { + attrs: { + href: "http://www.afip.gob.ar/ws/ws-padron-a13/manual-ws-sr-padron-a13-v1.2.pdf", + target: "_blank", + rel: "noopener noreferrer", + }, + }, + [e._v("especificación del Web service"), t("OutboundLink")], + 1 + ), + ]), + e._v(" "), + t("h2", { attrs: { id: "obtener-cuit-a-partir-de-un-dni" } }, [ + t( + "a", + { + staticClass: "header-anchor", + attrs: { href: "#obtener-cuit-a-partir-de-un-dni" }, + }, + [e._v("#")] + ), + e._v(" Obtener CUIT a partir de un DNI"), + ]), + e._v(" "), + t("p", [ + e._v("Debemos utilizar el metodo "), + t("code", [e._v("getTaxIDByDocument")]), + e._v( + " pasando como parámetro el DNI del contribuyente. Nos devolverá el CUIT o " + ), + t("code", [e._v("null")]), + e._v(" en caso de no existir en el padrón"), + ]), + e._v(" "), + t("div", { staticClass: "language-js extra-class" }, [ + t("pre", { pre: !0, attrs: { class: "language-js" } }, [ + t("code", [ + t( + "span", + { pre: !0, attrs: { class: "token keyword" } }, + [e._v("const")] + ), + e._v(" taxID "), + t( + "span", + { pre: !0, attrs: { class: "token operator" } }, + [e._v("=")] + ), + e._v(" "), + t( + "span", + { pre: !0, attrs: { class: "token keyword" } }, + [e._v("await")] + ), + e._v(" afip"), + t( + "span", + { pre: !0, attrs: { class: "token punctuation" } }, + [e._v(".")] + ), + e._v("registerScopeThirteenService"), + t( + "span", + { pre: !0, attrs: { class: "token punctuation" } }, + [e._v(".")] + ), + t( + "span", + { pre: !0, attrs: { class: "token function" } }, + [e._v("getTaxIDByDocument")] + ), + t( + "span", + { pre: !0, attrs: { class: "token punctuation" } }, + [e._v("(")] + ), + e._v("\n "), + t("span", { pre: !0, attrs: { class: "token number" } }, [ + e._v("11111111"), + ]), + e._v("\n"), + t( + "span", + { pre: !0, attrs: { class: "token punctuation" } }, + [e._v(")")] + ), + t( + "span", + { pre: !0, attrs: { class: "token punctuation" } }, + [e._v(";")] + ), + e._v(" "), + t( + "span", + { pre: !0, attrs: { class: "token comment" } }, + [ + e._v( + "//Devuelve el CUIT correspondiente al DNI 11111111" + ), + ] + ), + e._v("\n"), + ]), + ]), + ]), + t("h2", { attrs: { id: "obtener-estado-del-servidor" } }, [ + t( + "a", + { + staticClass: "header-anchor", + attrs: { href: "#obtener-estado-del-servidor" }, + }, + [e._v("#")] + ), + e._v(" Obtener estado del servidor"), + ]), + e._v(" "), + t("p", [ + e._v("Para esto utilizaremos el método "), + t("code", [e._v("getServerStatus")]), + ]), + e._v(" "), + t("div", { staticClass: "language-js extra-class" }, [ + t("pre", { pre: !0, attrs: { class: "language-js" } }, [ + t("code", [ + t( + "span", + { pre: !0, attrs: { class: "token keyword" } }, + [e._v("const")] + ), + e._v(" serverStatus "), + t( + "span", + { pre: !0, attrs: { class: "token operator" } }, + [e._v("=")] + ), + e._v(" "), + t( + "span", + { pre: !0, attrs: { class: "token keyword" } }, + [e._v("await")] + ), + e._v(" afip"), + t( + "span", + { pre: !0, attrs: { class: "token punctuation" } }, + [e._v(".")] + ), + e._v("registerScopeThirteenService"), + t( + "span", + { pre: !0, attrs: { class: "token punctuation" } }, + [e._v(".")] + ), + t( + "span", + { pre: !0, attrs: { class: "token function" } }, + [e._v("getServerStatus")] + ), + t( + "span", + { pre: !0, attrs: { class: "token punctuation" } }, + [e._v("(")] + ), + t( + "span", + { pre: !0, attrs: { class: "token punctuation" } }, + [e._v(")")] + ), + t( + "span", + { pre: !0, attrs: { class: "token punctuation" } }, + [e._v(";")] + ), + e._v("\n\nconsole"), + t( + "span", + { pre: !0, attrs: { class: "token punctuation" } }, + [e._v(".")] + ), + t( + "span", + { pre: !0, attrs: { class: "token function" } }, + [e._v("log")] + ), + t( + "span", + { pre: !0, attrs: { class: "token punctuation" } }, + [e._v("(")] + ), + t("span", { pre: !0, attrs: { class: "token string" } }, [ + e._v('"Este es el estado del servidor:"'), + ]), + t( + "span", + { pre: !0, attrs: { class: "token punctuation" } }, + [e._v(")")] + ), + t( + "span", + { pre: !0, attrs: { class: "token punctuation" } }, + [e._v(";")] + ), + e._v("\nconsole"), + t( + "span", + { pre: !0, attrs: { class: "token punctuation" } }, + [e._v(".")] + ), + t( + "span", + { pre: !0, attrs: { class: "token function" } }, + [e._v("log")] + ), + t( + "span", + { pre: !0, attrs: { class: "token punctuation" } }, + [e._v("(")] + ), + e._v("serverStatus"), + t( + "span", + { pre: !0, attrs: { class: "token punctuation" } }, + [e._v(")")] + ), + t( + "span", + { pre: !0, attrs: { class: "token punctuation" } }, + [e._v(";")] + ), + e._v("\n"), + ]), + ]), + ]), + t("p", [ + e._v( + "Para mas información acerca de este método ver el item 3.1 de la " + ), + t( + "a", + { + attrs: { + href: "http://www.afip.gob.ar/ws/ws-padron-a13/manual-ws-sr-padron-a13-v1.2.pdf", + target: "_blank", + rel: "noopener noreferrer", + }, + }, + [e._v("especificación del Web service"), t("OutboundLink")], + 1 + ), + ]), + ] + ); + }, + [], + !1, + null, + null, + null + ); + t.default = n.exports; + }, + }, +]); diff --git a/docs-old/.vuepress/dist/guide/Consulta-al-padron-de-AFIP-alcance-13.html b/docs-old/.vuepress/dist/guide/Consulta-al-padron-de-AFIP-alcance-13.html index 3666dbc..5f7be3e 100644 --- a/docs-old/.vuepress/dist/guide/Consulta-al-padron-de-AFIP-alcance-13.html +++ b/docs-old/.vuepress/dist/guide/Consulta-al-padron-de-AFIP-alcance-13.html @@ -1,54 +1,525 @@ - - + + Padrón de AFIP alcance 13 | Afip.ts - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -

# Padrón de AFIP alcance 13

Los métodos de este Web Service se encuentran disponibles en afip.registerScopeTThirteenService

La especificación de este Web Service se encuentra disponible en http://www.afip.gob.ar/ws/ws-padron-a13/manual-ws-sr-padron-a13-v1.2.pdf

# Métodos disponibles

  1. Obtener datos del contribuyente (getPersona)
  2. Obtener CUIT a partir de un DNI
  3. Obtener estado del servidor

# Obtener datos del contribuyente

Debemos utilizar el metodo getTaxpayerDetails pasando como parámetro el documento identificador del contribuyente, por ej. el CUIT. Nos devolvera un objeto con los detalles o null en caso de no existir en el padrón

const taxpayerDetails =
-  await afip.registerScopeTThirteenService.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 (opens new window)

# Obtener CUIT a partir de un DNI

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

const taxID = await afip.registerScopeTThirteenService.getTaxIDByDocument(
+    
+
+ + + +
+
+

+ # + Padrón de AFIP alcance 13 +

+

+ Los métodos de este Web Service se encuentran disponibles en + afip.registerScopeThirteenService +

+

+ La especificación de este Web Service se encuentra disponible en + http://www.afip.gob.ar/ws/ws-padron-a13/manual-ws-sr-padron-a13-v1.2.pdf +

+

+ # Métodos + disponibles +

+
    +
  1. + Obtener datos del contribuyente (getPersona) +
  2. +
  3. + Obtener CUIT a partir de un DNI +
  4. +
  5. + Obtener estado del servidor +
  6. +
+

+ # + Obtener datos del contribuyente +

+

+ Debemos utilizar el metodo getTaxpayerDetails pasando + como parámetro el documento identificador del contribuyente, por + ej. el CUIT. Nos devolvera un objeto con los detalles o + null en caso de no existir en el padrón +

+
+
const taxpayerDetails =
+  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 + (opens new window) +

+

+ # + Obtener CUIT a partir de un DNI +

+

+ 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 +

+
+
const taxID = await afip.registerScopeThirteenService.getTaxIDByDocument(
   11111111
 ); //Devuelve el CUIT correspondiente al DNI 11111111
-

# Obtener estado del servidor

Para esto utilizaremos el método getServerStatus

const serverStatus = await afip.registerScopeTThirteenService.getServerStatus();
+
+
+

+ # + Obtener estado del servidor +

+

Para esto utilizaremos el método getServerStatus

+
+
const serverStatus = await afip.registerScopeThirteenService.getServerStatus();
 
 console.log("Este es el estado del servidor:");
 console.log(serverStatus);
-

Para mas información acerca de este método ver el item 3.1 de la especificación del Web service (opens new window)

Last Updated: 7/11/2022, 22:00:12
- +
+
+

+ Para mas información acerca de este método ver el item 3.1 de la + especificación del Web service + (opens new window) +

+
+
+ +
+ Last Updated: + 7/11/2022, 22:00:12 +
+
+ +
+
+
+
+ + + diff --git a/docs-old/guide/Consulta-al-padron-de-AFIP-alcance-13.md b/docs-old/guide/Consulta-al-padron-de-AFIP-alcance-13.md index 0ff6bb3..2ae135a 100644 --- a/docs-old/guide/Consulta-al-padron-de-AFIP-alcance-13.md +++ b/docs-old/guide/Consulta-al-padron-de-AFIP-alcance-13.md @@ -1,6 +1,6 @@ # Padrón de AFIP alcance 13 -Los métodos de este Web Service se encuentran disponibles en `afip.registerScopeTThirteenService` +Los métodos de este Web Service se encuentran disponibles en `afip.registerScopeThirteenService` La especificación de este Web Service se encuentra disponible en http://www.afip.gob.ar/ws/ws-padron-a13/manual-ws-sr-padron-a13-v1.2.pdf @@ -16,7 +16,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) @@ -26,7 +26,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 ``` @@ -36,7 +36,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/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/tests/mocks/data/soapClient.mock.ts b/tests/mocks/data/soapClient.mock.ts index 99f0aa1..ba96876 100644 --- a/tests/mocks/data/soapClient.mock.ts +++ b/tests/mocks/data/soapClient.mock.ts @@ -1151,3 +1151,142 @@ export const getPersonaList_v2AsyncReturnMocks = [ }, }, ]; + +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/services/register-scope-five.service.test.ts b/tests/services/register-scope-five.service.test.ts index 4d97258..2253cff 100644 --- a/tests/services/register-scope-five.service.test.ts +++ b/tests/services/register-scope-five.service.test.ts @@ -10,10 +10,10 @@ import { mockLoginCredentials } from "../mocks/data/credential-json.mock"; import { RegisterScopeFiveService } from "../../src/services/register-scope-five.service"; describe("Register Scope Five Service", () => { - let afip: Afip; const originalNodeTlsRejectUnauthStatus = process.env.NODE_TLS_REJECT_UNAUTHORIZED; let registerScopeFiveService: RegisterScopeFiveService; + const cuitPayload = 20111111111; beforeAll(() => { process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; @@ -65,16 +65,17 @@ describe("Register Scope Five Service", () => { it("should get taxpayer details", async () => { const details = await registerScopeFiveService.getTaxpayerDetails( - 20111111111 + cuitPayload ); expect(details).toStrictEqual( getPersona_v2AsyncReturnMocks[0].personaReturn ); }); - it("should get taxpayer details", async () => { + it("should get taxpayers details", async () => { const details = await registerScopeFiveService.getTaxpayersDetails([ - 20111111111, 20111111111, + cuitPayload, + cuitPayload, ]); expect(details).toStrictEqual( getPersonaList_v2AsyncReturnMocks[0].personaListReturn From dd0e4ac595783017079109c35387cd65242deffd Mon Sep 17 00:00:00 2001 From: Rodrigo Alcorta Date: Tue, 3 Oct 2023 08:44:22 -0300 Subject: [PATCH 4/4] fix: thirteen service method typo fixed with new test for other services --- .../register-scope-four.service.test.ts | 68 ++++++++++++++++++ .../register-scope-ten.service.test.ts | 68 ++++++++++++++++++ .../register-scope-thirteen.service.test.ts | 70 +++++++++++++++++++ 3 files changed, 206 insertions(+) create mode 100644 tests/services/register-scope-four.service.test.ts create mode 100644 tests/services/register-scope-ten.service.test.ts create mode 100644 tests/services/register-scope-thirteen.service.test.ts 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); + }); +});