Skip to content

Commit

Permalink
Add new variables to order options response
Browse files Browse the repository at this point in the history
  • Loading branch information
boscar committed Jan 29, 2021
1 parent c39e748 commit dd30236
Show file tree
Hide file tree
Showing 13 changed files with 199 additions and 80 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wayke-se/ecom",
"version": "3.3.0",
"version": "3.4.0-alpha.1",
"description": "A SDK to utilize Wayke e-commerce APIs",
"main": "src/index.ts",
"typings": "src/index.d.ts",
Expand Down
46 changes: 21 additions & 25 deletions src/credit-assessment/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,26 @@ const api = require("../http/apis/credit-assessment");
describe("Credit assessment functions", () => {
describe(":newCase()", () => {
beforeAll(() => {
api.newCase = jest.fn()
.mockImplementation(
() => new Promise((resolve) => {
const assessmentCase = fixture("ICreditAssessmentCase");
resolve(assessmentCase);
})
api.newCase = jest.fn().mockImplementation(
() =>
new Promise((resolve) => {
const assessmentCase = fixture("ICreditAssessmentCase");
resolve(assessmentCase);
})
);
});

describe("Given valid inquiry", () => {
beforeAll(() => {
validator.validateInquiry = jest.fn();
});

it("Should validate inquiry", async () => {
const inquiry = fixture("ICreditAssessmentInquiry");
const spy = jest.spyOn(validator, "validateInquiry");

await newCase(inquiry);

expect(spy).toHaveBeenCalledWith(inquiry);
});

Expand All @@ -40,15 +40,11 @@ describe("Credit assessment functions", () => {

describe("Given invalid inquiry", () => {
beforeAll(() => {
validator.validateInquiry = jest
.fn()
.mockImplementation(
() => {
throw new TypeError("Invalid inquiry");
}
);
validator.validateInquiry = jest.fn().mockImplementation(() => {
throw new TypeError("Invalid inquiry");
});
});

it("Should throw", async () => {
expect.assertions(1);

Expand Down Expand Up @@ -77,20 +73,20 @@ describe("Credit assessment functions", () => {

beforeAll(() => {
expectedStatus = fixture("ICreditAssessmentStatus");
api.getStatus = jest.fn()
.mockImplementation(
() => new Promise((resolve) => {
resolve(expectedStatus);
})

api.getStatus = jest.fn().mockImplementation(
() =>
new Promise((resolve) => {
resolve(expectedStatus);
})
);
});

it("Should return status", async () => {
const status = await api.getStatus("caseId");
expect(status).toBe(expectedStatus);
});

afterAll(() => {
api.newCase.mockClear();
});
Expand Down
18 changes: 12 additions & 6 deletions src/credit-assessment/sign-response.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ describe("Create credit assessment sign response", () => {
describe("Given same device method", () => {
it("Should be same device response", () => {
const apiResponse = fixture("ICreditAssessmentSignApiResponse");

const response = new CreditAssessmentSignResponse(apiResponse, AuthMethod.SameDevice);


const response = new CreditAssessmentSignResponse(
apiResponse,
AuthMethod.SameDevice
);

expect(response.isSameDevice()).toBe(true);
expect(response.isQrCode()).toBe(false);
});
Expand All @@ -19,9 +22,12 @@ describe("Create credit assessment sign response", () => {
describe("Given qr code method", () => {
it("Should be qr code response", () => {
const apiResponse = fixture("ICreditAssessmentSignApiResponse");

const response = new CreditAssessmentSignResponse(apiResponse, AuthMethod.QrCode);


const response = new CreditAssessmentSignResponse(
apiResponse,
AuthMethod.QrCode
);

expect(response.isQrCode()).toBe(true);
expect(response.isSameDevice()).toBe(false);
});
Expand Down
135 changes: 90 additions & 45 deletions src/credit-assessment/validator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@ const fixtures = require("../../test/fixtures");
const fixture = (name: string, withValues: any = undefined): any =>
fixtures.create(name, withValues);

import { ICreditAssessmentCustomer, ICreditAssessmentHouseholdEconomy, ICreditAssessmentInquiry, ICreditAssessmentLoan } from "./types";
import { validateCustomer, validateHouseholdEconomy, validateInquiry, validateLoan } from "./validator";
import {
ICreditAssessmentCustomer,
ICreditAssessmentHouseholdEconomy,
ICreditAssessmentInquiry,
ICreditAssessmentLoan,
} from "./types";
import {
validateCustomer,
validateHouseholdEconomy,
validateInquiry,
validateLoan,
} from "./validator";

describe("Validate credit assessment inquiry", () => {
describe("Given complete inquiry", () => {
Expand All @@ -21,10 +31,13 @@ describe("Validate credit assessment inquiry", () => {

describe("Given null external id", () => {
it("Should throw", () => {
const inquiry = fixture("ICreditAssessmentInquiry", (data: ICreditAssessmentInquiry) => {
data.externalId = null as any;
return data;
});
const inquiry = fixture(
"ICreditAssessmentInquiry",
(data: ICreditAssessmentInquiry) => {
data.externalId = null as any;
return data;
}
);
expect(() => validateInquiry(inquiry)).toThrowError();
});
});
Expand All @@ -46,20 +59,26 @@ describe("Validate customer for credit assessment", () => {

describe("Given null social id", () => {
it("Should throw", () => {
const customer = fixture("ICreditAssessmentCustomer", (data: ICreditAssessmentCustomer) => {
data.socialId = null as any;
return data;
});
const customer = fixture(
"ICreditAssessmentCustomer",
(data: ICreditAssessmentCustomer) => {
data.socialId = null as any;
return data;
}
);
expect(() => validateCustomer(customer)).toThrowError();
});
});

describe("Given null signer ip", () => {
it("Should not throw", () => {
const customer = fixture("ICreditAssessmentCustomer", (data: ICreditAssessmentCustomer) => {
data.signerIp = null as any;
return data;
});
const customer = fixture(
"ICreditAssessmentCustomer",
(data: ICreditAssessmentCustomer) => {
data.signerIp = null as any;
return data;
}
);
expect(() => validateCustomer(customer)).not.toThrowError();
});
});
Expand All @@ -81,41 +100,53 @@ describe("Validate loan for credit assessment", () => {

describe("Given null down payment", () => {
it("Should throw", () => {
const loan = fixture("ICreditAssessmentLoan", (data: ICreditAssessmentLoan) => {
data.downPayment = null as any;
return data;
});
const loan = fixture(
"ICreditAssessmentLoan",
(data: ICreditAssessmentLoan) => {
data.downPayment = null as any;
return data;
}
);
expect(() => validateLoan(loan)).toThrowError();
});
});

describe("Given no down payment", () => {
it("Should not throw", () => {
const loan = fixture("ICreditAssessmentLoan", (data: ICreditAssessmentLoan) => {
data.downPayment = 0;
return data;
});
const loan = fixture(
"ICreditAssessmentLoan",
(data: ICreditAssessmentLoan) => {
data.downPayment = 0;
return data;
}
);
expect(() => validateLoan(loan)).not.toThrowError();
});
});

describe("Given undefined term", () => {
it("Should not throw", () => {
const loan = fixture("ICreditAssessmentLoan", (data: ICreditAssessmentLoan) => {
data.term = undefined;
return data;
});
const loan = fixture(
"ICreditAssessmentLoan",
(data: ICreditAssessmentLoan) => {
data.term = undefined;
return data;
}
);
expect(() => validateLoan(loan)).not.toThrowError();
});
});
});


describe("Validate household economy for credit assessment", () => {
describe("Given complete household economy", () => {
it("Should not throw", () => {
const householdEconomy = fixture("ICreditAssessmentHouseholdEconomy");
expect(() => validateHouseholdEconomy(householdEconomy)).not.toThrowError();
const householdEconomy = fixture(
"ICreditAssessmentHouseholdEconomy"
);
expect(() =>
validateHouseholdEconomy(householdEconomy)
).not.toThrowError();
});
});

Expand All @@ -127,32 +158,46 @@ describe("Validate household economy for credit assessment", () => {

describe("Given undefined marital status", () => {
it("Should throw", () => {
const householdEconomy = fixture("ICreditAssessmentHouseholdEconomy", (data: ICreditAssessmentHouseholdEconomy) => {
data.maritalStatus = null as any;
return data;
});
expect(() => validateHouseholdEconomy(householdEconomy)).toThrowError();
const householdEconomy = fixture(
"ICreditAssessmentHouseholdEconomy",
(data: ICreditAssessmentHouseholdEconomy) => {
data.maritalStatus = null as any;
return data;
}
);
expect(() =>
validateHouseholdEconomy(householdEconomy)
).toThrowError();
});
});

describe("Given null income", () => {
it("Should throw", () => {
const householdEconomy = fixture("ICreditAssessmentHouseholdEconomy", (data: ICreditAssessmentHouseholdEconomy) => {
data.income = null as any;
return data;
});
expect(() => validateHouseholdEconomy(householdEconomy)).toThrowError();
const householdEconomy = fixture(
"ICreditAssessmentHouseholdEconomy",
(data: ICreditAssessmentHouseholdEconomy) => {
data.income = null as any;
return data;
}
);
expect(() =>
validateHouseholdEconomy(householdEconomy)
).toThrowError();
});
});

describe("Given no income", () => {
it("Should not throw", () => {
const householdEconomy = fixture("ICreditAssessmentHouseholdEconomy", (data: ICreditAssessmentHouseholdEconomy) => {
data.income = 0;
return data;
});
expect(() => validateHouseholdEconomy(householdEconomy)).not.toThrowError();
const householdEconomy = fixture(
"ICreditAssessmentHouseholdEconomy",
(data: ICreditAssessmentHouseholdEconomy) => {
data.income = 0;
return data;
}
);
expect(() =>
validateHouseholdEconomy(householdEconomy)
).not.toThrowError();
});
});
});

9 changes: 8 additions & 1 deletion src/http/apis/credit-assessment.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ const fixture = (name: string, withValues: any = undefined): any =>

const http = require("..");

import { accept, cancelSigning, decline, getStatus, newCase, signCase } from "./credit-assessment";
import {
accept,
cancelSigning,
decline,
getStatus,
newCase,
signCase,
} from "./credit-assessment";

describe("API: Credit Assessment", () => {
describe("Given unsuccessful request", () => {
Expand Down
8 changes: 6 additions & 2 deletions src/http/apis/credit-assessment/sign.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ describe("BankId Auth", () => {

var url = getUrl(request);

expect(url).toBe(`${host}/credit-assessment/sign/${request.caseId}/same-device`);
expect(url).toBe(
`${host}/credit-assessment/sign/${request.caseId}/same-device`
);
});
});

Expand All @@ -44,7 +46,9 @@ describe("BankId Auth", () => {

var url = getUrl(request);

expect(url).toEqual(`${host}/credit-assessment/sign/${request.caseId}/qr-code`);
expect(url).toEqual(
`${host}/credit-assessment/sign/${request.caseId}/qr-code`
);
});
});
});
Expand Down
16 changes: 16 additions & 0 deletions src/orders/order-options-response.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const fixtures = require("../../test/fixtures");

import { PaymentLookupResponse } from "../payments/payment-lookup-response";
import { OrderOptionsResponse } from "./order-options-response";
import { IOrderOptionsResponseData } from "./types";

const fixture = (name: string, withData: any = undefined): any =>
fixtures.create(name, withData);
Expand Down Expand Up @@ -54,6 +55,21 @@ describe("OrderOptionsResponse", () => {

expect(actual.length).toBe(0);
});
it("returns external id in payment options", () => {
const response: IOrderOptionsResponseData = fixture(
"IOrderOptionsResponse"
);

const options = new OrderOptionsResponse(
response
).getPaymentOptions();

for (let i = 0; i < response.payment.length; i++) {
const expected = response.payment[i].externalId;
const actual = options[i].externalId;
expect(actual).toBe(expected);
}
});
});

describe(":getDeliveryOptions()", () => {
Expand Down

0 comments on commit dd30236

Please sign in to comment.