Skip to content

Commit

Permalink
Merge 0f8f97c into 91c30dd
Browse files Browse the repository at this point in the history
  • Loading branch information
boscar committed Nov 25, 2020
2 parents 91c30dd + 0f8f97c commit e9fbf75
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 4 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": "@wayke-se/ecom",
"version": "3.2.1",
"version": "3.3.0",
"description": "A SDK to utilize Wayke e-commerce APIs",
"main": "src/index.ts",
"typings": "src/index.d.ts",
Expand Down
2 changes: 2 additions & 0 deletions src/customers/address-lookup-response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export class AddressLookupResponse implements IAddressLookupResponse {
return {
city: this.response.city,
name: this.response.name,
givenName: this.response.givenName,
surname: this.response.surname,
postalCode: this.response.postalCode,
street: this.response.street,
street2: this.response.street2,
Expand Down
29 changes: 29 additions & 0 deletions src/customers/customer-builder.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const fixtures = require("../../test/fixtures");

import { CustomerBuilder } from "./customer-builder";
import { IAddress, ICustomer } from "./types";

const fixture = (id: string, withData: any = undefined): any =>
fixtures.create(id, withData);
Expand All @@ -15,9 +16,37 @@ describe("CustomerBuilder", () => {
.withEmail(expected.email)
.withPersonalNumber(expected.personalNumber)
.withPhoneNumber(expected.phoneNumber)
.withGivenName(expected.givenName)
.withSurname(expected.surname)
.build();

expect(actual).toEqual(expected);
});
});

describe(":withAddress()", () => {
let expected: IAddress;
let actual: ICustomer;

beforeAll(() => {
expected = fixture("IAddress");
actual = new CustomerBuilder().withAddress(expected).build();
});

it("sets given name", () => {
expect(actual.givenName).toBe(expected.givenName);
});

it("sets surname", () => {
expect(actual.surname).toBe(expected.surname);
});

it("sets name", () => {
expect(actual.name).toBe(expected.name);
});

it("sets address", () => {
expect(actual.address).toBe(expected);
});
});
});
14 changes: 14 additions & 0 deletions src/customers/customer-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export class CustomerBuilder {
public withAddress(address: IAddress): CustomerBuilder {
this.properties.address = address;
this.properties.name = address.name;
this.properties.givenName = address.givenName;
this.properties.surname = address.surname;

return this;
}
Expand All @@ -27,6 +29,18 @@ export class CustomerBuilder {
return this;
}

public withGivenName(givenName: string): CustomerBuilder {
this.properties.givenName = givenName;

return this;
}

public withSurname(surname: string): CustomerBuilder {
this.properties.surname = surname;

return this;
}

public build(): ICustomer {
return this.properties as ICustomer;
}
Expand Down
8 changes: 6 additions & 2 deletions src/customers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,20 @@ export interface IDistance {

export interface IAddress {
city: string;
name: string;
name?: string;
givenName: string;
surname: string;
postalCode: string;
street: string;
street2: string;
distance?: IDistance | null;
}

export interface ICustomer {
name: string;
name?: string;
personalNumber: string;
givenName: string;
surname: string;
email: string;
phoneNumber: string;
address: IAddress;
Expand Down
2 changes: 2 additions & 0 deletions src/http/apis/orders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const buildCreateRequest = (
phone: request.customer.phoneNumber,
name: request.customer.name,
address: request.customer.address,
givenName: request.customer.givenName,
surname: request.customer.surname,
},
origin: config.getOrigin(),
};
Expand Down

0 comments on commit e9fbf75

Please sign in to comment.