Skip to content

Commit

Permalink
Merge pull request #455 from kontist/feature/COM-360-extend-eric-erro…
Browse files Browse the repository at this point in the history
…r-logic-ustva

COM-360 Extend Eric error logic for UstVA
  • Loading branch information
caglaralkiss authored Aug 27, 2024
2 parents eb28e63 + 9a75c6f commit c82d963
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 0 deletions.
37 changes: 37 additions & 0 deletions lib/graphql/declaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
DeclarationStats,
MutationCategorizeTransactionForDeclarationArgs,
CategorizeTransactionForDeclarationResponse,
AccountVatDeclarationSubmissionsArgs,
DeclarationSubmission
} from "./schema";

const DECLARATION_FIELDS = `
Expand All @@ -21,6 +23,21 @@ const DECLARATION_FIELDS = `
submissionStatus
`;

const DECLARATION_SUBMISSION_FIELDS = `
id
period
year
isFinal
isSuccessful
submittedAt
messages {
type
text
formLineNumber
fieldIdentifier
}
`;

const FETCH_DECLARATIONS = `
query fetchDeclarations ($type: DeclarationType!) {
viewer {
Expand All @@ -33,6 +50,18 @@ const FETCH_DECLARATIONS = `
}
`;

const FETCH_DECLARATION_SUBMISSIONS = `
query fetchDeclarationSubmissions ($year: Int!, $period: String!) {
viewer {
mainAccount {
vatDeclarationSubmissions (year: $year, period: $period) {
${DECLARATION_SUBMISSION_FIELDS}
}
}
}
}
`;

const GET_DECLARATION_PDF = `
query getDeclarationPdf ($id: Int!) {
viewer {
Expand Down Expand Up @@ -148,6 +177,14 @@ export class Declaration {
return result.viewer?.mainAccount?.declarations || [];
}

public async fetchDeclarationSubmissions(
args: AccountVatDeclarationSubmissionsArgs
): Promise<DeclarationSubmission[]> {
const result: Query = await this.client.rawQuery(FETCH_DECLARATION_SUBMISSIONS, args);

return result.viewer?.mainAccount?.vatDeclarationSubmissions || [];
}

public async getPdfUrl(
args: AccountDeclarationPdfUrlArgs
): Promise<string | null> {
Expand Down
19 changes: 19 additions & 0 deletions lib/graphql/schema.flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export type Account = {|
/** A list of iban/name combinations based on existing user's transactions, provided to assist users when creating new transfers */
transferSuggestions?: ?Array<TransferSuggestion>,
transfers: TransfersConnection,
vatDeclarationSubmissions: Array<DeclarationSubmission>,
/** Account vat-related settings */
vatYearSettings: Array<VatYearSetting>,
|};
Expand Down Expand Up @@ -125,6 +126,13 @@ export type AccountTransfersArgs = {|
|};


/** The bank account of the current user */
export type AccountVatDeclarationSubmissionsArgs = {|
period: $ElementType<Scalars, 'String'>,
year: $ElementType<Scalars, 'Int'>,
|};


/** The bank account of the current user */
export type AccountVatYearSettingsArgs = {|
year?: ?$ElementType<Scalars, 'Int'>,
Expand Down Expand Up @@ -1067,6 +1075,17 @@ export type DeclarationStats = {|
uncategorized: Array<TransactionForAccountingView>,
|};

export type DeclarationSubmission = {|
__typename?: 'DeclarationSubmission',
id: $ElementType<Scalars, 'Int'>,
isFinal: $ElementType<Scalars, 'Boolean'>,
isSuccessful: $ElementType<Scalars, 'Boolean'>,
messages: Array<BizTaxDeclarationResultMessage>,
period: $ElementType<Scalars, 'String'>,
submittedAt: $ElementType<Scalars, 'DateTime'>,
year: $ElementType<Scalars, 'Int'>,
|};

export const DeclarationTypeValues = Object.freeze({
Euer: 'EUER',
GewSt: 'GewSt',
Expand Down
19 changes: 19 additions & 0 deletions lib/graphql/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export type Account = {
/** A list of iban/name combinations based on existing user's transactions, provided to assist users when creating new transfers */
transferSuggestions?: Maybe<Array<TransferSuggestion>>;
transfers: TransfersConnection;
vatDeclarationSubmissions: Array<DeclarationSubmission>;
/** Account vat-related settings */
vatYearSettings: Array<VatYearSetting>;
};
Expand Down Expand Up @@ -130,6 +131,13 @@ export type AccountTransfersArgs = {
};


/** The bank account of the current user */
export type AccountVatDeclarationSubmissionsArgs = {
period: Scalars['String']['input'];
year: Scalars['Int']['input'];
};


/** The bank account of the current user */
export type AccountVatYearSettingsArgs = {
year?: InputMaybe<Scalars['Int']['input']>;
Expand Down Expand Up @@ -1014,6 +1022,17 @@ export type DeclarationStats = {
uncategorized: Array<TransactionForAccountingView>;
};

export type DeclarationSubmission = {
__typename?: 'DeclarationSubmission';
id: Scalars['Int']['output'];
isFinal: Scalars['Boolean']['output'];
isSuccessful: Scalars['Boolean']['output'];
messages: Array<BizTaxDeclarationResultMessage>;
period: Scalars['String']['output'];
submittedAt: Scalars['DateTime']['output'];
year: Scalars['Int']['output'];
};

export enum DeclarationType {
Euer = 'EUER',
GewSt = 'GewSt',
Expand Down
87 changes: 87 additions & 0 deletions tests/graphql/declaration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
TransactionCategory,
CategorizeTransactionForDeclarationResponse,
SubmissionStatus,
DeclarationSubmission,
BizTaxDeclarationResultMessageType,
} from "../../lib/graphql/schema";

describe("Declaration", () => {
Expand Down Expand Up @@ -87,6 +89,91 @@ describe("Declaration", () => {
});
});

describe("#fetchDeclarationSubmissions", () => {
it("should call rawQuery and return declaration submissions array", async () => {
// arrange
const declarationSubmissionsResponse: DeclarationSubmission[] = [
{
id: 1,
period: "01",
year: 2024,
submittedAt: "2024-01-01",
isFinal: true,
isSuccessful: false,
messages: [
{
fieldIdentifier: "fieldIdentifier",
formLineNumber: "11",
text: "some error text",
type: BizTaxDeclarationResultMessageType.Notice,
}
],
},
{
id: 2,
period: "01",
year: 2024,
submittedAt: "2024-02-01",
isFinal: true,
isSuccessful: true,
messages: [],
},
];
const spyOnRawQuery = sandbox.stub(client.graphQL, "rawQuery").resolves({
viewer: {
mainAccount: {
vatDeclarationSubmissions: declarationSubmissionsResponse,
},
},
} as any);

// act
const result = await declaration.fetchDeclarationSubmissions({
year: 2024,
period: "01"
});

// assert
sinon.assert.calledOnce(spyOnRawQuery);
expect(result).to.deep.eq(declarationSubmissionsResponse);
});

it("should call rawQuery and return empty array for missing account", async () => {
// arrange
const spyOnRawQuery = sandbox.stub(client.graphQL, "rawQuery").resolves({
viewer: {},
} as any);

// act
const result = await declaration.fetch({
type: DeclarationType.UStVa,
});

// assert
sinon.assert.calledOnce(spyOnRawQuery);
expect(result).to.deep.eq([]);
});

it("should call rawQuery and return empty array for missing vatDeclarationSubmissions", async () => {
// arrange
const spyOnRawQuery = sandbox.stub(client.graphQL, "rawQuery").resolves({
viewer: {
mainAccount: {},
},
} as any);

// act
const result = await declaration.fetchDeclarationSubmissions({
year: 2024,
period: "01"
});

// assert
sinon.assert.calledOnce(spyOnRawQuery);
expect(result).to.deep.eq([]);
});
});

describe("#getPdfUrl", () => {
it("should call rawQuery and return result", async () => {
// arrange
Expand Down

0 comments on commit c82d963

Please sign in to comment.