Skip to content
This repository has been archived by the owner on Jul 15, 2024. It is now read-only.

Commit

Permalink
Merge pull request #41 from Giftbit/discountSellerLiabilityRule
Browse files Browse the repository at this point in the history
Discount seller liability rule
  • Loading branch information
Tim authored Nov 19, 2019
2 parents daff54f + f2ca2b7 commit 64f94ca
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lightrail-client",
"version": "4.2.2",
"version": "4.3.0",
"description": "A Javascript and Typescript client for Lightrail",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export function request(method: string, path: string): superagent.Request {
}
if (!configuration.isBrowser) {
// TODO@Dan Review Previous import of package.json to dynamically set this was breaking publish (dist included src/ & package.json file)
r.set("User-Agent", "Lightrail-JavaScript/4.2.2");
r.set("User-Agent", "Lightrail-JavaScript/4.3.0");
}
if (configuration.isBrowser) {
r.set("X-Requested-With", "XMLHttpRequest");
Expand Down
4 changes: 4 additions & 0 deletions src/model/DiscountSellerLiabilityRule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface DiscountSellerLiabilityRule {
rule: string;
explanation: string;
}
3 changes: 3 additions & 0 deletions src/model/Program.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import {BalanceRule} from "./BalanceRule";
import {RedemptionRule} from "./RedemptionRule";
import {DiscountSellerLiabilityRule} from "./DiscountSellerLiabilityRule";

export interface Program {
id: string;
name: string;
currency: string;
discount: boolean;
/** @deprecated since v4.3.0 - use DiscountSellerLiabilityRule instead. */
discountSellerLiability: number;
discountSellerLiabilityRule: DiscountSellerLiabilityRule;
pretax: boolean;
active: boolean;
redemptionRule: RedemptionRule;
Expand Down
3 changes: 3 additions & 0 deletions src/model/Value.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {BalanceRule} from "./BalanceRule";
import {RedemptionRule} from "./RedemptionRule";
import {GenericCodeOptions} from "./GenericCodeOptions";
import {DiscountSellerLiabilityRule} from "./DiscountSellerLiabilityRule";

export interface Value {
id: string;
Expand All @@ -20,7 +21,9 @@ export interface Value {
canceled: boolean;
redemptionRule: RedemptionRule;
discount: boolean;
/** @deprecated since v4.3.0 - use DiscountSellerLiabilityRule instead. */
discountSellerLiability: number;
discountSellerLiabilityRule: DiscountSellerLiabilityRule;
startDate: string;
endDate: string;
tags: string[];
Expand Down
1 change: 1 addition & 0 deletions src/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export * from "./RedemptionRule";
export * from "./Transaction";
export * from "./Value";
export * from "./GenericCodeOptions";
export * from "./DiscountSellerLiabilityRule";
7 changes: 5 additions & 2 deletions src/params/programs/CreateProgramParams.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import {Program} from "../../model";
import {LightrailResponse} from "../LightrailResponse";
import {BalanceRule} from "../../model/BalanceRule";
import {RedemptionRule} from "../../model/RedemptionRule";
import {BalanceRule} from "../../model";
import {RedemptionRule} from "../../model";
import {DiscountSellerLiabilityRule} from "../../model";

export interface CreateProgramParams {
id: string;
currency: string;
name: string;
discount?: boolean;
/** @deprecated since v4.3.0 - use DiscountSellerLiabilityRule instead. */
discountSellerLiability?: number;
discountSellerLiabilityRule?: DiscountSellerLiabilityRule;
pretax?: boolean;
active?: boolean;
redemptionRule?: RedemptionRule;
Expand Down
3 changes: 3 additions & 0 deletions src/params/programs/UpdateProgramParams.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import {BalanceRule, Program, RedemptionRule} from "../../model";
import {LightrailResponse} from "../LightrailResponse";
import {DiscountSellerLiabilityRule} from "../../model";

export interface UpdateProgramParams {
name?: string;
discount?: boolean;
/** @deprecated since v4.3.0 - use DiscountSellerLiabilityRule instead. */
discountSellerLiability?: number;
discountSellerLiabilityRule?: DiscountSellerLiabilityRule;
pretax?: boolean;
active?: boolean;
redemptionRule?: RedemptionRule;
Expand Down
11 changes: 7 additions & 4 deletions src/params/values/CreateValueParams.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {Value} from "../../model/Value";
import {Value} from "../../model";
import {LightrailResponse} from "../LightrailResponse";
import {BalanceRule} from "../../model/BalanceRule";
import {RedemptionRule} from "../../model/RedemptionRule";
import {GenericCodeOptions} from "../../model/GenericCodeOptions";
import {BalanceRule} from "../../model";
import {RedemptionRule} from "../../model";
import {GenericCodeOptions} from "../../model";
import {DiscountSellerLiabilityRule} from "../../model";

export interface CreateValueParams {
id: string;
Expand All @@ -15,7 +16,9 @@ export interface CreateValueParams {
active?: boolean;
frozen?: boolean;
discount?: boolean;
/** @deprecated since v4.3.0 - use DiscountSellerLiabilityRule instead. */
discountSellerLiability?: number;
discountSellerLiabilityRule?: DiscountSellerLiabilityRule;
genericCodeOptions?: GenericCodeOptions;
redemptionRule?: RedemptionRule;
balanceRule?: BalanceRule;
Expand Down
9 changes: 6 additions & 3 deletions src/params/values/UpdateValueParams.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {LightrailResponse} from "../LightrailResponse";
import {Value} from "../../model/Value";
import {BalanceRule} from "../../model/BalanceRule";
import {RedemptionRule} from "../../model/RedemptionRule";
import {Value} from "../../model";
import {BalanceRule} from "../../model";
import {RedemptionRule} from "../../model";
import {DiscountSellerLiabilityRule} from "../../model";

export interface UpdateValueParams {
contactId?: string;
Expand All @@ -12,7 +13,9 @@ export interface UpdateValueParams {
redemptionRule?: RedemptionRule;
balanceRule?: BalanceRule;
discount?: boolean;
/** @deprecated since v4.3.0 - use DiscountSellerLiabilityRule instead. */
discountSellerLiability?: number;
discountSellerLiabilityRule?: DiscountSellerLiabilityRule;
startDate?: string;
endDate?: string;
tags?: string[];
Expand Down
11 changes: 7 additions & 4 deletions src/programs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ describe("programs", () => {
id: testID,
name: "javascript programs unit test",
currency: "USD",
discount: false,
discountSellerLiability: null,
discount: true,
pretax: false,
active: true,
redemptionRule: {
Expand All @@ -35,6 +34,10 @@ describe("programs", () => {
rule: "100",
explanation: "$1",
},
discountSellerLiabilityRule: {
rule: "0.5",
explanation: "seller is 50% liable"
},
minInitialBalance: null, // must be null if balanceRule
maxInitialBalance: null, // must be null if balanceRule
fixedInitialBalances: null, // must be null if balanceRule
Expand All @@ -47,9 +50,9 @@ describe("programs", () => {
};
const program = await Lightrail.programs.createProgram(request);
chai.assert.isNotNull(program);
chai.assert.deepEqualExcluding(program.body, request,
chai.assert.deepEqualExcluding(program.body, {...request, discountSellerLiability: 0.5},
[
"startDate", "endDate", "createdBy", "createdDate", "updatedDate"
"startDate", "endDate", "createdBy", "createdDate", "updatedDate",
] as any);
});
});
Expand Down
9 changes: 6 additions & 3 deletions src/values.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ describe("values", () => {
frozen: false,
discount: true,
pretax: true,
discountSellerLiability: 1,
redemptionRule: {
rule: "1 == 1",
explanation: "true"
},
discountSellerLiabilityRule: {
rule: "0.5",
explanation: "seller is 50% liable"
},
balanceRule: null,
usesRemaining: 1,
startDate: new Date("3030-01-01").toISOString(),
Expand All @@ -45,9 +48,9 @@ describe("values", () => {
const value = await Lightrail.values.createValue(testValue);

chai.assert.isNotNull(value);
chai.assert.deepEqualExcluding(value.body, testValue,
chai.assert.deepEqualExcluding(value.body, {...testValue, discountSellerLiability: 0.5},
[
"startDate", "endDate", "createdBy", "createdDate", "updatedDate", "code", "issuanceId", "updatedContactIdDate", "canceled", "programId"
"startDate", "endDate", "createdBy", "createdDate", "updatedDate", "code", "issuanceId", "updatedContactIdDate", "canceled", "programId",
] as any);
});
});
Expand Down

0 comments on commit 64f94ca

Please sign in to comment.