Skip to content

Commit

Permalink
Merge pull request #69 from ralcorta/FIX-68
Browse files Browse the repository at this point in the history
FIX-68: Fix ENOENT error
  • Loading branch information
ralcorta authored Jun 4, 2024
2 parents 2df60d7 + a29ad5c commit 607e8d7
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ package-lock.json
pnpm-lock.yaml

src/auth/tickets
tests/mocks/credentials
*/mocks/credentials

docs/.vitepress/dist
7 changes: 6 additions & 1 deletion src/auth/afip-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,12 @@ export class AfipAuth {
throw new Error(`Access denied to ticket file: ${filePath}`);
}

const fileData = await fs.readFile(filePath, "utf8");
let fileData;
try {
fileData = await fs.readFile(filePath, "utf8");
} catch (error) {
return undefined;
}

try {
return new AccessTicket(JSON.parse(fileData));
Expand Down
2 changes: 1 addition & 1 deletion src/services/afip.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export class AfipService<T extends Client> {
throw new Error("Credentials expired.");
}
} else if (!this._credentials || this._credentials.isExpired()) {
this._credentials = await this._afipAuth.login(this._serviceName);
this._credentials = await this.login();
}

return this._credentials.getWSAuthFormat(this.context.cuit);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { mockLoginCredentials } from "./../mocks/data/credential-json.mock";
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 "../utils/env-test";
import { AccessTicket } from "../../../src/auth/access-ticket";
import { ILoginCredentials } from "../../../src/types";
import EnvTest from "../../utils/env-test";

describe("Access Ticket", () => {
describe("getSign", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { mockLoginCredentials } from "./../mocks/data/credential-json.mock";
import { AfipAuth } from "./../../src/auth/afip-auth";
import { ServiceNamesEnum } from "../../src/soap/service-names.enum";
import { Context, ILoginCredentials } from "./../../src/types";
import { AccessTicket } from "../../src/auth/access-ticket";
import { mockLoginCredentials } from "../../mocks/data/credential-json.mock";
import { AfipAuth } from "../../../src/auth/afip-auth";
import { ServiceNamesEnum } from "../../../src/soap/service-names.enum";
import { Context, ILoginCredentials } from "../../../src/types";
import { AccessTicket } from "../../../src/auth/access-ticket";
import moment from "moment";
import { promises as fs } from "fs";

jest.mock("../../src/soap/soap-client-facade", () => ({
jest.mock("../../../src/soap/soap-client-facade", () => ({
create: jest.fn(() => ({
loginCmsAsync: jest.fn(() => {
return [{ loginCmsReturn: "" }, "", {}, ""];
}),
})),
}));

jest.mock("../../src/utils/parser", () => ({
jest.mock("../../../src/utils/parser", () => ({
jsonToXml: jest.fn((json) => JSON.stringify(json)),
xmlToJson: jest.fn((xml) => JSON.parse(xml)),
}));

jest.mock("../../src/utils/crypt-data", () => ({
jest.mock("../../../src/utils/crypt-data", () => ({
Cryptography: jest.fn(() => ({
sign: jest.fn(() => "signedTRA"),
})),
Expand All @@ -38,7 +38,7 @@ jest.mock("fs", () => ({
},
}));

jest.mock("../../src/utils/logger", () => ({
jest.mock("../../../src/utils/logger", () => ({
error: jest.fn(),
}));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { Client } from "soap";
import { EndpointsEnum, SoapServiceVersion } from "../../src/enums";
import { AfipService } from "../../src/services/afip.service";
import { IServiceSoap12Soap } from "../../src/soap/interfaces/Service/ServiceSoap12";
import { ServiceNamesEnum } from "../../src/soap/service-names.enum";
import { WsdlPathEnum } from "../../src/soap/wsdl-path.enum";
import { AfipServiceSoapParam, Context } from "../../src/types";
import { testCuit } from "../mocks/data/voucher.mock";
import { TestConfigUtils } from "../utils/config.utils";
import { mockFn } from "../utils/jest.utils";
import { EndpointsEnum, SoapServiceVersion } from "../../../src/enums";
import { AfipService } from "../../../src/services/afip.service";
import { IServiceSoap12Soap } from "../../../src/soap/interfaces/Service/ServiceSoap12";
import { ServiceNamesEnum } from "../../../src/soap/service-names.enum";
import { WsdlPathEnum } from "../../../src/soap/wsdl-path.enum";
import { AfipServiceSoapParam, Context } from "../../../src/types";
import { testCuit } from "../../mocks/data/voucher.mock";
import { TestConfigUtils } from "../../utils/config.utils";
import { mockFn } from "../../utils/jest.utils";

describe("AfipService", () => {
let afipService: AfipService<Client>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ import {
FEParamGetTiposMonedasAsyncReturnMocks,
FEParamGetTiposOpcionalAsyncReturnMocks,
FEParamGetTiposTributosAsyncReturnMocks,
} from "../mocks/data/soapClient.mock";
} from "../../mocks/data/soapClient.mock";
import {
data,
testCbteNro,
testCbteTipo,
testCuit,
testPtoVta,
} from "../mocks/data/voucher.mock";
import { Afip } from "../../src/afip";
import { TestConfigUtils } from "../utils/config.utils";
import { AccessTicket } from "../../src/auth/access-ticket";
import { mockLoginCredentials } from "../mocks/data/credential-json.mock";
} from "../../mocks/data/voucher.mock";
import { Afip } from "../../../src/afip";
import { TestConfigUtils } from "../../utils/config.utils";
import { AccessTicket } from "../../../src/auth/access-ticket";
import { mockLoginCredentials } from "../../mocks/data/credential-json.mock";

describe("Electronic Billings Service", () => {
let afip: Afip;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { testCuit } from "./../mocks/data/voucher.mock";
import { Afip } from "../../src/afip";
import { TestConfigUtils } from "../utils/config.utils";
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 { RegisterInscriptionProofService } from "../../src/services/register-inscription-proof.service";
} from "../../mocks/data/soapClient.mock";
import { mockLoginCredentials } from "../../mocks/data/credential-json.mock";
import { RegisterInscriptionProofService } from "../../../src/services/register-inscription-proof.service";

describe("Register Inscription Proof Service", () => {
const originalNodeTlsRejectUnauthStatus =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { testCuit } from "./../mocks/data/voucher.mock";
import { Afip } from "../../src/afip";
import { TestConfigUtils } from "../utils/config.utils";
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";
} 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 =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { testCuit } from "../mocks/data/voucher.mock";
import { Afip } from "../../src/afip";
import { TestConfigUtils } from "../utils/config.utils";
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";
} 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 =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
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 { 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";
} from "../../mocks/data/soapClient.mock";

describe("Register Scope Ten Service", () => {
const originalNodeTlsRejectUnauthStatus =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
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 { 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";
} from "../../mocks/data/soapClient.mock";

describe("Register Scope Thirteen Service", () => {
const originalNodeTlsRejectUnauthStatus =
Expand Down

0 comments on commit 607e8d7

Please sign in to comment.