Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: idempotencyKey should be optional in header cause it is a optional params in all API #651

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 141 additions & 0 deletions src/gen/api/__tests__/accountingApi.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import {AccountingApi} from '../accountingApi';
import {Invoice} from '../../model/accounting/invoice';
import {restoreAndMockEmptyResponse} from "../../../test/utils/mockRequest";

jest.mock('fs');
jest.mock('request');

const localVarRequest = require('request');
const fs = require('fs');
const accountingAPI = new AccountingApi();
const testInvoices = {
invoices: [
{
type: Invoice.TypeEnum.ACCREC,
contact: {
contactID: 'test-contactId',
},
lineItems: [
{
description: 'Acme Tires',
quantity: 2.0,
unitAmount: 20.0,
accountCode: '500',
taxType: 'NONE',
lineAmount: 40.0,
},
],
date: '2019-03-11',
dueDate: '2018-12-10',
reference: 'Website Design',
status: Invoice.StatusEnum.AUTHORISED,
},
],
};
const testAccount = {}
describe('gen.api.accountingApi', () => {
describe('updateOrCreateInvoices function', () => {
it('header will contain Idempotency-Key if call this with idempotencyKey params', async () => {
restoreAndMockEmptyResponse(localVarRequest);
await accountingAPI.updateOrCreateInvoices('test-xeroTenantId', testInvoices, 'test-idempotencyKey');
expect(localVarRequest.mock.calls[0][0].headers.hasOwnProperty('Idempotency-Key')).toBe(true);
});
it('header will not contain Idempotency-Key if call this without idempotencyKey params', async () => {
restoreAndMockEmptyResponse(localVarRequest);
await accountingAPI.updateOrCreateInvoices('test-xeroTenantId', testInvoices, null);
expect(localVarRequest.mock.calls[0][0].headers.hasOwnProperty('Idempotency-Key')).toBe(false);
});
});
describe('createAccount function', () => {
it('header will contain Idempotency-Key if call this with idempotencyKey params', async () => {
restoreAndMockEmptyResponse(localVarRequest);
await accountingAPI.createAccount('test-xeroTenantId', testAccount, 'test-idempotencyKey');
expect(localVarRequest.mock.calls[0][0].headers.hasOwnProperty('Idempotency-Key')).toBe(true);
});
it('header will not contain Idempotency-Key if call this without idempotencyKey params', async () => {
restoreAndMockEmptyResponse(localVarRequest);
await accountingAPI.createAccount('test-xeroTenantId', testAccount, null);
expect(localVarRequest.mock.calls[0][0].headers.hasOwnProperty('Idempotency-Key')).toBe(false);
});
});
describe('createAccountAttachmentByFileName function', () => {
it('header will contain Idempotency-Key if call this with idempotencyKey params', async () => {
restoreAndMockEmptyResponse(localVarRequest);
const mReadStream = {
pipe: jest.fn().mockReturnThis(),
on: jest.fn().mockImplementation(function (event, handler) {
handler();
return this;
}),
};
fs.createReadStream.mockReturnValueOnce(mReadStream);
await accountingAPI.createAccountAttachmentByFileName(
'test-xeroTenantId',
'test-accountId',
'test-fileName',
fs.createReadStream('test-path'),
'test-idempotencyKey'
);
expect(localVarRequest.mock.calls[0][0].headers.hasOwnProperty('Idempotency-Key')).toBe(true);
});
it('header will not contain Idempotency-Key if call this without idempotencyKey params', async () => {
restoreAndMockEmptyResponse(localVarRequest);
const mReadStream = {
pipe: jest.fn().mockReturnThis(),
on: jest.fn().mockImplementation(function (event, handler) {
handler();
return this;
}),
};
fs.createReadStream.mockReturnValueOnce(mReadStream);
await accountingAPI.createAccountAttachmentByFileName(
'test-xeroTenantId',
'test-accountId',
'test-fileName',
fs.createReadStream('test-path'),
null
);
expect(localVarRequest.mock.calls[0][0].headers.hasOwnProperty('Idempotency-Key')).toBe(false);
});
});
describe('createBankTransactionAttachmentByFileName function', () => {
it('header will contain Idempotency-Key if call this with idempotencyKey params', async () => {
restoreAndMockEmptyResponse(localVarRequest);
const mReadStream = {
pipe: jest.fn().mockReturnThis(),
on: jest.fn().mockImplementation(function (event, handler) {
handler();
return this;
}),
};
fs.createReadStream.mockReturnValueOnce(mReadStream);
await accountingAPI.createBankTransactionAttachmentByFileName(
'test-xeroTenantId',
'test-bankTransactionId',
'test-fileName',
fs.createReadStream('test-path'),
'test-idempotencyKey'
);
expect(localVarRequest.mock.calls[0][0].headers.hasOwnProperty('Idempotency-Key')).toBe(true);
});
it('header will not contain Idempotency-Key if call this without idempotencyKey params', async () => {
restoreAndMockEmptyResponse(localVarRequest);
const mReadStream = {
pipe: jest.fn().mockReturnThis(),
on: jest.fn().mockImplementation(function (event, handler) {
handler();
return this;
}),
};
fs.createReadStream.mockReturnValueOnce(mReadStream);
await accountingAPI.createBankTransactionAttachmentByFileName(
'test-xeroTenantId',
'test-bankTransactionId',
'test-fileName',
fs.createReadStream('test-path'),
null
);
expect(localVarRequest.mock.calls[0][0].headers.hasOwnProperty('Idempotency-Key')).toBe(false);
});
});
});
70 changes: 70 additions & 0 deletions src/gen/api/__tests__/assetApi.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import {AssetApi} from '../assetApi';
import {AssetStatus} from "../../model/assets/assetStatus";
import {BookDepreciationSetting} from "../../model/assets/bookDepreciationSetting";
import {restoreAndMockEmptyResponse} from "../../../test/utils/mockRequest";

jest.mock('request');

const localVarRequest = require('request');
const assetAPI = new AssetApi();

const testAsset = {
"assetName": "Computer74863",
"assetNumber": "123477544",
"purchaseDate": "2020-01-01",
"purchasePrice": 100,
"disposalPrice": 23.23,
"assetStatus": AssetStatus.Draft,
"bookDepreciationSetting": {
"depreciationMethod": BookDepreciationSetting.DepreciationMethodEnum.StraightLine,
"averagingMethod": BookDepreciationSetting.AveragingMethodEnum.ActualDays,
"depreciationRate": 0.5,
"depreciationCalculationMethod": BookDepreciationSetting.DepreciationCalculationMethodEnum.None,
},
"bookDepreciationDetail": {
"currentCapitalGain": 5.32,
"currentGainLoss": 3.88,
"depreciationStartDate": "2020-01-02",
"costLimit": 100,
"currentAccumDepreciationAmount": 2.25
},
"AccountingBookValue": 99.5
};
const testAssetType = {
"assetTypeName": "Machinery11004",
"fixedAssetAccountId": "3d8d063a-c148-4bb8-8b3c-a5e2ad3b1e82",
"depreciationExpenseAccountId": "d1602f69-f900-4616-8d34-90af393fa368",
"accumulatedDepreciationAccountId": "9195cadd-8645-41e6-9f67-7bcd421defe8",
"bookDepreciationSetting": {
"depreciationMethod": BookDepreciationSetting.DepreciationMethodEnum.DiminishingValue100,
"averagingMethod": BookDepreciationSetting.AveragingMethodEnum.ActualDays,
"depreciationRate": 0.05,
"depreciationCalculationMethod": BookDepreciationSetting.DepreciationCalculationMethodEnum.None,
}
}
describe('gen.api.assetApi', () => {
describe('createAsset function', () => {
it('header will contain Idempotency-Key if call this with idempotencyKey params', async () => {
restoreAndMockEmptyResponse(localVarRequest);
await assetAPI.createAsset('test-xeroTenantId', testAsset, 'test-idempotencyKey');
expect(localVarRequest.mock.calls[0][0].headers.hasOwnProperty('Idempotency-Key')).toBe(true);
});
it('header will not contain Idempotency-Key if call this without idempotencyKey params', async () => {
restoreAndMockEmptyResponse(localVarRequest);
await assetAPI.createAsset('test-xeroTenantId', testAsset, null);
expect(localVarRequest.mock.calls[0][0].headers.hasOwnProperty('Idempotency-Key')).toBe(false);
});
});
describe('createAssetType function', () => {
it('header will contain Idempotency-Key if call this with idempotencyKey params', async () => {
restoreAndMockEmptyResponse(localVarRequest);
await assetAPI.createAssetType('test-xeroTenantId', 'test-idempotencyKey', testAssetType);
expect(localVarRequest.mock.calls[0][0].headers.hasOwnProperty('Idempotency-Key')).toBe(true);
});
it('header will not contain Idempotency-Key if call this without idempotencyKey params', async () => {
restoreAndMockEmptyResponse(localVarRequest);
await assetAPI.createAssetType('test-xeroTenantId', null, testAssetType);
expect(localVarRequest.mock.calls[0][0].headers.hasOwnProperty('Idempotency-Key')).toBe(false);
});
});
});
21 changes: 21 additions & 0 deletions src/gen/api/__tests__/filesApi.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { FilesApi } from '../filesApi';
import {restoreAndMockEmptyResponse} from "../../../test/utils/mockRequest";
jest.mock('request');

const localVarRequest = require('request');
const fileAPI = new FilesApi();

describe('gen.api.filesApi', () => {
describe('createFileAssociation function', () => {
it('header will contain Idempotency-Key if call this with idempotencyKey params', async () => {
restoreAndMockEmptyResponse(localVarRequest);
await fileAPI.createFileAssociation('test-xeroTenantId', 'test-fileId', 'test-idempotencyKey');
expect(localVarRequest.mock.calls[0][0].headers.hasOwnProperty('Idempotency-Key')).toBe(true);
});
it('header will not contain Idempotency-Key if call this without idempotencyKey params', async () => {
restoreAndMockEmptyResponse(localVarRequest);
await fileAPI.createFileAssociation('test-xeroTenantId', 'test-fileId', null);
expect(localVarRequest.mock.calls[0][0].headers.hasOwnProperty('Idempotency-Key')).toBe(false);
});
});
});
41 changes: 41 additions & 0 deletions src/gen/api/__tests__/payrollAUApi.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import {PayrollAuApi} from '../payrollAUApi';
import {restoreAndMockEmptyResponse} from "../../../test/utils/mockRequest";

jest.mock('request');

const localVarRequest = require('request');
const payRollAuAPI = new PayrollAuApi();

const testEmployee = [{
"firstName": "Nick",
"lastName": "Fury",
"dateOfBirth": new Date(321523200000).toISOString(),
"externalLink": {"Url": "http://twitter.com/#!/search/Nick+Fury"}
}]
describe('gen.api.payrollAUApi', () => {
describe('approveLeaveApplication function', () => {
it('header will contain Idempotency-Key if call this with idempotencyKey params', async () => {
restoreAndMockEmptyResponse(localVarRequest);
await payRollAuAPI.approveLeaveApplication('test-xeroTenantId', 'test-leaveApplicationID', 'test-idempotencyKey');
expect(localVarRequest.mock.calls[0][0].headers.hasOwnProperty('Idempotency-Key')).toBe(true);
});
it('header will not contain Idempotency-Key if call this without idempotencyKey params', async () => {
restoreAndMockEmptyResponse(localVarRequest);
await payRollAuAPI.approveLeaveApplication('test-xeroTenantId', 'test-leaveApplicationID', null);
expect(localVarRequest.mock.calls[0][0].headers.hasOwnProperty('Idempotency-Key')).toBe(false);
});
});

describe('createEmployee function', () => {
it('header will contain Idempotency-Key if call this with idempotencyKey params', async () => {
restoreAndMockEmptyResponse(localVarRequest);
await payRollAuAPI.createEmployee('test-xeroTenantId', testEmployee, 'test-idempotencyKey');
expect(localVarRequest.mock.calls[0][0].headers.hasOwnProperty('Idempotency-Key')).toBe(true);
});
it('header will not contain Idempotency-Key if call this without idempotencyKey params', async () => {
restoreAndMockEmptyResponse(localVarRequest);
await payRollAuAPI.createEmployee('test-xeroTenantId', testEmployee, null);
expect(localVarRequest.mock.calls[0][0].headers.hasOwnProperty('Idempotency-Key')).toBe(false);
});
});
});
32 changes: 32 additions & 0 deletions src/gen/api/__tests__/payrollUKApi.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {PayrollUkApi} from '../payrollUKApi';
import {restoreAndMockEmptyResponse} from "../../../test/utils/mockRequest";
import {Benefit} from "../../model/payroll-uk/benefit";

jest.mock('request');

const localVarRequest = require('request');
const payRollUkAPI = new PayrollUkApi();

const testBenefit = {
"name": "test benefit",
"category": Benefit.CategoryEnum.Other,
"liabilityAccountId": "test-liabilityAccountId",
"expenseAccountId": "test-expenseAccountId",
"percentage": 10,
"calculationType": Benefit.CalculationTypeEnum.FixedAmount,
};
describe('gen.api.payRollUkApi', () => {
describe('createBenefit function', () => {
it('header will contain Idempotency-Key if call this with idempotencyKey params', async () => {
restoreAndMockEmptyResponse(localVarRequest);
await payRollUkAPI.createBenefit('test-xeroTenantId', testBenefit, 'test-idempotencyKey');
expect(localVarRequest.mock.calls[0][0].headers.hasOwnProperty('Idempotency-Key')).toBe(true);
});
it('header will not contain Idempotency-Key if call this without idempotencyKey params', async () => {
restoreAndMockEmptyResponse(localVarRequest);
await payRollUkAPI.createBenefit('test-xeroTenantId', testBenefit, null);
expect(localVarRequest.mock.calls[0][0].headers.hasOwnProperty('Idempotency-Key')).toBe(false);
});
});

});
19 changes: 12 additions & 7 deletions src/gen/api/accountingApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,9 @@ export class AccountingApi {
}

localVarHeaderParams['xero-tenant-id'] = ObjectSerializer.serialize(xeroTenantId, "string");
localVarHeaderParams['Idempotency-Key'] = ObjectSerializer.serialize(idempotencyKey, "string");

if( idempotencyKey ){
localVarHeaderParams['Idempotency-Key'] = ObjectSerializer.serialize(idempotencyKey, "string");
}
(<any>Object).assign(localVarHeaderParams, options.headers);
let localVarUseFormData = false;

Expand Down Expand Up @@ -235,8 +236,9 @@ export class AccountingApi {
this.binaryHeaders = {'Accept': 'application/json'};
(<any>Object).assign(localVarHeaderParams, this.binaryHeaders);
localVarHeaderParams['xero-tenant-id'] = ObjectSerializer.serialize(xeroTenantId, "string");
localVarHeaderParams['Idempotency-Key'] = ObjectSerializer.serialize(idempotencyKey, "string");

if( idempotencyKey ){
localVarHeaderParams['Idempotency-Key'] = ObjectSerializer.serialize(idempotencyKey, "string");
}
(<any>Object).assign(localVarHeaderParams, options.headers);
let localVarUseFormData = false;

Expand Down Expand Up @@ -338,8 +340,9 @@ export class AccountingApi {
this.binaryHeaders = {'Accept': 'application/json'};
(<any>Object).assign(localVarHeaderParams, this.binaryHeaders);
localVarHeaderParams['xero-tenant-id'] = ObjectSerializer.serialize(xeroTenantId, "string");
localVarHeaderParams['Idempotency-Key'] = ObjectSerializer.serialize(idempotencyKey, "string");

if( idempotencyKey ){
localVarHeaderParams['Idempotency-Key'] = ObjectSerializer.serialize(idempotencyKey, "string");
}
(<any>Object).assign(localVarHeaderParams, options.headers);
let localVarUseFormData = false;

Expand Down Expand Up @@ -16439,7 +16442,9 @@ export class AccountingApi {
}

localVarHeaderParams['xero-tenant-id'] = ObjectSerializer.serialize(xeroTenantId, "string");
localVarHeaderParams['Idempotency-Key'] = ObjectSerializer.serialize(idempotencyKey, "string");
if( idempotencyKey ){
localVarHeaderParams['Idempotency-Key'] = ObjectSerializer.serialize(idempotencyKey, "string");
}

(<any>Object).assign(localVarHeaderParams, options.headers);
let localVarUseFormData = false;
Expand Down
10 changes: 6 additions & 4 deletions src/gen/api/assetApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@ export class AssetApi {
}

localVarHeaderParams['xero-tenant-id'] = ObjectSerializer.serialize(xeroTenantId, "string");
localVarHeaderParams['Idempotency-Key'] = ObjectSerializer.serialize(idempotencyKey, "string");

if( idempotencyKey ){
localVarHeaderParams['Idempotency-Key'] = ObjectSerializer.serialize(idempotencyKey, "string");
}
(<any>Object).assign(localVarHeaderParams, options.headers);
let localVarUseFormData = false;

Expand Down Expand Up @@ -167,8 +168,9 @@ export class AssetApi {
}

localVarHeaderParams['xero-tenant-id'] = ObjectSerializer.serialize(xeroTenantId, "string");
localVarHeaderParams['Idempotency-Key'] = ObjectSerializer.serialize(idempotencyKey, "string");

if( idempotencyKey ){
localVarHeaderParams['Idempotency-Key'] = ObjectSerializer.serialize(idempotencyKey, "string");
}
(<any>Object).assign(localVarHeaderParams, options.headers);
let localVarUseFormData = false;

Expand Down
5 changes: 3 additions & 2 deletions src/gen/api/filesApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@ export class FilesApi {
}

localVarHeaderParams['xero-tenant-id'] = ObjectSerializer.serialize(xeroTenantId, "string");
localVarHeaderParams['Idempotency-Key'] = ObjectSerializer.serialize(idempotencyKey, "string");

if( idempotencyKey ){
localVarHeaderParams['Idempotency-Key'] = ObjectSerializer.serialize(idempotencyKey, "string");
}
(<any>Object).assign(localVarHeaderParams, options.headers);
let localVarUseFormData = false;

Expand Down
Loading