Skip to content

Commit

Permalink
feat(Sell): add missed api calls
Browse files Browse the repository at this point in the history
 * improve oas spec test
  • Loading branch information
dantio committed Sep 25, 2020
1 parent 3b1514e commit 4749eba
Show file tree
Hide file tree
Showing 4 changed files with 278 additions and 39 deletions.
128 changes: 127 additions & 1 deletion src/api/restful/sell/account/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import Api from '../../';
import {Program} from '../../../../types/restfulTypes';
import {
FulfillmentPolicyRequest,
PaymentPolicyRequest,
Program,
ReturnPolicyRequest, SalesTaxBase
} from '../../../../types/restfulTypes';

/**
* The <b>Account API</b> gives sellers the ability to configure their eBay seller accounts,
Expand All @@ -25,6 +30,37 @@ export default class Account extends Api {
});
}

/**
* This method creates a new fulfillment policy where the policy encapsulates seller's terms for fulfilling item
* purchases.
*
* @param body Request to create a seller account fulfillment policy.
*/
public createFulfillmentPolicy(body: FulfillmentPolicyRequest) {
return this.post(`/fulfillment_policy/`, body);
}

/**
* This method updates an existing fulfillment policy.
*
* @param fulfillmentPolicyId This path parameter specifies the ID of the fulfillment policy you want to update.
* @param body Request to create a seller account fulfillment policy.
*/
public updateFulfillmentPolicy(fulfillmentPolicyId: string, body: FulfillmentPolicyRequest) {
const id = encodeURIComponent(fulfillmentPolicyId);
return this.put(`/fulfillment_policy/${id}`, body);
}

/**
* This method deletes a fulfillment policy.
*
* @param fulfillmentPolicyId This path parameter specifies the ID of the fulfillment policy to delete.
*/
public deleteFulfillmentPolicy(fulfillmentPolicyId: string) {
const id = encodeURIComponent(fulfillmentPolicyId);
return this.delete(`/fulfillment_policy/${id}`);
}

/**
* This method retrieves the complete details of a fulfillment policy.
* Supply the ID of the policy you want to retrieve using the fulfillmentPolicyId path parameter.
Expand Down Expand Up @@ -75,6 +111,36 @@ export default class Account extends Api {
return this.get(`/payment_policy/${id}`);
}

/**
* This method creates a new payment policy where the policy encapsulates seller's terms for purchase payments.
*
* @param body Payment policy request
*/
public createPaymentPolicy(body: PaymentPolicyRequest) {
return this.post(`/payment_policy/`, body);
}

/**
* This method updates an existing payment policy.
*
* @param paymentPolicyId This path parameter specifies the ID of the payment policy you want to update.
* @param body Payment policy request
*/
public updatePaymentPolicy(paymentPolicyId: string, body: PaymentPolicyRequest) {
const id = encodeURIComponent(paymentPolicyId);
return this.put(`/payment_policy/${id}`, body);
}

/**
* This method updates an existing payment policy.
*
* @param paymentPolicyId This path parameter specifies the ID of the payment policy you want to delete.
*/
public deletePaymentPolicy(paymentPolicyId: string) {
const id = encodeURIComponent(paymentPolicyId);
return this.delete(`/payment_policy/${id}`);
}

/**
* This method retrieves the complete details of a single payment policy.
*
Expand Down Expand Up @@ -175,6 +241,36 @@ export default class Account extends Api {
return this.get(`/return_policy/${id}`);
}

/**
* This method creates a new return policy where the policy encapsulates seller's terms for returning items.
*
* @param body Return policy request
*/
public createReturnPolicy(body: ReturnPolicyRequest) {
return this.post(`/return_policy/`, body);
}

/**
* This method creates a new return policy where the policy encapsulates seller's terms for returning items.
*
* @param returnPolicyId This path parameter specifies the ID of the return policy you want to update.
* @param body Return policy request
*/
public updateReturnPolicy(returnPolicyId: string, body: ReturnPolicyRequest) {
const id = encodeURIComponent(returnPolicyId);
return this.put(`/return_policy/${id}`, body);
}

/**
* This method deletes a return policy.
*
* @param returnPolicyId This path parameter specifies the ID of the return policy you want to delete.
*/
public deleteReturnPolicy(returnPolicyId: string) {
const id = encodeURIComponent(returnPolicyId);
return this.delete(`/return_policy/${id}`);
}

/**
* This method retrieves the complete details of a single return policy.
*
Expand Down Expand Up @@ -205,6 +301,36 @@ export default class Account extends Api {
return this.get(`/sales_tax/${cc}/${jId}`);
}


/**
* This method creates or updates a sales tax table entry for a jurisdiction.
*
* @param countryCode This path parameter specifies the two-letter ISO 3166-1 Alpha-2 code for the country for
* which you want to create tax table entry.
* @param jurisdictionId This path parameter specifies the ID of the sales-tax jurisdiction for the table entry you
* want to create.
* @param body A container that describes the how the sales tax is calculated.
*/
public createOrReplaceSalesTax(countryCode: string, jurisdictionId: string, body: SalesTaxBase) {
const cc = encodeURIComponent(countryCode);
const jId = encodeURIComponent(jurisdictionId);
return this.put(`/sales_tax/${cc}/${jId}`, body);
}

/**
* This call deletes a tax table entry for a jurisdiction.
*
* @param countryCode This path parameter specifies the two-letter ISO 3166-1 Alpha-2 code for the country for
* which you want to create tax table entry.
* @param jurisdictionId This path parameter specifies the ID of the sales-tax jurisdiction for the table entry you
* want to delete.
*/
public deleteSalesTax(countryCode: string, jurisdictionId: string) {
const cc = encodeURIComponent(countryCode);
const jId = encodeURIComponent(jurisdictionId);
return this.delete(`/sales_tax/${cc}/${jId}`);
}

/**
* Use this call to retrieve a sales tax table that the seller established for a specific country.
*
Expand Down
114 changes: 114 additions & 0 deletions src/types/restfulTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -903,3 +903,117 @@ export type DecideReturnRequest = {
RMANumber?: string;
rMAProvided?: boolean;
};

export type CategoryType = {
default: boolean
name: string
}

export type TimeDuration = {
unit: string
value: number
}

export type Region = {
regionName: string
regionType: string
}

export type RegionSet = {
regionExcluded: Region[]
regionIncluded: Region[]
}

export type ShippingService = {
additionalShippingCost: Amount
buyerResponsibleForPickup: boolean
buyerResponsibleForShipping: boolean
cashOnDeliveryFee: Amount
freeShipping: boolean
shippingCarrierCode: string
shippingCost: Amount
shippingServiceCode: string
shipToLocations: RegionSet
sortOrder: number
surcharge: Amount
}

export type ShippingOption = {
costType: string
insuranceFee: Amount
insuranceOffered: boolean
optionType: string
packageHandlingCost: Amount
rateTableId: string
shippingServices: ShippingService
}

export type FulfillmentPolicyRequest = {
categoryTypes: CategoryType[]
description?: string
freightShipping: boolean
handlingTime: TimeDuration
localPickup: boolean
marketplaceId?: string
name: string
pickupDropOff: boolean
shippingOptions: ShippingOption
shipToLocations: RegionSet
}

export type RecipientAccountReference = {
referenceId: string
referenceType: string
}

export type PaymentMethod = {
brands?: string[]
paymentMethodType: string
recipientAccountReference?: RecipientAccountReference
}

export type Deposit = {
amount: Amount
dueIn: TimeDuration
paymentMethods: PaymentMethod[]
}

export type PaymentPolicyRequest = {
categoryTypes: CategoryType[]
deposit: Deposit
description: string
fullPaymentDueIn: TimeDuration
immediatePay: boolean
marketplaceId?: string
name: string
paymentInstructions: string
paymentMethods: PaymentMethod
}

export type InternationalReturnOverrideType = {
returnMethod?: string
returnPeriod?: TimeDuration
returnsAccepted?: boolean
returnShippingCostPayer?: string
}

export type ReturnPolicyRequest = {
categoryTypes: CategoryType[]
description?: string
extendedHolidayReturnsOffered: boolean
internationalOverride: InternationalReturnOverrideType
marketplaceId: string
name: string
refundMethod: string
restockingFeePercentage: string
returnInstructions: string
returnMethod: string
returnPeriod: TimeDuration
returnsAccepted: boolean
returnShippingCostPayer: string
}

export type SalesTaxBase = {
salesTaxPercentage: string
shippingAndHandlingTaxed: boolean
}
70 changes: 33 additions & 37 deletions test/api/restful/oas.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,51 +47,47 @@ describe('Open API Tests', () => {
});

Object.keys(Oas.paths).forEach((path: any) => {
const method = Oas.paths[path].get ? 'get' : 'post';
const endpoint = Oas.paths[path];
const call = endpoint[method];
const queryParams = path.match(/(?<={).+?(?=})/ig);
const paramsInPath = queryParams ? queryParams : [];
const paramsInHeader = call.parameters ? call.parameters.filter((p: any) => p.in === 'header') : [];
const args = paramsInPath.map((paramName: any) => '{' + paramName + '}')
.concat(paramsInHeader.map((p: any) => p.name));
Object.keys(Oas.paths[path]).forEach(method => {
const endpoint = Oas.paths[path];
const call = endpoint[method];
if (!call.operationId || call.deprecated) {
return;
}
const queryParams = path.match(/(?<={).+?(?=})/ig);
const paramsInPath = queryParams ? queryParams : [];
const paramsInHeader = call.parameters ? call.parameters.filter((p: any) => p.in === 'header') : [];
const args = paramsInPath.map((paramName: any) => '{' + paramName + '}')
.concat(paramsInHeader.map((p: any) => p.name));

const req = {
get: sinon.stub().returns(Promise.resolve()),
post: sinon.stub().returns(Promise.resolve()),
postForm: sinon.stub().returns(Promise.resolve())
};
const req: any = {
get: sinon.stub().returns(Promise.resolve()),
put: sinon.stub().returns(Promise.resolve()),
delete: sinon.stub().returns(Promise.resolve()),
post: sinon.stub().returns(Promise.resolve()),
postForm: sinon.stub().returns(Promise.resolve())
};

const restApi = new Api(auth, req);
const restApi = new Api(auth, req);

it('"' + name + ':' + Api.name + '" should implement this method', () => {
expect(restApi[call.operationId]).to
.be.a('function', 'AssertionError: expected to have "'
+ call.operationId + '" implemented.');
});
it(`"${name}:${Api.name}" should implement this method (${path}). `, () => {
expect(restApi[call.operationId]).to
.be.a('function', 'AssertionError: expected to have "'
+ call.operationId + '" implemented.');
});

it('"' + name + ':' + Api.name + ':' + call.operationId + '" call correct method', () => {
return restApi[call.operationId](...args).then(() => {
if (method === 'get') {
// tslint:disable-next-line:no-unused-expression
expect(req.get.calledOnce).to.be.true;
} else if (method === 'post') {
// tslint:disable-next-line:no-unused-expression
expect(req.post.calledOnce).to.be.true;
}
it(`"${name}:${Api.name}:${call.operationId}" call correct method (${path}).`, () => {
return restApi[call.operationId](...args).then(() => {
expect(req[method].calledOnce).to.be.true;
});
});
});

it('"' + name + ':' + Api.name + ':' + call.operationId + '" calls correct url', () => {
return restApi[call.operationId](...args).then(() => {
if (method === 'get') {
expect(decodeURI(req.get.args[0][0]))
it(`"${name}:${Api.name}:${call.operationId}" calls correct url (${path}).`, () => {
return restApi[call.operationId](...args).then(() => {
expect(decodeURI(req[method].args[0][0]))
.to.equal(decodeURI(encodeURI(restApi.baseUrl + path)));
} else if (method === 'post') {
expect(decodeURI(req.post.args[0][0]))
.to.equal(decodeURI(encodeURI(restApi.baseUrl + path)));
}
});
});

});
});
});
Expand Down
5 changes: 4 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src"]
"include": ["src"],
"exclude": [
"test"
]
}

0 comments on commit 4749eba

Please sign in to comment.